#!/usr/bin/python #-*- coding: UTF-8 -*- from fabric.api import * from fabric.context_managers import * # env.hosts=['root@192.168.2.2'] # env.password='mypass' def t_exportvminfor(): remote_fab_folder = '/var/fab/' local_file = 'D:\py\sf\ExportKVM.py' local_result_folder = 'D:pysf' #判断/var/fabric目录是否存在 run('if [ ! -d /var/fab ]; then mkdir /var/fab; fi') #将ExportKVM_vms.py脚本拷贝到远程服务器 remote_fab_script = os.path.join(remote_fab_folder,os.path.split(local_file)[1]) put(local_file,remote_fab_folder) run('python %s %s' %(remote_fab_script,env.host)) #将ExportKVM_vms.py脚本的执行结果拷贝到本地服务器 vm_result_csvfile = '%squeryresult-%s.csv' %(remote_fab_folder,env.host) get(vm_result_csvfile,local_result_folder) def dotask(): execute(t_exportvminfor)
在外部提供远程服务器和账号密码(Windows下不支持parallel):
fab -f D:py est-01.py dotask -H root@192.168.2.2 -p mypasswd