2016-06-16 5 views
0

저는 fabric API에 익숙하지 않으며 각 호스트마다 다른 명령 행 인수를 전달하려고합니다. 그래서, 지금 여기에 있습니다. 현재 아래의 비트는 세 호스트 각각에서 병렬로 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) 

각 호스트에 대한 다른 파이썬 스크립트에 명령 줄 인수를 전달 할 수있을 것입니다,하지만 여전히 병렬로 실행할 수있다. 이 같은 뭔가 :

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

다음은 기본적으로 각 호스트에 대해 다른 start의 세트 end 있습니다. 난 당신이 here 정의 된 역할을 사용할 수 있다고 생각

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

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

답변

0

: 어떤 날 매달려 것은 내가 호스트 목록을 통과하지만 난처럼, 각 명령 줄 인수에 대한 목록을 통과 생각하지 않는 것입니다.

+0

언뜻보기에 문제가 해결되지 않는 것 같습니다. 'roles' 데코레이터는 호스트와 연결 문자열을 찾는 것입니다. 이것은 제가 직면하고있는 도전이 아닙니다. 위의'호스트 '목록을 이미 전달했습니다. –

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)