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


Python Shell.ssh方法代码示例

本文整理汇总了Python中cloudmesh_base.Shell.Shell.ssh方法的典型用法代码示例。如果您正苦于以下问题:Python Shell.ssh方法的具体用法?Python Shell.ssh怎么用?Python Shell.ssh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cloudmesh_base.Shell.Shell的用法示例。


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

示例1: delete

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    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
                cm = CloudmeshDatabase()
                arguments = {'cluster': cluster,
                             'group': group}
                db_jobs = 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:rajaramcomputers,项目名称:client,代码行数:54,代码来源:BatchProviderSLURM.py

示例2: qsub

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def qsub(self, name, host, script, template=None, kind="dict"):
        """
        Executes the qsub command on a given host.
        NOTE this method may not yet be fully implemented

        :param name: name of the script
        :param host: host on which the script is to be run
        :param script: The name of the script
        :param template: The script is wrapped into a template
        :param kind: The return is passed as dict, yaml, xml
        :return:
        """
        self.jobid_incr()
        jobscript = self.create_script(name, script, template)

        # copy the script to the remote host
        self._write_to_file(jobscript, name)
        # copy script to remote host

        remote_path = self.data.get("cloudmesh", "pbs", host, "scripts")

        print(remote_path)
        xmkdir(host, remote_path)

        manager_host = self.manager(host)

        # call qsub on the remot host
        r = Shell.scp(name, manager_host + ":" + remote_path)
        jobid = Shell.ssh(manager_host, "qsub {0}/{1}".format(remote_path, name)).rstrip()

        return self.jobstatus(host, jobid, kind=kind)
开发者ID:kwtillma,项目名称:pbs,代码行数:33,代码来源:OpenPBS.py

示例3: execute

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 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:rajpushkar83,项目名称:base,代码行数:9,代码来源:ssh_config.py

示例4: delete

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def delete(cls, cluster, job):
        """
        This method is used to terminate a job with the specified
        job_id or job_name in a given cluster
        :param cluster: the cluster like comet
        :param job: the job id or name
        :return: success message or error
        """
        try:
            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:
            return ex
开发者ID:atavism,项目名称:client,代码行数:21,代码来源:BatchProviderSLURM.py

示例5: rm

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 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, e:
             pass
开发者ID:rajaramcomputers,项目名称:client,代码行数:13,代码来源:experiment.py

示例6: list

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 def list(cls, cluster, id=None, format=None):
     data = {
         "CLUSTER": cluster,
         "ID": id,
     }
     result = None
     if id is not None:
         try:
             result = Shell.ssh(cluster, "ls experiment/{ID}".format(**data))
             result = result.split("\n")
         except Exception, e:
             result = None
开发者ID:rajaramcomputers,项目名称:client,代码行数:14,代码来源:experiment.py

