当前位置: 首页>>代码示例>>Python>>正文


Python Shell.Shell类代码示例

本文整理汇总了Python中cloudmesh_client.common.Shell.Shell的典型用法代码示例。如果您正苦于以下问题:Python Shell类的具体用法?Python Shell怎么用?Python Shell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Shell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

 def execute(self, name, command):
     """executes the command on the named host"""
     if name in ["localhost"]:
         r = '\n'.join(Shell.sh("-c", command).split()[-1:])
     else:
         r = '\n'.join(Shell.ssh(name, command).split()[-1:])
     return r
开发者ID:sohiljain,项目名称:client,代码行数:7,代码来源:ssh_config.py

示例2: create_cloudmesh_yaml

def create_cloudmesh_yaml(filename):
    if not os.path.exists(filename):
        path = os.path.dirname(filename)
        if not os.path.isdir(path):
            Shell.mkdir(path)
        etc_path = os.path.dirname(cloudmesh_client.__file__)
        etc_file = os.path.join(etc_path, "etc", "cloudmesh.yaml")
        to_dir = path_expand("~/.cloudmesh")
        shutil.copy(etc_file, to_dir)
        Console.ok("~/.cloudmesh/cloudmesh.yaml created")
开发者ID:alistairking,项目名称:client,代码行数:10,代码来源:cm.py

示例3: delete

    def delete(cls, cluster, job, group=None):
        """
        This method is used to terminate a job with the specified or a group of jobs
        job_id or job_name in a given cluster
        :param group:
        :param cluster: the cluster like comet
        :param job: the job id or name
        :return: success message or error
        """
        try:
            if group is not None:
                # get the job ids from the db

                arguments = {'cluster': cluster,
                             'group': group}
                db_jobs = cls.cm.find('batchjob',
                                      **arguments)

                list1 = []
                for i in db_jobs:
                    list1.append(db_jobs[i]['job_id'])

                # read active jobs
                active_jobs = json.loads(cls.queue(cluster))
                list2 = []
                for i in active_jobs:
                    list2.append(active_jobs[i]['jobid'])

                # find intersection
                res = set(list1).intersection(set(list2))

                if res is not None:
                    for j in res:
                        cmd = 'scancel {}'.format(str(j))
                        Shell.ssh(cluster, cmd)
                        print("Deleted {}".format(j))

                return "All jobs for group {} killed successfully".format(group)

            else:
                args = 'scancel '
                if job.isdigit():
                    args += job
                else:
                    args += "-n {}".format(job)

                Shell.ssh(cluster, args)
                return "Job {} killed successfully".format(job)
        except Exception as ex:
            print("in exceptio")
            print(ex)
            return ex
开发者ID:arpiagariu,项目名称:client,代码行数:52,代码来源:BatchProviderSLURM.py

示例4: _grep

 def _grep(self, search, platform):
   if not search:
       search = "'OS_PASSWORD': '[a-zA-Z0-9]+'"
   cmd = "egrep -ri \"{0}\" * | cut -d\":\" -f1 > a.tmp".format(search)
   print("[{0}]:{1}".format(platform, cmd))
   os.system(cmd)
   res = Shell.cat("a.tmp")
   if res:
       print ('[{0}]: [ERROR] PASSWORD(OR SECRET KEY) DETECTED, SEE FILES '
              'BELOW'.format(platform))
       print ("")
       print (res)
   else:
       print ("[{0}]: NO PASSWORD DETECTED".format(platform))
   Shell.rm("a.tmp")
   print ("")
开发者ID:alistairking,项目名称:client,代码行数:16,代码来源:setup-old.py

示例5: list

    def list(cls, verbose=False):

        def convert(line):
            entry = (' '.join(line.split())).split(' ')
            data = dotdict()
            data.id = entry[0]
            data.name = entry[1]
            data.provider = entry[2]
            data.state = entry[3]
            data.directory = entry[4]

            return data

        result = Shell.execute("vagrant", "global-status --prune")
        if verbose:
            print(result)
        if "There are no active" in result:
            return None

        lines = []
        for line in result.split("\n")[2:]:
            if line == " ":
                break
            else:
                lines.append(convert(line))
        return lines
