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


Python GLOBAL_CFG.get_host_item方法代码示例

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


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

示例1: init_suite_run_dir

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def init_suite_run_dir(self, suite_name, user_at_host):
        """Initialise suite run dir on a [email protected]

        Create SUITE_RUN_DIR/log/job/ if necessary.
        Install suite contact environment file.
        Install suite python modules.

        Raise RemoteJobHostInitError if initialisation cannot complete.

        """
        if '@' in user_at_host:
            owner, host = user_at_host.split('@', 1)
        else:
            owner, host = None, user_at_host
        if ((owner, host) in [(None, 'localhost'), (USER, 'localhost')] or
                host in self.initialised_hosts or
                self.single_task_mode):
            return

        suite_run_dir = GLOBAL_CFG.get_derived_host_item(
            suite_name, 'suite run directory')
        sources = [os.path.join(suite_run_dir, CylcSuiteEnv.BASE_NAME)]
        if 'CYLC_SUITE_DEF_PATH' in os.environ:
            sources.append(
                os.path.join(os.getenv('CYLC_SUITE_DEF_PATH'), 'passphrase'))
        suite_run_py = os.path.join(suite_run_dir, 'python')
        if os.path.isdir(suite_run_py):
            sources.append(suite_run_py)
        r_suite_run_dir = GLOBAL_CFG.get_derived_host_item(
            suite_name, 'suite run directory', host, owner)
        r_log_job_dir = GLOBAL_CFG.get_derived_host_item(
            suite_name, 'suite job log directory', host, owner)
        getLogger('main').log(INFO, 'Initialising %s:%s' % (
            user_at_host, r_suite_run_dir))

        ssh_tmpl = GLOBAL_CFG.get_host_item(
            'remote shell template', host, owner).replace(' %s', '')
        scp_tmpl = GLOBAL_CFG.get_host_item(
            'remote copy template', host, owner)

        cmd1 = shlex.split(ssh_tmpl) + [
            "-n", user_at_host,
            'mkdir', '-p', r_suite_run_dir, r_log_job_dir]
        cmd2 = shlex.split(scp_tmpl) + ['-pr'] + sources + [
            user_at_host + ":" + r_suite_run_dir + '/']
        for cmd in [cmd1, cmd2]:
            proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
            out, err = proc.communicate()
            if proc.wait():
                raise RemoteJobHostInitError(
                    user_at_host, " ".join([quote(item) for item in cmd]),
                    proc.returncode, out, err)
        self.initialised_hosts.append(user_at_host)
开发者ID:benfitzpatrick,项目名称:cylc,代码行数:55,代码来源:job_host.py

