本文整理匯總了Python中rose.host_select.HostSelector.expand方法的典型用法代碼示例。如果您正苦於以下問題:Python HostSelector.expand方法的具體用法?Python HostSelector.expand怎麽用?Python HostSelector.expand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rose.host_select.HostSelector
的用法示例。
在下文中一共展示了HostSelector.expand方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SuiteRestarter
# 需要導入模塊: from rose.host_select import HostSelector [as 別名]
# 或者: from rose.host_select.HostSelector import expand [as 別名]
class SuiteRestarter(object):
"""Wrap "cylc restart"."""
def __init__(self, event_handler=None):
self.event_handler = event_handler
self.popen = RosePopener(self.event_handler)
self.fs_util = FileSystemUtil(self.event_handler)
self.config_pm = ConfigProcessorsManager(
self.event_handler, self.popen, self.fs_util)
self.host_selector = HostSelector(self.event_handler, self.popen)
self.suite_engine_proc = SuiteEngineProcessor.get_processor(
event_handler=self.event_handler,
popen=self.popen,
fs_util=self.fs_util)
def handle_event(self, *args, **kwargs):
"""Handle event."""
if callable(self.event_handler):
self.event_handler(*args, **kwargs)
def restart(
self, suite_name=None, host=None, gcontrol_mode=None, args=None):
"""Restart a "cylc" suite."""
# Check suite engine specific compatibility
self.suite_engine_proc.check_global_conf_compat()
if not suite_name:
suite_name = get_suite_name(self.event_handler)
suite_dir = self.suite_engine_proc.get_suite_dir(suite_name)
if not os.path.exists(suite_dir):
raise SuiteNotFoundError(suite_dir)
# Ensure suite is not running
hosts = []
if host:
hosts.append(host)
self.suite_engine_proc.check_suite_not_running(suite_name, hosts)
# Determine suite host to restart suite
if host:
hosts = [host]
else:
hosts = []
val = ResourceLocator.default().get_conf().get_value(
["rose-suite-run", "hosts"], "localhost")
known_hosts = self.host_selector.expand(val.split())[0]
for known_host in known_hosts:
if known_host not in hosts:
hosts.append(known_host)
if hosts == ["localhost"]:
host = hosts[0]
else:
host = self.host_selector(hosts)[0][0]
self.handle_event(SuiteHostSelectEvent(suite_name, "restart", host))
# Suite host environment
run_conf_file_name = self.suite_engine_proc.get_suite_dir(
suite_name, "log", "rose-suite-run.conf")
try:
run_conf = ConfigLoader().load(run_conf_file_name)
except (ConfigSyntaxError, IOError):
environ = None
else:
run_conf_tree = ConfigTree()
run_conf_tree.node = run_conf
environ = self.config_pm(run_conf_tree, "env")
# Restart the suite
self.suite_engine_proc.run(suite_name, host, environ, "restart", args)
# Write suite host name to host file
host_file_name = self.suite_engine_proc.get_suite_dir(
suite_name, "log", "rose-suite-run.host")
open(host_file_name, "w").write(host + "\n")
# Launch the monitoring tool
# Note: maybe use os.ttyname(sys.stdout.fileno())?
if os.getenv("DISPLAY") and host and gcontrol_mode:
self.suite_engine_proc.gcontrol(suite_name, host)
return
示例2: SuiteRunner
# 需要導入模塊: from rose.host_select import HostSelector [as 別名]
# 或者: from rose.host_select.HostSelector import expand [as 別名]
class SuiteRunner(Runner):
"""Invoke a Rose suite."""
SLEEP_PIPE = 0.05
NAME = "suite"
OPTIONS = ["conf_dir", "defines", "defines_suite", "gcontrol_mode", "host",
"install_only_mode", "local_install_only_mode",
"log_archive_mode", "log_keep", "log_name", "name", "new_mode",
"no_overwrite_mode", "opt_conf_keys", "reload_mode", "remote",
"restart_mode", "run_mode", "strict_mode"]
REC_DONT_SYNC = re.compile(
r"\A(?:\..*|cylc-suite\.db.*|log(?:\..*)*|state|share|work)\Z")
def __init__(self, *args, **kwargs):
Runner.__init__(self, *args, **kwargs)
self.host_selector = HostSelector(self.event_handler, self.popen)
self.suite_run_cleaner = SuiteRunCleaner(
event_handler=self.event_handler,
host_selector=self.host_selector,
suite_engine_proc=self.suite_engine_proc)
def run_impl(self, opts, args, uuid, work_files):
# Log file, temporary
if hasattr(self.event_handler, "contexts"):
t_file = TemporaryFile()
log_context = ReporterContext(None, self.event_handler.VV, t_file)
self.event_handler.contexts[uuid] = log_context
# Check suite engine specific compatibility
self.suite_engine_proc.check_global_conf_compat()
# Suite name from the current working directory
if opts.conf_dir:
self.fs_util.chdir(opts.conf_dir)
opts.conf_dir = os.getcwd()
if opts.defines_suite:
suite_section = "jinja2:" + self.suite_engine_proc.SUITE_CONF
if not opts.defines:
opts.defines = []
for define in opts.defines_suite:
opts.defines.append("[" + suite_section + "]" + define)
# --remote=KEY=VALUE,...
if opts.remote:
# opts.name always set for remote.
return self._run_remote(opts, opts.name)
conf_tree = self.config_load(opts)
self.fs_util.chdir(conf_tree.conf_dirs[0])
suite_name = opts.name
if not opts.name:
suite_name = os.path.basename(os.getcwd())
# Automatic Rose constants
# ROSE_ORIG_HOST: originating host
# ROSE_VERSION: Rose version (not retained in run_mode=="reload")
# Suite engine version
jinja2_section = "jinja2:" + self.suite_engine_proc.SUITE_CONF
my_rose_version = ResourceLocator.default().get_version()
suite_engine_key = self.suite_engine_proc.get_version_env_name()
if opts.run_mode == "reload":
prev_config_path = self.suite_engine_proc.get_suite_dir(
suite_name, "log", "rose-suite-run.conf")
prev_config = ConfigLoader()(prev_config_path)
suite_engine_version = prev_config.get_value(
["env", suite_engine_key])
else:
suite_engine_version = self.suite_engine_proc.get_version()
auto_items = {"ROSE_ORIG_HOST": socket.gethostname(),
"ROSE_VERSION": ResourceLocator.default().get_version(),
suite_engine_key: suite_engine_version}
for key, val in auto_items.items():
requested_value = conf_tree.node.get_value(["env", key])
if requested_value:
if key == "ROSE_VERSION" and val != requested_value:
exc = VersionMismatchError(requested_value, val)
raise ConfigValueError(["env", key], requested_value, exc)
val = requested_value
else:
conf_tree.node.set(["env", key], val,
state=conf_tree.node.STATE_NORMAL)
conf_tree.node.set([jinja2_section, key], '"' + val + '"')
# See if suite is running or not
hosts = []
if opts.host:
hosts.append(opts.host)
conf = ResourceLocator.default().get_conf()
known_hosts = self.host_selector.expand(
conf.get_value(["rose-suite-run", "hosts"], "").split() +
conf.get_value(["rose-suite-run", "scan-hosts"], "").split() +
["localhost"])[0]
known_hosts = list(set(known_hosts))
for known_host in known_hosts:
#.........這裏部分代碼省略.........