本文整理汇总了Python中fabric.api.env.host方法的典型用法代码示例。如果您正苦于以下问题:Python env.host方法的具体用法?Python env.host怎么用?Python env.host使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.api.env
的用法示例。
在下文中一共展示了env.host方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keys
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def keys():
if "rsdir" not in env:
secret = file("secret.key").read()
public = rscoin.Key(secret, public=False)
pid = b64encode(public.id())
env["rsdir"] = {"special": pid, "directory": []}
[_, host] = env.host_string.split("@")
with cd('/home/ubuntu/projects/rscoin'):
run('touch secret.key')
run('rm secret.key')
result = run('python derivekey.py --store')
[_, key] = result.strip().split()
kid = b64encode(rscoin.Key(b64decode(key)).id())
env["rsdir"]["directory"] += [ [kid, host, 8080] ]
from json import dumps
file("directory.conf", "w").write(dumps(env["rsdir"]))
示例2: experiment1collect
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def experiment1collect():
# run("ls experiment1/*")
with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
get('issue-times.txt', '%s/%s-issue-times.txt' % (env.expname, env.host))
with lcd(env.expname):
local("cat %s-issue-times.txt >> issue-times.txt" % env.host)
with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
get('r1-times.txt', '%s/%s-r1-times.txt' % (env.expname, env.host))
with lcd(env.expname):
local("cat %s-r1-times.txt >> r1-times.txt" % env.host)
with cd('/home/ubuntu/projects/rscoin/%s' % env.expname):
get('r2-times.txt', '%s/%s-r2-times.txt' % (env.expname, env.host))
with lcd(env.expname):
local("cat %s-r2-times.txt >> r2-times.txt" % env.host)
# local("python exp1plot.py experiment1")
示例3: deployMultiClient
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def deployMultiClient(num):
local('rm -f testMap.csv')
for i in range(int(num)):
dirc = 'client%s' % i
with cd(dirc):
with cd('loopix'):
run("git pull")
run("git checkout %s" % BRANCH)
with cd('loopix/loopix'):
N = hexlify(os.urandom(8))
providers = getProvidersNames()
prvName = random.choice(providers)
port = int(9999 - i)
print "CLIENT: Client%s" % N
run("python setup_client.py %d %s Client%s %s" % (port, str(env.host), N, prvName))
get('publicClient.bin', 'publicClient-%d-%s.bin'%(port, env.host))
with open('testMap.csv', 'a') as outfile:
csvW = csv.writer(outfile)
csvW.writerow(['Client%s'%N, dirc])
示例4: deploy
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def deploy(clients):
execute(deployMulti, clients)
#
# @roles("providers")
# def checkHost():
# print env.host
#
#
# @runs_once
# def takeNamesDb():
# database = "example.db"
# db = sqlite3.connect(database)
# c = db.cursor()
# c.execute("SELECT * FROM Providers")
# providers = c.fetchall()
# for p in providers:
# print p
#
#
示例5: is_port_in_use
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [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
示例6: get_ext_ip_of_node
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def get_ext_ip_of_node(client):
node_properties_file = os.path.join(constants.REMOTE_CONF_DIR,
'node.properties')
with settings(hide('stdout')):
node_uuid = sudo('sed -n s/^node.id=//p ' + node_properties_file)
external_ip_row = execute_external_ip_sql(client, node_uuid)
external_ip = ''
if len(external_ip_row) > 1:
warn_more_than_one_ip = 'More than one external ip found for ' + env.host + \
'. There could be multiple nodes associated with the same node.id'
_LOGGER.debug(warn_more_than_one_ip)
warn(warn_more_than_one_ip)
return external_ip
for row in external_ip_row:
if row:
external_ip = row[0]
if not external_ip:
_LOGGER.debug('Cannot get external IP for ' + env.host)
external_ip = 'Unknown'
return external_ip
示例7: announce_deploy
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def announce_deploy(project, channel=None, username=None, icon_emoji=None, web_hook_url=None):
"""
announce_deploy - a decorator to announces a new deploy of the specificed project start,
who started it and when. Also sends a message when the deploy ends and how long it took.
"""
def real_announce_deploy(func):
@functools.wraps(func)
def inner_decorator(*args, **kwargs):
deploy_start = datetime.datetime.utcnow()
# Get user's identity from a environment variable SLACK_IDENTITY, otherwise just get the default username
deployment_handler = os.environ.get('SLACK_IDENTITY', getpass.getuser())
# Send a message on deployment start...
if env.host:
start_message = "%s deployment started by %s on %s" % (project, deployment_handler, env.host)
else:
start_message = "%s deployment started by %s" % (project, deployment_handler)
send_slack_message(start_message, channel=channel, username=username, icon_emoji=icon_emoji, web_hook_url=web_hook_url)
return_value = func(*args, **kwargs)
# ... and upon finish
if env.host:
end_message = "%s deployment ended by %s on %s. Took: %s" % (project, deployment_handler, env.host, str(datetime.datetime.utcnow() - deploy_start))
else:
end_message = "%s deployment ended by %s. Took: %s" % (project, deployment_handler, str(datetime.datetime.utcnow() - deploy_start))
send_slack_message(end_message, channel=channel, username=username, icon_emoji=icon_emoji)
return return_value
return inner_decorator
return real_announce_deploy
示例8: elasticsearch
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def elasticsearch():
global ELASTICSEARCH_CHECKED
if not ELASTICSEARCH_CHECKED:
run("curl -XGET 'http://%s:9200/_cluster/health?pretty=true'" % env.host)
ELASTICSEARCH_CHECKED = True
run('service elasticsearch status')
示例9: sync_offline_from_control
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def sync_offline_from_control():
for host in _hosts_in_roles(ROLES_ALL_SRC, exclude_roles=ROLES_DEPLOY):
run("rsync -rvz --exclude 'commcare-hq/*' {} {}".format(
env.offline_code_dir,
'{}@{}:{}'.format(env.user, host, env.offline_releases)
))
示例10: update_code_offline
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def update_code_offline():
'''
An online release usually clones from the previous release then tops
off the new updates from the remote github. Since we can't access the remote
Github, we do this:
1. Clone the current release to the user's home directory
2. Update that repo with any changes from the user's local copy of HQ (in offline-staging)
3. Clone the user's home repo to the release that is being deployed (code_root)
'''
clone_current_release_to_home_directory()
git_remote_url = 'ssh://{user}@{host}{code_dir}'.format(
user=env.user,
host=env.host,
code_dir=os.path.join(env.offline_code_dir, 'commcare-hq')
)
local('cd {}/commcare-hq && git push {}/.git {}'.format(
OFFLINE_STAGING_DIR,
git_remote_url,
env.deploy_metadata.deploy_ref,
))
# Iterate through each submodule and push master
local("cd {}/commcare-hq && git submodule foreach 'git push {}/$path/.git --all'".format(
OFFLINE_STAGING_DIR,
git_remote_url,
))
clone_home_directory_to_release()
with cd(env.code_root):
sudo('git checkout `git rev-parse {}`'.format(env.deploy_metadata.deploy_ref))
sudo('git reset --hard {}'.format(env.deploy_metadata.deploy_ref))
sudo('git submodule update --init --recursive')
# remove all untracked files, including submodules
sudo("git clean -ffd")
sudo('git remote set-url origin {}'.format(env.code_repo))
sudo("find . -name '*.pyc' -delete")
示例11: _decommission_host
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def _decommission_host(host):
files.comment(
'/etc/nginx/sites-available/{}_commcare'.format(env.deploy_env),
'^[ ]*server[ ]+{}'.format(host),
use_sudo=True,
)
_check_and_reload_nginx()
示例12: decommissioned_host
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def decommissioned_host(host):
more_than_one_webworker = len(env.roledefs['django_app']) > 1
if more_than_one_webworker:
execute(_decommission_host, host)
yield
if more_than_one_webworker:
execute(_recommission_host, host)
示例13: restart_webworkers
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def restart_webworkers():
with decommissioned_host(env.host):
_services_restart()
示例14: run_notebook
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def run_notebook(workdir=None, args=None, kwargs=None):
args = args or []
kwargs = kwargs or {}
command = "jupyter notebook --ip {host} --allow-root".format(host=env.host).split() + list(args)
return run_command(command, workdir=workdir)
示例15: run_jupyterlab
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import host [as 别名]
def run_jupyterlab(workdir=None, args=None, kwargs=None):
args = args or []
kwargs = kwargs or {}
command = "jupyter lab --ip {host} --allow-root".format(host=env.host).split() + list(args)
return run_command(command, workdir=workdir)