示例2: write_environment_1

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def write_environment_1( self, BUFFER=None ):
        if not BUFFER:
            BUFFER = self.FILE

        BUFFER.write( "\n\n# CYLC SUITE ENVIRONMENT:" )

        # write the static suite variables
        for var, val in sorted(self.__class__.suite_env.items()):
            BUFFER.write( "\nexport " + var + "=" + str(val) )

        if str(self.__class__.suite_env.get('CYLC_UTC')) == 'True':
            BUFFER.write( "\nexport TZ=UTC" )

        BUFFER.write("\n")
        # override and write task-host-specific suite variables
        suite_work_dir = GLOBAL_CFG.get_derived_host_item( self.suite, 'suite work directory', self.host, self.owner )
        st_env = deepcopy( self.__class__.suite_task_env ) 
        st_env[ 'CYLC_SUITE_RUN_DIR'    ] = GLOBAL_CFG.get_derived_host_item( self.suite, 'suite run directory', self.host, self.owner )
        st_env[ 'CYLC_SUITE_WORK_DIR'   ] = suite_work_dir
        st_env[ 'CYLC_SUITE_SHARE_DIR'  ] = GLOBAL_CFG.get_derived_host_item( self.suite, 'suite share directory', self.host, self.owner )
        st_env[ 'CYLC_SUITE_SHARE_PATH' ] = '$CYLC_SUITE_SHARE_DIR' # DEPRECATED
        rsp = self.jobconfig['remote suite path']
        if rsp:
            st_env[ 'CYLC_SUITE_DEF_PATH' ] = rsp
        else:
            # replace home dir with '$HOME' for evaluation on the task host
            st_env[ 'CYLC_SUITE_DEF_PATH' ] = re.sub( os.environ['HOME'], '$HOME', st_env['CYLC_SUITE_DEF_PATH'] )
        for var, val in sorted(st_env.items()):
            BUFFER.write( "\nexport " + var + "=" + str(val) )

        task_work_dir  = os.path.join( suite_work_dir, self.jobconfig['work sub-directory'] )

        use_login_shell = GLOBAL_CFG.get_host_item( 'use login shell', self.host, self.owner )
        comms = GLOBAL_CFG.get_host_item( 'task communication method', self.host, self.owner )

        BUFFER.write( "\n\n# CYLC TASK ENVIRONMENT:" )
        BUFFER.write( "\nexport CYLC_TASK_COMMS_METHOD=" + comms )
        BUFFER.write( "\nexport CYLC_TASK_CYCLE_POINT=" + self.point_string )
        BUFFER.write( "\nexport CYLC_TASK_CYCLE_TIME=" + self.point_string )
        BUFFER.write( "\nexport CYLC_TASK_ID=" + self.task_id )
        BUFFER.write( "\nexport CYLC_TASK_IS_COLDSTART=" + str( self.jobconfig['is cold-start']) )
        BUFFER.write( "\nexport CYLC_TASK_LOG_ROOT=" + self.log_root )
        BUFFER.write( "\nexport CYLC_TASK_MSG_MAX_TRIES=" + str( GLOBAL_CFG.get( ['task messaging','maximum number of tries'])) )
        BUFFER.write( "\nexport CYLC_TASK_MSG_RETRY_INTVL=" + str( GLOBAL_CFG.get( ['task messaging','retry interval in seconds'])) )
        BUFFER.write( "\nexport CYLC_TASK_MSG_TIMEOUT=" + str( GLOBAL_CFG.get( ['task messaging','connection timeout in seconds'])) )
        BUFFER.write( "\nexport CYLC_TASK_NAME=" + self.task_name )
        BUFFER.write( '\nexport CYLC_TASK_NAMESPACE_HIERARCHY="' + ' '.join( self.jobconfig['namespace hierarchy']) + '"')
        BUFFER.write( "\nexport CYLC_TASK_SSH_LOGIN_SHELL=" + str(use_login_shell) )
        BUFFER.write( "\nexport CYLC_TASK_SUBMIT_NUMBER=" + str(self.jobconfig['absolute submit number']) )
        BUFFER.write( "\nexport CYLC_TASK_TRY_NUMBER=" + str(self.jobconfig['try number']) )
        BUFFER.write( "\nexport CYLC_TASK_WORK_DIR=" + task_work_dir )
        BUFFER.write( "\nexport CYLC_TASK_WORK_PATH=$CYLC_TASK_WORK_DIR") # DEPRECATED
开发者ID:dmanubens,项目名称:cylc,代码行数:54,代码来源:jobfile.py

示例3: init_suite_run_dir

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def init_suite_run_dir(self, suite_name, user_at_host):
        """Initialise suite run dir on a [email protected]

        Create SUITE_RUN_DIR/log/job/ if necessary.
        Install suite contact environment file.
        Install suite python modules.

        Raise RemoteJobHostInitError if initialisation cannot complete.

        """
        if '@' in user_at_host:
            owner, host = user_at_host.split('@', 1)
        else:
            owner, host = None, user_at_host
        if ((owner, host) in [(None, 'localhost'), (user, 'localhost')] or
                host in self.initialised_hosts or
                self.single_task_mode):
            return

        suite_run_dir = GLOBAL_CFG.get_derived_host_item(
            suite_name, 'suite run directory')
        sources = [os.path.join(suite_run_dir, "cylc-suite-env")]
        suite_run_py = os.path.join(suite_run_dir, "python")
        if os.path.isdir(suite_run_py):
            sources.append(suite_run_py)
        try:
            r_suite_run_dir = GLOBAL_CFG.get_derived_host_item(
                suite_name, 'suite run directory', host, owner)
            r_log_job_dir = GLOBAL_CFG.get_derived_host_item(
                suite_name, 'suite job log directory', host, owner)
            getLogger('main').log(INFO, 'Initialising %s:%s' % (
                user_at_host, r_suite_run_dir))

            ssh_tmpl = GLOBAL_CFG.get_host_item(
                'remote shell template', host, owner).replace(" %s", "")
            scp_tmpl = GLOBAL_CFG.get_host_item(
                'remote copy template', host, owner)

            cmd1 = shlex.split(ssh_tmpl) + [
                user_at_host,
                'mkdir -p "%s" "%s"' % (r_suite_run_dir, r_log_job_dir)]
            cmd2 = shlex.split(scp_tmpl) + ["-r"] + sources + [
                user_at_host + ":" + r_suite_run_dir + "/"]
            for cmd in [cmd1, cmd2]:
                check_call(cmd)
        except Exception:
            raise RemoteJobHostInitError(user_at_host)
        self.initialised_hosts.append(user_at_host)
