本文整理匯總了Python中fabric.api.local方法的典型用法代碼示例。如果您正苦於以下問題:Python api.local方法的具體用法?Python api.local怎麽用?Python api.local使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fabric.api
的用法示例。
在下文中一共展示了api.local方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: experiment1collect
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [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")
示例2: drop_db_connections
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def drop_db_connections(database_name):
"""
looks up the db in local settings by its alias and drops any connections
"""
drop_connections = """
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
datname = '{db}'
AND pid <> pg_backend_pid()
""".format(db=database_name)
psql(drop_connections)
示例3: _setup_maven_authentication
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def _setup_maven_authentication(config):
dse_source_build_artifactory_username = config.get('dse_source_build_artifactory_username')
dse_source_build_artifactory_password = config.get('dse_source_build_artifactory_password')
dse_source_build_artifactory_url = config.get('dse_source_build_artifactory_url')
maven_settings = "<settings><mirrors><mirror><id>artifactory</id><name>DataStax Maven repository</name>" \
"<url>{url}</url>" \
"<mirrorOf>central,java.net2,xerial,datanucleus,apache,datastax-public-snapshot,datastax-public-release,datastax-deps,datastax-release,datastax-snapshot</mirrorOf>" \
"</mirror></mirrors><servers><server><id>artifactory</id><username>{username}</username>" \
"<password>{password}</password></server></servers></settings>" \
.format(username=dse_source_build_artifactory_username, password=dse_source_build_artifactory_password,
url=dse_source_build_artifactory_url)
fab.local('rm -rf ~/.m2/settings.xml')
fab.local('mkdir -p ~/.m2')
fab.local('echo "{maven_settings}" > ~/.m2/settings.xml'.format(maven_settings=maven_settings))
示例4: _setup_gradle_authentication
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def _setup_gradle_authentication(config):
dse_source_build_artifactory_username = config.get('dse_source_build_artifactory_username')
dse_source_build_artifactory_password = config.get('dse_source_build_artifactory_password')
dse_source_build_artifactory_url = config.get('dse_source_build_artifactory_url')
gradle_settings = """
allprojects {{
repositories {{
maven {{
url = "\\"{url}\\""
credentials {{
username '{username}'
password '{password}'
}}
}}
}}
}}
""".format(username=dse_source_build_artifactory_username, password=dse_source_build_artifactory_password,
url=dse_source_build_artifactory_url)
fab.local('rm -rf ~/.gradle')
fab.local('mkdir -p ~/.gradle/init.d')
fab.local('echo "{gradle_settings}" > ~/.gradle/init.d/nexus.gradle'.format(gradle_settings=gradle_settings))
示例5: deployMultiClient
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [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])
示例6: build
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def build(name, ask=True, **kwargs):
"""
Build the malicious mote to its target hardware.
:param name: experiment name (or absolute path to experiment)
:param ask: ask confirmation
:param path: expanded path of the experiment (dynamically filled in through 'command' decorator with 'expand')
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
def is_device_present():
with settings(hide(*HIDDEN_ALL), warn_only=True):
return local("if [ -c /dev/ttyUSB0 ]; then echo 'ok'; else echo 'nok'; fi", capture=True) == 'ok'
console = kwargs.get('console')
counter, interval = 0.0, 0.5
while not is_device_present():
sleep(interval)
counter += interval
if counter % 5 == 0:
logger.warning("Waiting for mote to be detected...")
elif counter >= 120:
logger.error("Something failed with the mote ; check that it mounts to /dev/ttyUSB0")
return
remake(name, build=True, **kwargs) if console is None else console.do_remake(name, build=True, **kwargs)
return "Mote built on /dev/ttyUSB0"
示例7: versions
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def versions(**kwargs):
"""
Check versions of Contiki-OS and RPL Attacks Framework.
:param kwargs: simulation keyword arguments (see the documentation for more information)
"""
with hide(*HIDDEN_ALL):
with lcd(CONTIKI_FOLDER):
cversion = local('git --git-dir .git describe --tags --always', capture=True)
logger.warn("Contiki-OS: {}".format(cversion))
with lcd(FRAMEWORK_FOLDER):
cversion = local('git --git-dir .git describe --tags --always', capture=True)
logger.warn("RPL Attacks Framework: {}".format(cversion))
# **************************************** MAGICAL COMMANDS ***************************************
示例8: __init__
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def __init__(self, name, cwd=None):
"""Create a tmux session.
Args:
name (str): name of the new session
cwd (str): initial directory of the session
Options used:
-d: do not attach to the new session
-s: specify a name for the session
"""
self.name = name
with settings(hide('warnings'), warn_only=True):
result = local("tmux new -d -s {}".format(name)) # start tmux session
if result.failed:
raise TmuxSessionExists()
if cwd is None:
cwd = os.getcwd()
# move to current directory
self.run("cd {}".format(cwd))
示例9: modify_server_json
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def modify_server_json():
params=read_ini_file(sys.argv[1:])
if not params:
return None
if not params.has_key('server_file'):
return None
server_file = params['server_file']
timestamp = dt.now().strftime("%Y_%m_%d_%H_%M_%S")
local( 'cp %s %s.org.%s' %(server_file, server_file, timestamp) )
in_file = open( server_file, 'r' )
in_data = in_file.read()
server_dict = json.loads(in_data)
update_roles_from_testbed_py(server_dict)
out_file = open(server_file, 'w')
out_data = json.dumps(server_dict, indent=4)
out_file.write(out_data)
out_file.close()
return server_dict
示例10: get_vns_with_vns_id_from_db
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def get_vns_with_vns_id_from_db():
vns_id = get_user_vns_id()
if not vns_id:
params=read_ini_file(sys.argv[1:])
vns_id = params['vns_id']
vns_dict = {"vns": []}
temp_dir= expanduser("~")
file_name = '%s/vns.json' %(temp_dir)
local('server-manager show --detail vns --vns_id %s \
> %s' %(vns_id, file_name) )
in_file = open( file_name, 'r' )
in_data = in_file.read()
vns_dict = json.loads(in_data)
return vns_dict
示例11: get_server_with_ip_from_db
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def get_server_with_ip_from_db(ip=None):
params=read_ini_file(sys.argv[1:])
server_dict={}
if not ip:
print "Please provide an ip as input arg"
return ip
temp_dir= expanduser("~")
file_name = '%s/server.json' %(temp_dir)
local('server-manager show --detail server --ip %s \
> %s' %(ip, file_name) )
in_file = open( file_name, 'r' )
in_data = in_file.read()
server_dict = json.loads(in_data)
return server_dict
示例12: deploy
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def deploy(target='dev', sha1=None):
if sha1 is None:
# get current working git sha1
sha1 = local('git rev-parse HEAD', capture=True)
# server code reset to current working sha1
home_dir = '/home/pyconkr/{target}.pycon.kr/pyconkr-2016'.format(target=target)
if target == 'dev':
python_env = '/home/pyconkr/.pyenv/versions/pyconkr-2016-dev'
else:
python_env = '/home/pyconkr/.pyenv/versions/pyconkr-2016'
with settings(cd(home_dir), shell_env(DJANGO_SETTINGS_MODULE='pyconkr.settings_prod')):
sudo('git fetch --all -p', user='pyconkr')
sudo('git reset --hard ' + sha1, user='pyconkr')
sudo('bower install', user='pyconkr')
sudo('%s/bin/pip install -r requirements.txt' % python_env, user='pyconkr')
sudo('%s/bin/python manage.py compilemessages' % python_env, user='pyconkr')
sudo('%s/bin/python manage.py migrate' % python_env, user='pyconkr')
sudo('%s/bin/python manage.py collectstatic --noinput' % python_env, user='pyconkr')
# worker reload
run('echo r > /var/run/pyconkr-2016-%s.fifo' % target)
示例13: _get_vagrant_connection
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def _get_vagrant_connection():
local('vagrant up')
result = local('vagrant ssh-config', capture=True)
hostname = re.findall(r'HostName\s+([^\n]+)', result)[0]
port = re.findall(r'Port\s+([^\n]+)', result)[0]
env.hosts = ['%s:%s' % (hostname, port)]
env.user = re.findall(r'User\s+([^\n]+)', result)[0]
env.key_filename = re.findall(r'IdentityFile\s+([^\n]+)', result)[0].lstrip("\"").rstrip("\"")
示例14: install_phantomjs
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def install_phantomjs():
# The PhantomJS headless browser
sudo('apt-get -y install fontconfig')
run('wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2')
run('tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2')
sudo('mv phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs')
示例15: get_host_user_and_ssh_key_path
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import local [as 別名]
def get_host_user_and_ssh_key_path(instance_name, project, zone):
"""Return a tuple of (hostname, username and ssh_key_path)."""
output = api.local(
'gcloud compute ssh --project "%s" --zone "%s" %s --dry-run' %
(project, zone, instance_name),
capture=True)
print(output)
m = re.match('/usr/bin/ssh .*-i ([^ ]+)(?: -o [^ ]+)* ([^ ]+)@([^ ]+)',
output)
return (m.group(3), m.group(2), m.group(1))