开发者ID:cloudmesh,项目名称:vagrant,代码行数:26,代码来源:vm.py

示例6: execute

    def execute(cls, name, command, cwd=None):

        vms = cls.to_dict(cls.list())

        arg = "ssh {} -c {}".format(name, command)
        result = Shell.execute("vagrant", ["ssh", name, "-c", command], cwd=vms[name]["directory"])
        return result
开发者ID:cloudmesh,项目名称:vagrant,代码行数:7,代码来源:vm.py

示例7: run

def run(command):
    parameter = command.split(" ")
    shell_command = parameter[0]
    args = parameter[1:]
    result = Shell.execute(shell_command, args)
    print(result)
    return result
开发者ID:alistairking,项目名称:client,代码行数:7,代码来源:test_group.py

示例8: run

def run(command):
    print ("EXECUTING:", command)
    parameter = command.split(" ")
    shell_command = parameter[0]
    args = parameter[1:]
    result = Shell.execute(shell_command, args)
    return result
开发者ID:alistairking,项目名称:client,代码行数:7,代码来源:test_register.py

示例9: run

 def run(self, command):
     command = command.format(**self.data)
     banner(command)
     parameter = command.split(" ")
     shell_command = parameter[0]
     args = parameter[1:]
     result = Shell.execute(shell_command, args)
     return result
开发者ID:alistairking,项目名称:client,代码行数:8,代码来源:test_vm.py

示例10: list

    def list(cls, cloud, start=None, end=None, tenant=None, format="table"):
        # set the environment variables
        set_os_environ(cloud)

        try:
            # execute the command
            args = ["usage"]
            if start is not None:
                args.extend(["--start", start])
            if end is not None:
                args.extend(["--end", end])
            if tenant is not None:
                args.extend(["--tenant", tenant])

            result = Shell.execute("nova", args)
            result = Nova.remove_subjectAltName_warning(result)

            lines = result.splitlines()
            dates = lines[0]

            # TODO: as stated below, nova returns additional lines,
            # on my pc, SecurityWarning is returned, so filtering..

            for l in lines[1:]:
                if l.__contains__("SecurityWarning"):
                    lines.remove(l)

            table = '\n'.join(lines[1:])

            dates = dates.replace("Usage from ", "").replace("to", "").replace(" +", " ")[:-1].split()

            #
            # TODO: for some reason the nova command has returned not the
            # first + char, so we could not ignore the line we may set - as
            # additional comment char, but that did not work
            #

            d = TableParser.convert(table, comment_chars="+#")

            # d["0"]["start"] = "start"
            # d["0"]["end"] = "end"

            d["0"]["start"] = dates[0]
            d["0"]["end"] = dates[1]

            # del d['0']

            return Printer.write(d,
                                 order=["start",
                                        "end",
                                        "servers",
                                        "cpu hours",
                                        "ram mb-hours",
                                        "disk gb-hours"],
                                 output=format)

        except Exception as e:
            return e
开发者ID:arpiagariu,项目名称:client,代码行数:58,代码来源:usage.py

示例11: rm

    def rm(cls, cluster, id=None, format=None):
        data = {
            "CLUSTER": cluster,
            "ID": id,
        }
        result = None
        if id is not None:
            try:
                result = Shell.ssh(cluster, "rm -rf experiment/{ID}".format(**data))
            except Exception as e:
                pass
        else:
            try:
                result = Shell.ssh(cluster, "rm -rf experiment/*").split("\n")
            except Exception as e:
                pass

        return result
开发者ID:alistairking,项目名称:client,代码行数:18,代码来源:experiment.py