开发者ID:ScottWales,项目名称:cylc,代码行数:50,代码来源:job_host.py

示例4: _write_prelude

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def _write_prelude(cls, handle, job_conf):
        """Job script prelude."""
        if cylc.flags.debug:
            if 'bash' in job_conf['job script shell']:
                handle.write("\n\nPS4='+[\D{%Y%m%dT%H%M%S%z}]\[email protected]\h '")
            handle.write('\n\nset -x')
        handle.write('\n\necho "JOB SCRIPT STARTING"')
        # set cylc version and source profile scripts before turning on
        # error trapping so that profile errors do not abort the job
        handle.write('\n\nprelude() {')
        keys = GLOBAL_CFG.get_host_item(
            'copyable environment variables',
            job_conf['host'], job_conf['owner'])
        for key in keys + ['CYLC_DIR', 'CYLC_VERSION']:
            if key in os.environ:
                handle.write("\n    export %s='%s'" % (key, os.environ[key]))
        handle.write(
            r'''
    for FILE_NAME in \
        "${HOME}/.cylc/job-init-env.sh" \
        "${CYLC_DIR}/conf/job-init-env.sh" \
        "${CYLC_DIR}/conf/job-init-env-default.sh"
    do
        if [[ -f "${FILE_NAME}" ]]; then
            . "${FILE_NAME}" 1>/dev/null 2>&1
            break
        fi
    done
}
prelude''')
开发者ID:benfitzpatrick,项目名称:cylc,代码行数:32,代码来源:job_file.py

示例5: _write_prelude

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def _write_prelude(cls, handle, job_conf):
        """Job script prelude."""
        handle.write('\n\necho "JOB SCRIPT STARTING"')
        # set cylc version and source profile scripts before turning on
        # error trapping so that profile errors do not abort the job
        handle.write("\n\nprelude() {")
        keys = GLOBAL_CFG.get_host_item("copyable environment variables", job_conf["host"], job_conf["owner"])
        for key in keys + ["CYLC_DIR", "CYLC_VERSION"]:
            if key in os.environ:
                handle.write("\n    export %s='%s'" % (key, os.environ[key]))
        handle.write(
            r"""
    for FILE_NAME in \
        "${HOME}/.cylc/job-init-env.sh" \
        "${CYLC_DIR}/conf/job-init-env.sh" \
        "${CYLC_DIR}/conf/job-init-env-default.sh"
    do
        if [[ -f "${FILE_NAME}" ]]; then
            . "${FILE_NAME}" 1>/dev/null 2>&1
            break
        fi
    done
}
prelude"""
        )
开发者ID:bjlittle,项目名称:cylc,代码行数:27,代码来源:job_file.py

示例6: list_suites

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
 def list_suites(self, regfilter=None):
     """Return a filtered list of valid suite registrations."""
     rec_regfilter = None
     if regfilter:
         try:
             rec_regfilter = re.compile(regfilter)
         except re.error as exc:
             raise ValueError("%s: %s" % (regfilter, exc))
     from cylc.cfgspec.globalcfg import GLOBAL_CFG
     run_d = GLOBAL_CFG.get_host_item('run directory')
     results = []
     for dirpath, dnames, fnames in os.walk(run_d, followlinks=True):
         # Always descend for top directory, but
         # don't descend further if it has a:
         # * .service/
         # * cylc-suite.db: (pre-cylc-7 suites don't have ".service/").
         if dirpath != run_d and (
                 self.DIR_BASE_SRV in dnames or "cylc-suite.db" in fnames):
             dnames[:] = []
         # Choose only suites with .service and matching filter
         reg = os.path.relpath(dirpath, run_d)
         path = os.path.join(dirpath, self.DIR_BASE_SRV)
         if (not self._locate_item(self.FILE_BASE_SOURCE, path) or
                 rec_regfilter and not rec_regfilter.search(reg)):
             continue
         try:
             results.append([
                 reg,
                 self.get_suite_source_dir(reg),
                 self._get_suite_title(reg)])
         except (IOError, SuiteServiceFileError) as exc:
             print >> sys.stderr, str(exc)
     return results
