2016-06-16 15 views
0

私はfabric APIには新しく、各ホストごとに異なるコマンドライン引数を渡そうとしています。だから、今ここにいるのです。現在、以下のビットは、3つのホストのそれぞれで、スクリプトget_num_reviews_aws.pyを正しく並列に実行します。私が探している何ファブリック実行タスクのコマンドライン引数を渡す

hosts = [[email protected], 
     [email protected], 
     [email protected]] 

#%% 
from fabric.api import run, parallel 
from fabric.tasks import execute 


%% 
@parallel 
def webscraper(): 
    run("python get_num_reviews_aws.py") 


#%% run on hosts 
execute(webscraper, hosts=hosts) 

は、ホストごとに異なっているPythonスクリプトにコマンドライン引数を渡すことができるようにすることですが、それでも、その後、並列に実行してきました。したがって、このような何か:

@parallel 
def webscraper(start, end): 
    run("python get_num_reviews_aws.py %s %s" % (start, end)) 

、その後、基本的に各ホストのstartendの異なるセットを持っています。私はあなたがhere定義された役割を使用することができると思い

start = [1, 2, 3] 
end = [4, 5, 6] 

execute(webscraper, start, end, hosts=hosts) 

答えて

0

:何を私にハングアップするのは、私がホストのリストを渡すが、私はのように私は、各コマンドライン引数のリストを渡すとは思わないです。

+0

一見すると、それは問題を解決していないようです。 'roles'デコレータは、ホストと接続文字列を検索するためのものですが、これは私が直面している課題ではありません。私は既に上記の 'hosts'のリストを渡します。 –

0

これは私のために、いくつか他のものを見てから働いたsimilar questions on SO

hosts = [[email protected], 
     [email protected], 
     [email protected]] 


#%% get username and host 
hosts = ["[email protected]" + ip.ip_address for ip in instance_lst] 


#%% Create my command line arguments and store them in a dict 
# use the hostname as the key and store arguments in a tuple 
host_dict = {host: (0, 10 + x) for x, host in enumerate(hosts)} 


#%% 
from fabric.api import run, parallel, env 
from fabric.tasks import execute 


#%% set environment 
env.hosts = hosts 


#%% 
@parallel 
def webscraper(host_dict): 
    host = "[email protected]" + env.host # cuts off the username, so have to re-add 
    start_end = host_dict[host] # get the start and end for each host 
    run("python get_num_reviews_aws.py %s %s" % start_end) 


#%% run on hosts 
# since I stored the hosts in an environment, don't need to pass hosts 
execute(webscraper, host_dict) 
関連する問題