示例12: ec2

    def ec2(cls, cloud, zipfile):

        def sanitize(name):
            return name.replace(".zip", "").replace("@", "_")

        def find_exports(filename):
            with open(filename, "r") as f:
                content = f.read()
            data = {}
            for line in content.split("\n"):
                if line.startswith("export "):
                    line = line.replace("export ", "")
                    attribute, value = line.split("=", 1)
                    value = value.replace("${NOVA_KEY_DIR}/", "")
                    # remove comments
                    data[attribute] = value.split("#")[0].strip()
            return data

        base = sanitize(os.path.basename(zipfile))
        dest = sanitize(os.path.join(
            path_expand("~"),
            ".cloudmesh",
            "clouds",
            cloud,
            os.path.basename(zipfile)))
        Console.msg("Unzip file {} -> {}".format(zipfile, dest))
        r = Shell.unzip(zipfile, dest)
        rcfile = os.path.join(dest, "ec2rc.sh")
        data = find_exports(rcfile)
        data["DEST"] = dest
        data["CLOUD"] = cloud
        d = {
            "cm_heading": "{CLOUD}, EC2".format(**data),
            "cm_host": None,
            "cm_label": "{CLOUD}_ec2".format(**data),
            "cm_type": "ec2",
            "cm_type_version": "ec2",
            "credentials": {
                "EC2_ACCESS_KEY": "{EC2_ACCESS_KEY}".format(**data),
                "EC2_SECRET_KEY": "{EC2_SECRET_KEY}".format(**data),
                "keyname": "TBD_not_used",
                "userid": "TBD_not_used",
                "EC2_URL": "{EC2_URL}".format(**data),
                "EC2_USER_ID": "{EC2_USER_ID}",
                "EC2_PRIVATE_KEY": "{DEST}/pk.pem".format(**data),
                "EC2_CERT": "{DEST}/cert.pem".format(**data),
                "NOVA_CERT": "{DEST}/cacert.pem".format(**data),
                "EUCALYPTUS_CERT": "{DEST}/cacert.pem".format(**data),
            },
            "default": {
                "flavor": "m1.small",
                "image": "None",
            }
        }
        config = ConfigDict("cloudmesh.yaml")
        config["cloudmesh"]["clouds"][cloud] = d
        config.save()
开发者ID:arpiagariu,项目名称:client,代码行数:57,代码来源:register.py

示例13: version

def version(verbose=False):
    result = Shell.execute("vagrant", ["version"])
    if verbose:
        return result
    else:
        lines = result.split("\n")
        for line in lines:
            if "Installed Version:" in line:
                return line.replace("Installed Version:", "").strip()
        return None
开发者ID:cloudmesh,项目名称:vagrant,代码行数:10,代码来源:__init__.py

示例14: sync

    def sync(cls, cloudname, localdir, remotedir, operation=None):
        """
        Syncs a local directory with a remote directory.
        Either from local to remote OR vice-versa
        :param cloudname:
        :param localdir:
        :param remotedir:
        :param operation: get/put
        :return:
        """
        # Get the operating system
        os_type = cls.operating_system()

        # fix the local dir path
        localdirpath = Config.path_expand(localdir)

        # check if local directory exists
        if not os.path.exists(localdirpath):
            if operation == "put":
                Console.error("The local directory [{}] does not exist."
                              .format(localdirpath))
                return None
            elif operation == "get":
                # for receiving, create local dir
                os.mkdir(localdirpath)
                Console.msg("Created local directory [{}] for sync."
                            .format(localdirpath))

        """
            rsync now works on windows machines as well.
            we install rsync (v5.4.1.20150827) on windows via chocolatey
            $ choco install rsync
        """

        host = cls.get_host(cloudname)
        if host is None:
            Console.error("Cloud [{}] not found in cloudmesh.yaml file."
                          .format(cloudname))
            return None
        else:
            args = None
            if operation == "put":
                args = [
                    "-r",
                    localdir,
                    host + ":" + remotedir
                ]
            elif operation == "get":
                args = [
                    "-r",
                    host + ":" + remotedir,
                    localdir
                ]
            # call rsync
            return Shell.rsync(*args)
开发者ID:arpiagariu,项目名称:client,代码行数:55,代码来源:sync.py

示例15: run

 def run(self, command):
     self.cloud = "aws"
     command = command.format(**self.data)
     banner(command, c="-")
     print(command)
     parameter = command.split(" ")
     shell_command = parameter[0]
     args = parameter[1:]
     result = Shell.execute(shell_command, args)
     print(result)
     return result
开发者ID:ashwinir20,项目名称:client,代码行数:11,代码来源:test_libcloud_cli.py


注:本文中的cloudmesh_client.common.Shell.Shell类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。