开发者ID:m214089,项目名称:cylc,代码行数:35,代码来源:suite_srv_files_mgr.py

示例7: init_suite_run_dir

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def init_suite_run_dir(self, suite_name, user_at_host):
        """Initialise suite run dir on a [email protected]

        Create SUITE_RUN_DIR/log/job/ if necessary.
        Install suite contact environment file.
        Install suite python modules.

        Raise RemoteJobHostInitError if initialisation cannot complete.

        """
        if "@" in user_at_host:
            owner, host = user_at_host.split("@", 1)
        else:
            owner, host = None, user_at_host
        if (
            (owner, host) in [(None, "localhost"), (user, "localhost")]
            or host in self.initialised_hosts
            or self.single_task_mode
        ):
            return

        suite_run_dir = GLOBAL_CFG.get_derived_host_item(suite_name, "suite run directory")
        sources = [os.path.join(suite_run_dir, "cylc-suite-env")]
        if "CYLC_SUITE_DEF_PATH" in os.environ:
            sources.append(os.path.join(os.getenv("CYLC_SUITE_DEF_PATH"), "passphrase"))
        suite_run_py = os.path.join(suite_run_dir, "python")
        if os.path.isdir(suite_run_py):
            sources.append(suite_run_py)
        r_suite_run_dir = GLOBAL_CFG.get_derived_host_item(suite_name, "suite run directory", host, owner)
        r_log_job_dir = GLOBAL_CFG.get_derived_host_item(suite_name, "suite job log directory", host, owner)
        getLogger("main").log(INFO, "Initialising %s:%s" % (user_at_host, r_suite_run_dir))

        ssh_tmpl = GLOBAL_CFG.get_host_item("remote shell template", host, owner).replace(" %s", "")
        scp_tmpl = GLOBAL_CFG.get_host_item("remote copy template", host, owner)

        cmd1 = shlex.split(ssh_tmpl) + ["-n", user_at_host, "mkdir", "-p", r_suite_run_dir, r_log_job_dir]
        cmd2 = shlex.split(scp_tmpl) + ["-pr"] + sources + [user_at_host + ":" + r_suite_run_dir + "/"]
        for cmd in [cmd1, cmd2]:
            proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
            out, err = proc.communicate()
            if proc.wait():
                raise RemoteJobHostInitError(
                    user_at_host, " ".join([quote(item) for item in cmd]), proc.returncode, out, err
                )
        self.initialised_hosts.append(user_at_host)
开发者ID:kaday,项目名称:cylc,代码行数:47,代码来源:job_host.py

示例8: _write_init_script

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
 def _write_init_script(cls, handle, job_conf):
     """Init-script."""
     global_init_script = GLOBAL_CFG.get_host_item("global init-script", job_conf["host"], job_conf["owner"])
     if global_init_script:
         handle.write("\n\n# GLOBAL INIT-SCRIPT:\n")
         handle.write(global_init_script)
     if not job_conf["init-script"]:
         return
     handle.write("\n\n# INIT-SCRIPT:\n")
     handle.write(job_conf["init-script"])
开发者ID:bjlittle,项目名称:cylc,代码行数:12,代码来源:job_file.py