示例7: info

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def info(cls, cluster, format='json', all=False):

        if all:
            result = Shell.ssh(cluster, 'sinfo --format=\"%all\"')
        else:
            result = Shell.ssh(
                cluster,
                'sinfo --format=\"%P|%a|%l|%D|%t|%N\"')

        # ignor leading lines till header is found
        l = result.splitlines()
        for i, res in enumerate(l):
            if 'PARTITION|AVAIL|' in res:
                result = "\n".join(l[i:])
                break

        parser = TableParser(strip=False)
        d = parser.to_dict(result)

        # add cluster and updated to each entry
        for key in d.keys():
            d[key]['cluster'] = cluster
            d[key]['updated'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        if format == 'json':
            return json.dumps(d, indent=4, separators=(',', ': '))

        else:
            return (dict_printer(d,
                                 order=['cluster',
                                        'partition',
                                        'avail',
                                        'timelimit',
                                        'nodes',
                                        'state',
                                        'nodelist',
                                        'updated'],
                                 output=format))
开发者ID:atavism,项目名称:client,代码行数:40,代码来源:BatchProviderSLURM.py

示例8: nodes

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def nodes(self, host, refresh=True):
        """
        returns the information from the command pbsnodes in a dict.

        :param host: the name of the host as specified in the .ssh/config file
        :param refresh: if False, reads returns a cached value
                        if True, issues a new command and refreshes the cach
        :return: information of the pbsnodes command in a dict
        """

        manager_host = self.manager(host)
        if self.pbs_nodes_data is None or refresh:
            try:
                result = Shell.ssh(manager_host, "pbsnodes", "-a")
            except:
                raise RuntimeError(
                    "can not execute pbs nodes on host {0}".format(manager_host))
            pbsinfo = {}
            nodes = result.split("\n\n")
            for node in nodes:
                pbs_data = node.split("\n")
                pbs_data = [e.strip() for e in pbs_data]
                name = pbs_data[0]
                if name != "":
                    pbsinfo[name] = {u'name': name}
                    for element in pbs_data[1:]:
                        try:
                            (attribute, value) = element.split(" = ")
                            if attribute == 'status':
                                status_elements = value.split(",")
                                pbsinfo[name][attribute] = {}
                                for e in status_elements:
                                    (a, v) = e.split("=")
                                    pbsinfo[name][attribute][a] = v
                            elif attribute == 'jobs':
                                pbsinfo[name][attribute] = value.split(',')
                            elif attribute == 'note' and (
                                        value.strip().startswith("{") or value.strip().startswith("[")):
                                pbsinfo[name][attribute] = literal_eval(value)
                            else:
                                pbsinfo[name][attribute] = value
                        except:
                            pass
            self.pbs_nodes_data = pbsinfo

        return self.pbs_nodes_data
开发者ID:kwtillma,项目名称:pbs,代码行数:48,代码来源:OpenPBS.py

示例9: queue

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def queue(cls, cluster, format='json', job=None):
        try:
            args = 'squeue '
            if job is not None:
                if job.isdigit():
                    args += ' -j {} '.format(job)  # search by job id
                else:
                    args += ' -n {} '.format(job)  # search by job name
            f = '--format=%all'
            args += f
            result = Shell.ssh(cluster, args)

            # TODO: process till header is found...(Need a better way)
            l = result.splitlines()
            for i, res in enumerate(l):
                if 'ACCOUNT|GRES|' in res:
                    result = "\n".join(l[i:])
                    break

            parser = TableParser(strip=True)
            d = parser.to_dict(result)

            # add cluster and updated to each entry
            for key in d.keys():
                d[key]['cluster'] = cluster
                d[key]['updated'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

            if format == 'json':
                return json.dumps(d, indent=4, separators=(',', ': '))

            else:
                return (dict_printer(d,
                                     order=['cluster',
                                            'jobid',
                                            'partition',
                                            'name',
                                            'user',
                                            'st',
                                            'time',
                                            'nodes',
                                            'nodelist',
                                            'updated'],
                                     output=format))
        except Exception as ex:
            return ex
开发者ID:atavism,项目名称:client,代码行数:47,代码来源:BatchProviderSLURM.py

示例10: output

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 def output(cls, cluster, id=None, format=None):
     data = {
         "CLUSTER": cluster,
         "ID": id,
     }
     result = None
     if id is None:
         ids = list(cluster)
     else:
         ids = [id]
     result = []
     for i in ids:
         try:
             result.append(Shell.ssh(cluster, "cat experiment/{}/*.out".format(i)))
         except:
             result.append("")
     # if result == []:
     #    result = None
     return result
开发者ID:rajaramcomputers,项目名称:client,代码行数:21,代码来源:experiment.py

示例11: jobstatus

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def jobstatus(self, host, jobid, kind='dict'):
        """
        The status of a specific job

        :param host: The host on which the job is running
        :param jobid: The jobid as specified by the queing system
        :param kind: The output can be returned as dict, xml, and yaml
        :return:
        """

        manager_host = self.manager(host)
        qstat_xml_data = Shell.ssh(manager_host, "qstat", "-x", jobid).rstrip()

        if kind == 'xml':
            r = qstat_xml_data
        else:
            r = self.qstat_xml_to_dict(qstat_xml_data)
            r[unicode(jobid)][u"cm_jobid"] = self.jobid
            r[unicode(jobid)]["cm_Variable_list"] = self.variable_list(r)
        if kind == 'yaml':
            r = yaml.dump(r, default_flow_style=False)
        return r
开发者ID:kwtillma,项目名称:pbs,代码行数:24,代码来源:OpenPBS.py

示例12: qstat

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
    def qstat(self, host, user=True, format='dict'):
        """
        executes the qstat command on a particular host and returns
        the information as dict.

        :param host: The host as specified in ~/.ssh/config
        :param user:  If True, only retirns information for the user
                      If False, all jobs for all users are returned
        :param format:
        :return:
        """
        data = None
        username = self.username(host)
        manager_host = self.manager(host)
        xml_data = Shell.ssh(manager_host, "qstat", "-x").rstrip()

        if format == 'dict':
            data = OpenPBS.qstat_xml_to_dict(xml_data)
            selected_data = {}
            for jobid in data:
                (owner, cm_host) = data[jobid]['Job_Owner'].split('@')
                if not user:
                    selected_data[unicode(jobid)] = data[unicode(jobid)]
                elif owner == username:
                    selected_data[unicode(jobid)] = data[unicode(jobid)]
            data = selected_data
            for jobid in data:
                data[unicode(jobid)][u"cm_jobid"] = jobid
                if "Variable_list" in data[unicode(jobid)]:
                    data[unicode(jobid)][u"cm_Variable_list"] = self.variable_list(data, jobid)
        elif format == "xml":
            if user is not None:
                print("WARNING: "
                      "restrictiong xml data for a user not supported.")
            data = xml_data
        return dict(data)
开发者ID:kwtillma,项目名称:pbs,代码行数:38,代码来源:OpenPBS.py

示例13: pbsnodes_data

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 def pbsnodes_data(manager_host):
     result = str(
         Shell.ssh(manager_host, "pbsnodes", "-l", "-n"))[:-1]
     return result
开发者ID:kwtillma,项目名称:pbs,代码行数:6,代码来源:OpenPBS.py

示例14: create_remote_dir

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 def create_remote_dir(cls, cluster, dir):
     Shell.ssh(cluster, "mkdir -p {dir}".format(dir=dir))
开发者ID:atavism,项目名称:client,代码行数:4,代码来源:BatchProviderBase.py

示例15: qstat

# 需要导入模块: from cloudmesh_base.Shell import Shell [as 别名]
# 或者: from cloudmesh_base.Shell.Shell import ssh [as 别名]
 def qstat(host):
     return Shell.ssh(host, "qstat").rstrip()
开发者ID:kwtillma,项目名称:pbs,代码行数:4,代码来源:PBSDeploy.py


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