2011-12-19 7 views
1

ファブリックとギヤマンを使用してコマンドを一括して実行するプログラムを作成しています。fabfileを使用しないファブリック内のリモートssh

次は私が労働者とクライアントのコードを実行しているときに問題があり、作業員はまだ尋ねる次は私のワーカーコード

import sys , os , json 
from fabric import * 
from fabric.api import * 
import gearman 
from gearman import GearmanWorker 




#executing the fab command . All the configurations are mentioned in fabfile.py 
def exe_job(gmWorker , gmJob): 
#host = 'synergy.corp.yahoo.com' 
#d = json.loads(gmJob) 
#run (str(d[cmd]), str(d[host])) 
d = json.loads(gmJob.data) 
env.hoststring = [ str(d['host']) ] 
run (str(d['cmd'])) 
return gmJob.data 


#woker node id to be specified in here 
gm_worker = gearman.GearmanWorker(['localhost:4730']) 
#gm_worker.set_client_id('client1') 
gm_worker.register_task('exe_job',exe_job) 
gm_worker.work() 

あるGearman

import sys , os , json 
from fabric.api import * 
import gearman 
from gearman import GearmanClient 


def check_request_status(job_request): 
    if job_request.complete: 
     print "Job %s finished! Result: %s - %s" % (job_request.job.unique, job_request.state, job_request.result) 
    elif job_request.timed_out: 
     print "Job %s timed out!" % job_request.unique 
    elif job_request.state == JOB_UNKNOWN: 
     print "Job %s connection failed!" % job_request.unique 


#gearman client (test file) 
gm_client = gearman.GearmanClient(['localhost:4730']) 

# See gearman/job.py to see attributes on the GearmanJobRequest 
d = {} 
d['host'] = 'xyz.abc.com' 
d['cmd'] = 'ls -l' 
a = json.dumps(d) 

completed_job_request = gm_client.submit_job("exe_job", a) 
check_request_status(completed_job_request) 

ためのクライアントコードであります私はホスト名eventhough私はホスト名を提供しています。 Fabricにホスト名を設定する他の方法はありますか?私はサブプロセスを生成し、ファブリックcmdを実行するつもりはありません。それを修正

答えて

0

  1. JSONは、Unicode形式ように使用されるのsimplejson内のデータを返していました。
  2. そのenv.host_stringはhostnameを保持する変数です。

関連する問題