示例9: _load_remote_item

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
 def _load_remote_item(self, item, reg, owner, host):
     """Load content of service item from remote [[email protected]]host via SSH."""
     if not is_remote_host(host) and not is_remote_user(owner):
         return
     # Prefix STDOUT to ensure returned content is relevant
     prefix = r'[CYLC-AUTH] %(suite)s' % {'suite': reg}
     # Attempt to cat passphrase file under suite service directory
     from cylc.cfgspec.globalcfg import GLOBAL_CFG
     script = (
         r"""echo '%(prefix)s'; """
         r'''cat "%(run_d)s/%(srv_base)s/%(item)s"'''
     ) % {
         'prefix': prefix,
         'run_d': GLOBAL_CFG.get_derived_host_item(
             reg, 'suite run directory', host, owner),
         'srv_base': self.DIR_BASE_SRV,
         'item': item
     }
     import shlex
     command = shlex.split(
         GLOBAL_CFG.get_host_item('ssh command', host, owner))
     command += ['-n', owner + '@' + host, script]
     from subprocess import Popen, PIPE
     try:
         proc = Popen(command, stdout=PIPE, stderr=PIPE)
     except OSError:
         if cylc.flags.debug:
             import traceback
             traceback.print_exc()
         return
     out, err = proc.communicate()
     ret_code = proc.wait()
     # Extract passphrase from STDOUT
     # It should live in the line with the correct prefix
     content = ""
     can_read = False
     for line in out.splitlines(True):
         if can_read:
             content += line
         elif line.strip() == prefix:
             can_read = True
     if not content or ret_code:
         if cylc.flags.debug:
             print >> sys.stderr, (
                 'ERROR: %(command)s # code=%(ret_code)s\n%(err)s\n'
             ) % {
                 'command': command,
                 # STDOUT may contain passphrase, so not safe to print
                 # 'out': out,
                 'err': err,
                 'ret_code': ret_code,
             }
         return
     return content
开发者ID:m214089,项目名称:cylc,代码行数:56,代码来源:suite_srv_files_mgr.py

示例10: _write_initial_scripting

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
 def _write_initial_scripting(cls, handle, job_conf):
     """Initial scripting."""
     global_initial_scripting = GLOBAL_CFG.get_host_item(
         'global initial scripting', job_conf["host"], job_conf["owner"])
     if global_initial_scripting:
         handle.write("\n\n# GLOBAL INITIAL SCRIPTING:\n")
         handle.write(global_initial_scripting)
     if not job_conf['initial scripting']:
         return
     handle.write("\n\n# INITIAL SCRIPTING:\n")
     handle.write(job_conf['initial scripting'])
开发者ID:chanwilson,项目名称:cylc,代码行数:13,代码来源:job_file.py

示例11: unlink_hosts_contacts

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def unlink_hosts_contacts(self, reg):
        """Remove suite contact files from initialised hosts.

        This is called on shutdown, so we don't want anything to hang.
        Terminate any incomplete SSH commands after 10 seconds.
        """
        # Issue all SSH commands in parallel
        procs = {}
        for (host, owner), should_unlink in self.init_host_map.items():
            if not should_unlink:
                continue
            user_at_host = host
            if owner:
                user_at_host = owner + '@' + host
            ssh_tmpl = GLOBAL_CFG.get_host_item('ssh command', host, owner)
            r_suite_contact_file = os.path.join(
                GLOBAL_CFG.get_derived_host_item(
                    reg, 'suite run directory', host, owner),
                self.suite_srv_files_mgr.DIR_BASE_SRV,
                self.suite_srv_files_mgr.FILE_BASE_CONTACT)
            cmd = shlex.split(ssh_tmpl) + [
                '-n', user_at_host, 'rm', '-f', r_suite_contact_file]
            procs[user_at_host] = (cmd, Popen(cmd, stdout=PIPE, stderr=PIPE))
        # Wait for commands to complete for a max of 10 seconds
        timeout = time() + 10.0
        while procs and time() < timeout:
            for user_at_host, (cmd, proc) in procs.copy().items():
                if proc.poll() is None:
                    continue
                del procs[user_at_host]
                out, err = proc.communicate()
                if proc.wait():
                    ERR.warning(RemoteJobHostInitError(
                        RemoteJobHostInitError.MSG_TIDY,
                        user_at_host, ' '.join([quote(item) for item in cmd]),
                        proc.returncode, out, err))
        # Terminate any remaining commands
        for user_at_host, (cmd, proc) in procs.items():
            try:
                proc.terminate()
            except OSError:
                pass
            out, err = proc.communicate()
            if proc.wait():
                ERR.warning(RemoteJobHostInitError(
                    RemoteJobHostInitError.MSG_TIDY,
                    user_at_host, ' '.join([quote(item) for item in cmd]),
                    proc.returncode, out, err))
开发者ID:m214089,项目名称:cylc,代码行数:50,代码来源:task_job_mgr.py

