本文整理汇总了Python中fabric.api.execute方法的典型用法代码示例。如果您正苦于以下问题:Python api.execute方法的具体用法?Python api.execute怎么用?Python api.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.api
的用法示例。
在下文中一共展示了api.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_command
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def run_command(self, hosts, parallel_pool_size=1):
from fabric.api import execute, sudo, env, parallel
if env.ssh_config_path and os.path.isfile(os.path.expanduser(env.ssh_config_path)):
env.use_ssh_config = True
env.forward_agent = True
# pass `-E` to sudo to preserve environment for ssh agent forwarding
env.sudo_prefix = "sudo -SE -p '%(sudo_prompt)s' "
env.user = self.user_name
env.password = self.password
env.hosts = hosts
env.warn_only = True
def _task():
result = sudo(self.command, user=self.user_as)
return result
task = _task
if parallel_pool_size > 1:
task = parallel(pool_size=parallel_pool_size)(_task)
res = execute(task)
return res
示例2: getrunning
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def getrunning(config):
"""
Gets all the running Cassandra processes so you know if C* is fully running across the cluster
"""
_set_hosts(config)
results = execute(_getpid)
i = 1
completed = 0
for host, result in results.items():
print "host {} [{}] pid is [{}]".format(i, host, result.strip())
i += 1
if len(result) > 1:
completed += 1
print "-"*50
print "{} out of {} hosts are running C*".format(completed, len(results))
print "-"*50
示例3: _bootstrapcass
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def _bootstrapcass():
# FIX HOSTS FILE for metrics to record remote IP properly
host = 'ip-%s' % env.host_string.replace('.','-')
sudo('sed -i "/127/c\\127.0.0.1 {} localhost" /etc/hosts'.format(host))
sudo("apt-get update")
# install required packages
sudo("""apt-get -y install --fix-missing libjna-java binutils pssh pbzip2 xfsprogs schedtool zip unzip ruby openssl ruby-dev libruby1.9.1 curl liblzo2-dev ntp subversion python-pip unzip xfsprogs ethtool""")
# install sysadmin tools
sudo("apt-get -y install --fix-missing iftop sysstat htop s3cmd nethogs nmon dstat tree collectd collectd-utils")
execute(_installjava)
#fix clocksource -> network performance
sudo("echo tsc > /sys/devices/system/clocksource/clocksource0/current_clocksource")
示例4: swarm_init
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def swarm_init():
"""
enable Docker swarm mode
"""
def init():
if not init.join_command:
fabricio.run(
'docker swarm init --advertise-addr {0}'.format(fab.env.host),
ignore_errors=True,
quiet=False,
)
join_token = fabricio.run(
'docker swarm join-token --quiet manager',
ignore_errors=True,
)
init.join_command = (
'docker swarm join --token {join_token} {host}:2377'
).format(join_token=join_token, host=fab.env.host)
else:
fabricio.run(init.join_command, ignore_errors=True, quiet=False)
init.join_command = None
with fab.settings(hosts=hosts):
fab.execute(init)
示例5: execute
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def execute(*args, **kwargs): # pragma: no cover
warnings.warn(
'fabricio.execute() is deprecated in favour of fabric.api.execute()',
DeprecationWarning,
)
warnings.warn(
'fabricio.execute() is deprecated and will be removed in v0.6, '
'use fabric.api.execute() instead',
RuntimeWarning, stacklevel=2,
)
try:
task, args = args[0], args[1:]
except IndexError:
raise TypeError('must provide task to execute')
default_name = '{command}.{task_name}({id})'.format(
command=fab.env.command,
task_name=getattr(task, 'name', task.__name__),
id=id(task),
)
with utils.patch(task, 'name', get_task_name(task) or default_name):
return fab.execute(task, *args, **kwargs)
示例6: test_rollback
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def test_rollback(self, revert, migrate_back):
tasks_list = tasks.DockerTasks(service=TestContainer(), hosts=['host'])
rollback = mock.Mock()
rollback.attach_mock(migrate_back, 'migrate_back')
rollback.attach_mock(revert, 'revert')
revert.return_value = True
# with migrate_back disabled
tasks_list.rollback.name = '{0}__migrate_disabled'.format(self)
fab.execute(tasks_list.rollback, migrate_back='no')
migrate_back.assert_not_called()
revert.assert_called_once()
rollback.reset_mock()
# default case
tasks_list.rollback.name = '{0}__default'.format(self)
fab.execute(tasks_list.rollback)
self.assertListEqual(
[mock.call.migrate_back(), mock.call.revert()],
rollback.mock_calls,
)
rollback.reset_mock()
示例7: configure_idm_external_auth
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def configure_idm_external_auth(idm_password=None):
"""Configure the Satellite6 Server for External Authentication.
Expects the following environment variables:
IDM_PASSWORD
IDM Server Password to fetch a token.
"""
result = run('id admin')
if result.failed:
print('Please execute enroll_idm before configuring External Auth')
sys.exit(1)
if idm_password is None:
idm_password = os.environ.get('IDM_PASSWORD')
run('echo {0} | kinit admin'.format(idm_password))
run('ipa service-add HTTP/$(hostname)')
run('satellite-installer --foreman-ipa-authentication=true')
run('foreman-maintain service restart')
示例8: init
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def init():
# local("grep rsa ~/.ssh/known_hosts > known_hosts")
local("python derivekey.py --store")
execute(passcache)
示例9: deploy
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def deploy():
execute(gitall)
execute(keys)
execute(loaddir)
execute(loadsecret)
示例10: experiment1
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def experiment1():
env.messages = 2000
env.expname = "experiment1"
local( "rm -rf experiment1" )
local( "mkdir experiment1" )
execute( "experiment1run" )
execute( "experiment1pre" )
execute( "experiment1actual" )
execute( "experiment1collect" )
local("python exp1plot.py experiment1")
local("python estthroughput.py %s > %s/stats.txt" % (env.expname, env.expname))
示例11: __init__
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def __init__(self, user_name, password, command, user_as=None):
"""
:param user_name: Username to login with
:param password: Password of the user
:param command: command to execute (This command will be executed using sudo. )
"""
self.user_name = user_name
self.password = password
self.command = command
self.user_as = user_as
示例12: _setup_env
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def _setup_env(env_name):
env.env_name = env_name
load_env()
_set_code_branch(env.default_branch)
_confirm_environment_time(env_name)
execute(env_common)
execute(_confirm_deploying_same_code)
示例13: kill_stale_celery_workers
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def kill_stale_celery_workers():
"""
Kills celery workers that failed to properly go into warm shutdown
"""
execute(release.kill_stale_celery_workers)
示例14: rollback_formplayer
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def rollback_formplayer():
execute(formplayer.rollback_formplayer)
execute(supervisor.restart_formplayer)
示例15: reverse_patch
# 需要导入模块: from fabric import api [as 别名]
# 或者: from fabric.api import execute [as 别名]
def reverse_patch(patchfile=None):
"""
Used to reverse a git patch created via `git format-patch`. Usage:
fab <env> reverse_patch:patchfile=/path/to/patch
Note: Only use this when absolutely necessary. Normally we should use regular
deploy. This is only used for patching when we do not have access to the Internet.
"""
if not patchfile:
print(red("Must specify patch filepath"))
exit()
execute(release.reverse_patch, patchfile)
silent_services_restart(use_current_release=True)