本文整理汇总了Python中fabric.context_managers.settings方法的典型用法代码示例。如果您正苦于以下问题:Python context_managers.settings方法的具体用法?Python context_managers.settings怎么用?Python context_managers.settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.context_managers
的用法示例。
在下文中一共展示了context_managers.settings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_notebook_running
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def is_notebook_running(self, ip_address_string, attempts=1):
""" Checks if jupyterhub/notebook is running on the target machine, returns True if Yes, False if not.
If an attempts count N is provided the check will be run N times or until the notebook is running, whichever
comes first. """
with settings(**FABRIC_DEFAULTS, host_string=ip_address_string):
for i in range(attempts):
self.log.debug("function check_notebook_running for user %s, attempt %s..." % (self.user.name, i+1))
output = yield run("ps -ef | grep jupyterhub-singleuser")
for line in output.splitlines(): #
#if "jupyterhub-singleuser" and NOTEBOOK_SERVER_PORT in line:
if "jupyterhub-singleuser" and str(NOTEBOOK_SERVER_PORT) in line:
self.log.debug("the following notebook is definitely running:")
self.log.debug(line)
return True
self.log.debug("Notebook for user %s not running..." % self.user.name)
yield gen.sleep(1)
self.log.error("Notebook for user %s is not running." % self.user.name)
return False
### Retun SSH_CONNECTION_FAILED if ssh connection failed
示例2: remote_notebook_start
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def remote_notebook_start(self, instance):
""" Do notebook start command on the remote server."""
# Setup environments
env = self.get_env()
lenv=''
for key in env:
lenv = lenv + key + "=" + env[key] + " "
# End setup environment
self.log.debug("function remote_server_start %s" % self.user.name)
worker_ip_address_string = instance.private_ip_address
start_notebook_cmd = self.cmd + self.get_args()
start_notebook_cmd = " ".join(start_notebook_cmd)
self.log.info("Starting user %s jupyterhub" % self.user.name)
with settings(user = self.user.name, key_filename = FABRIC_DEFAULTS["key_filename"], host_string=worker_ip_address_string):
yield sudo("%s %s --user=%s --notebook-dir=/home/%s/ --allow-root > /tmp/jupyter.log 2>&1 &" % (lenv, start_notebook_cmd,self.user.name,self.user.name), pty=False)
self.log.debug("just started the notebook for user %s, waiting." % self.user.name)
try:
self.user.settings[self.user.name] = instance.public_ip_address
except:
self.user.settings[self.user.name] = ""
# self.notebook_should_be_running = True
yield self.is_notebook_running(worker_ip_address_string, attempts=30)
示例3: _offline_tag_commit
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def _offline_tag_commit(self):
commit = local('cd {}/commcare-hq && git show-ref --hash --heads {}'.format(
OFFLINE_STAGING_DIR,
env.deploy_metadata.deploy_ref,
), capture=True)
tag_name = '{}-{}-offline-deploy'.format(self.timestamp, self._environment)
local('cd {staging_dir}/commcare-hq && git tag -a -m "{message}" {tag} {commit}'.format(
staging_dir=OFFLINE_STAGING_DIR,
message='{} offline deploy at {}'.format(self._environment, self.timestamp),
tag=tag_name,
commit=commit,
))
with settings(warn_only=True):
local('cd {staging_dir}/commcare-hq && git push origin {tag}'.format(
staging_dir=OFFLINE_STAGING_DIR,
tag=tag_name,
))
示例4: secure_create_file
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def secure_create_file(filepath, user_group, mode=600):
user, group = user_group.split(':')
missing_owner_code = 42
command = \
"( getent passwd {user} >/dev/null || exit {missing_owner_code} ) &&" \
" echo '' > {filepath} && " \
"chown {user_group} {filepath} && " \
"chmod {mode} {filepath} ".format(
filepath=filepath, user=user, user_group=user_group, mode=mode,
missing_owner_code=missing_owner_code)
with settings(warn_only=True):
result = sudo(command)
if result.return_code == missing_owner_code:
abort("User %s does not exist. Make sure the Presto server RPM "
"is installed and try again" % user)
elif result.failed:
abort("Failed to securely create file %s" % (filepath))
示例5: secure_create_directory
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def secure_create_directory(filepath, user_group, mode=755):
user, group = user_group.split(':')
missing_owner_code = 42
command = \
"( getent passwd {user} >/dev/null || exit {missing_owner_code} ) && " \
"mkdir -p {filepath} && " \
"chown {user_group} {filepath} && " \
"chmod {mode} {filepath} ".format(
filepath=filepath, user=user, user_group=user_group, mode=mode,
missing_owner_code=missing_owner_code)
with settings(warn_only=True):
result = sudo(command)
if result.return_code == missing_owner_code:
abort("User %s does not exist. Make sure the Presto server RPM "
"is installed and try again" % user)
elif result.failed:
abort("Failed to securely create file %s" % (filepath))
示例6: is_port_in_use
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def is_port_in_use(host):
_LOGGER.info("Checking if port used by Prestoserver is already in use..")
try:
portnum = lookup_port(host)
except Exception:
_LOGGER.info("Cannot find port from config.properties. "
"Skipping check for port already being used")
return 0
with settings(hide('warnings', 'stdout'), warn_only=True):
output = run('netstat -ln |grep -E "\<%s\>" |grep LISTEN' % str(portnum))
if output:
_LOGGER.info("Presto server port already in use. Skipping "
"server start...")
error('Server failed to start on %s. Port %s already in use'
% (env.host, str(portnum)))
return output
示例7: collect_node_information
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def collect_node_information():
with closing(PrestoClient(get_coordinator_role()[0], env.user)) as client:
with settings(hide('warnings')):
error_message = check_presto_version()
if error_message:
external_ip = 'Unknown'
is_running = False
else:
with settings(hide('warnings', 'aborts', 'stdout')):
try:
external_ip = get_ext_ip_of_node(client)
except:
external_ip = 'Unknown'
try:
is_running = service('status')
except:
is_running = False
return external_ip, is_running, error_message
示例8: coordinator_config
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def coordinator_config():
config_path = os.path.join(REMOTE_CONF_DIR, CONFIG_PROPERTIES)
config_host = env.roledefs['coordinator'][0]
try:
data = StringIO()
with settings(host_string='%s@%s' % (env.user, config_host)):
with hide('stderr', 'stdout'):
temp_dir = run('mktemp -d /tmp/prestoadmin.XXXXXXXXXXXXXX')
try:
get(config_path, data, use_sudo=True, temp_dir=temp_dir)
finally:
run('rm -rf %s' % temp_dir)
data.seek(0)
return PrestoConfig.from_file(data, config_path, config_host)
except:
_LOGGER.info('Could not find Presto config.')
return PrestoConfig(None, config_path, config_host)
示例9: test_should_set_all_hosts
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def test_should_set_all_hosts(self):
"""
should set env.all_hosts to its derived host list
"""
hosts = ['a', 'b']
roledefs = {'r1': ['c', 'd']}
roles = ['r1']
exclude_hosts = ['a']
def command():
self.assertEqual(set(env.all_hosts), set(['b', 'c', 'd']))
task = Fake(callable=True, expect_call=True).calls(command)
with settings(hide('everything'), roledefs=roledefs):
execute(
task, hosts=hosts, roles=roles, exclude_hosts=exclude_hosts
)
示例10: check_system_support
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def check_system_support():
# check hardware support
if run("egrep '^flags.*(vmx|svm)' /proc/cpuinfo > /dev/null").failed:
abort("Need hardware VM support (vmx)")
# check minimum kernel version:
# Linux kernel under 3.13.0 has a bug where the kernel crash
# when EPT support enabled with FUSE+mmap.
WORKING_KERNEL_VERSION = "3.13.0"
kernel_version = platform.platform().split("-")[1]
if LooseVersion(kernel_version) < LooseVersion(WORKING_KERNEL_VERSION):
msg = "Linux Kernel lower than %s has a bug when using FUSE + mmap"\
% WORKING_KERNEL_VERSION
abort(msg)
# check OS version
cmd = "cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F'=' '{print $2}'"
with settings(hide('everything'), warn_only=True):
os_dist = run(cmd)
if os_dist != 'trusty' and os_dist != "xenial":
msg = "Support only Ubuntu Precise (14.04) or Ubuntu Trusty (16.04)"
abort(msg)
return os_dist
return None
示例11: wait_until_SSHable
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def wait_until_SSHable(self, ip_address_string, max_retries=1):
""" Run a meaningless bash command (a comment) inside a retry statement. """
self.log.debug("function wait_until_SSHable for user %s" % self.user.name)
with settings(**FABRIC_DEFAULTS, host_string=ip_address_string):
ret = yield run("# waiting for ssh to be connectable for user %s..." % self.user.name, max_retries=max_retries)
if ret == "RETRY_FAILED":
ret = "SSH_CONNECTION_FAILED"
return (ret)
示例12: _is_preindex_complete
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def _is_preindex_complete():
with settings(warn_only=True), hide('warnings'):
return sudo(
('{virtualenv_root}/bin/python '
'{code_root}/manage.py preindex_everything '
'--check').format(
virtualenv_root=env.py3_virtualenv_root,
code_root=env.code_root,
user=env.user,
),
).succeeded
示例13: check_ready
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def check_ready():
_print_stats(os.path.join(OFFLINE_STAGING_DIR, 'commcare-hq'))
_print_stats(os.path.join(OFFLINE_STAGING_DIR, 'commcare-hq', 'bower_components'))
_print_stats(os.path.join(OFFLINE_STAGING_DIR, 'commcare-hq', 'node_modules'))
_print_stats(os.path.join(OFFLINE_STAGING_DIR, 'commcare-hq', 'wheelhouse'))
_print_stats(os.path.join(OFFLINE_STAGING_DIR, 'formplayer.jar'))
with settings(warn_only=True):
commit = local('cd {}/commcare-hq && git show-ref --hash --heads {}'.format(
OFFLINE_STAGING_DIR,
env.deploy_metadata.deploy_ref,
), capture=True)
print('Preparing to deploy ref {} on commit {}'.format(env.deploy_metadata.deploy_ref, commit))
示例14: tag_setup_release
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def tag_setup_release(self):
if _github_auth_provided():
try:
self.repo.create_git_ref(
ref='refs/tags/' + '{}-{}-setup_release'.format(self.timestamp, self._environment),
sha=self.deploy_ref,
)
except UnknownObjectException:
raise Exception(
'Github API key does not have the right settings. '
'Please create an API key with the public_repo scope enabled.'
)
return True
return False
示例15: _ssh_env
# 需要导入模块: from fabric import context_managers [as 别名]
# 或者: from fabric.context_managers import settings [as 别名]
def _ssh_env(self):
with self._capfd.disabled():
with context_managers.settings(fabric.api.hide('everything'),
**_FABRIC_ENV):
yield