示例12: set_host

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def set_host(self, host, set_timer=False):
        """Set the task host.

        The polling comms method is host-specific.

        """
        if GLOBAL_CFG.get_host_item(
                'task communication method', host) == "poll":
            if not self.intervals:
                self.intervals = copy(self.default_intervals)
                self.log(
                    WARNING,
                    '(polling comms) using default %s polling intervals' %
                    self.name
                )
            if set_timer:
                self.set_timer()
开发者ID:benfitzpatrick,项目名称:cylc,代码行数:19,代码来源:poll_timer.py

示例13: _load_passphrase_via_ssh

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
 def _load_passphrase_via_ssh(self, suite, owner, host):
     """Load passphrase from remote [[email protected]]host via SSH."""
     if not is_remote_host(host) and not is_remote_user(owner):
         return
     # Prefix STDOUT to ensure returned content is relevant
     prefix = r'[CYLC-PASSPHRASE] %(suite)s ' % {'suite': suite}
     # Extract suite definition directory from remote ~/.cylc/REGDB/SUITE
     # Attempt to cat passphrase file under suite definition directory
     script = (
         r'''echo -n '%(prefix)s'; '''
         r'''sed -n 's/^path=//p' '.cylc/REGDB/%(suite)s' | '''
         r'''xargs -I '{}' cat '{}/passphrase'; '''
         r'''echo'''
     ) % {'prefix': prefix, 'suite': suite}
     ssh_tmpl = str(GLOBAL_CFG.get_host_item(
         'remote shell template', host, owner))
     ssh_tmpl = ssh_tmpl.replace(' %s', '')  # back compat
     command = shlex.split(ssh_tmpl) + ['-n', owner + '@' + host, script]
     try:
         proc = Popen(command, stdout=PIPE, stderr=PIPE)
     except OSError:
         if cylc.flags.debug:
             traceback.print_exc()
         return
     out, err = proc.communicate()
     ret_code = proc.wait()
     # Extract passphrase from STDOUT
     # It should live in the line with the correct prefix
     passphrase = None
     for line in out.splitlines():
         if line.startswith(prefix):
             passphrase = line.replace(prefix, '').strip()
     if not passphrase or ret_code:
         if cylc.flags.debug:
             print >> sys.stderr, (
                 'ERROR: %(command)s # code=%(ret_code)s\n%(err)s\n'
             ) % {
                 'command': command,
                 # STDOUT may contain passphrase, so not safe to print
                 # 'out': out,
                 'err': err,
                 'ret_code': ret_code,
             }
         return
     return passphrase
开发者ID:benfitzpatrick,项目名称:cylc,代码行数:47,代码来源:registration.py

示例14: execute

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
    def execute(self, force_required=False, env=None, path=None,
                dry_run=False):
        """Execute command on remote host.

        Returns False if remote re-invocation is not needed, True if it is
        needed and executes successfully otherwise aborts.

        """
        if not self.is_remote:
            return False

        from cylc.cfgspec.globalcfg import GLOBAL_CFG
        from cylc.version import CYLC_VERSION

        name = os.path.basename(self.argv[0])[5:]  # /path/to/cylc-foo => foo

        user_at_host = ''
        if self.owner:
            user_at_host = self.owner + '@'
        if self.host:
            user_at_host += self.host
        else:
            user_at_host += 'localhost'

        # Build the remote command

        # ssh command and options (X forwarding)
        ssh_tmpl = str(GLOBAL_CFG.get_host_item(
            "remote shell template", self.host, self.owner)).replace(" %s", "")
        command = shlex.split(ssh_tmpl) + ["-Y", user_at_host]

        # Use bash -l?
        ssh_login_shell = self.ssh_login_shell
        if ssh_login_shell is None:
            ssh_login_shell = GLOBAL_CFG.get_host_item(
                "use login shell", self.host, self.owner)

        # Pass cylc version through.
        command += ["env", "CYLC_VERSION=%s" % CYLC_VERSION]

        if ssh_login_shell:
            # A login shell will always source /etc/profile and the user's bash
            # profile file. To avoid having to quote the entire remote command
            # it is passed as arguments to the bash script.
            command += ["bash", "--login", "-c", "'exec $0 \"[email protected]\"'"]

        # "cylc" on the remote host
        if path:
            command.append(os.sep.join(path + ["cylc"]))
        else:
            command.append(GLOBAL_CFG.get_host_item(
                "cylc executable", self.host, self.owner))

        command.append(name)

        if env is None:
            env = {}
        for var, val in env.iteritems():
            command.append("--env=%s=%s" % (var, val))

        for arg in self.args:
            command.append("'" + arg + "'")
            # above: args quoted to avoid interpretation by the shell,
            # e.g. for match patterns such as '.*' on the command line.

        if cylc.flags.verbose:
            # Wordwrap the command, quoting arguments so they can be run
            # properly from the command line
            command_str = ' '.join([quote(arg) for arg in command])
            print '\n'.join(
                TextWrapper(subsequent_indent='\t').wrap(command_str))

        if dry_run:
            return command

        try:
            popen = subprocess.Popen(command)
        except OSError as exc:
            sys.exit("ERROR: remote command invocation failed %s" % str(exc))

        res = popen.wait()
        if WIFSIGNALED(res):
            sys.exit("ERROR: remote command terminated by signal %d" % res)
        elif res:
            sys.exit("ERROR: remote command failed %d" % res)
        else:
            return True
开发者ID:benfitzpatrick,项目名称:cylc,代码行数:89,代码来源:remote.py

示例15: _load_item_via_ssh

# 需要导入模块: from cylc.cfgspec.globalcfg import GLOBAL_CFG [as 别名]
# 或者: from cylc.cfgspec.globalcfg.GLOBAL_CFG import get_host_item [as 别名]
 def _load_item_via_ssh(self, item, suite, owner, host, dest_dir=None):
     """Load item (e.g. passphrase) from remote [[email protected]]host via SSH."""
     if not is_remote_host(host) and not is_remote_user(owner):
         return
     # Prefix STDOUT to ensure returned content is relevant
     prefix = r'[CYLC-PASSPHRASE] %(suite)s ' % {'suite': suite}
     # Extract suite definition directory from remote ~/.cylc/REGDB/SUITE
     # Attempt to cat passphrase file under suite definition directory
     script = (
         r'''echo -n '%(prefix)s'; '''
         r'''sed -n 's/^path=//p' '.cylc/REGDB/%(suite)s' | '''
         r'''xargs -I '{}' cat '{}/%(item)s'; '''
         r'''echo'''
     ) % {'prefix': prefix, 'suite': suite, 'item': item}
     from cylc.cfgspec.globalcfg import GLOBAL_CFG
     ssh_tmpl = str(GLOBAL_CFG.get_host_item(
         'remote shell template', host, owner))
     ssh_tmpl = ssh_tmpl.replace(' %s', '')  # back compat
     import shlex
     command = shlex.split(ssh_tmpl) + ['-n', owner + '@' + host, script]
     from subprocess import Popen, PIPE
     try:
         proc = Popen(command, stdout=PIPE, stderr=PIPE)
     except OSError:
         if cylc.flags.debug:
             import traceback
             traceback.print_exc()
         return
     out, err = proc.communicate()
     ret_code = proc.wait()
     # Extract passphrase from STDOUT
     # It should live in the line with the correct prefix
     if item == self.PASSPHRASE_FILE_BASE:
         content = None
         for line in out.splitlines():
             if line.startswith(prefix):
                 content = line.replace(prefix, '').strip()
     else:
         content = []
         content_has_started = False
         for line in out.splitlines():
             if line.startswith(prefix):
                 line = line.replace(prefix, '')
                 content_has_started = True
             if content_has_started:
                 content.append(line)
         content = "\n".join(content)
     if not content or ret_code:
         if cylc.flags.debug:
             print >> sys.stderr, (
                 'ERROR: %(command)s # code=%(ret_code)s\n%(err)s\n'
             ) % {
                 'command': command,
                 # STDOUT may contain passphrase, so not safe to print
                 # 'out': out,
                 'err': err,
                 'ret_code': ret_code,
             }
         return
     if dest_dir is not None:
         if not os.path.exists(dest_dir):
             os.makedirs(dest_dir)
         os.chmod(dest_dir, 0700)
         dest_item = os.path.join(dest_dir, item)
         file_handle = open(dest_item, "w")
         file_handle.write(content)
         file_handle.close()
         os.chmod(dest_item, 0600)
         return dest_item
     return content
开发者ID:oliver-sanders,项目名称:cylc,代码行数:72,代码来源:registration.py


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