fabric2 使用
? fabric2 ? ? python ?    993    0    0
swimming   ? fabric2 ? ? python ?

fabric2 使用


pythonLab-v3/fabricSample/fab2sample.py


from fabric2 import Config # ssh配置文件
from fabric2 import Connection # 连接池
from fabric2 import ThreadingGroup # 多线程并行
from fabric2 import SerialGroup # 串行
from invoke import task # @task annotation
from invoke import Responder 

#con = Connection('student@192.168.19.128', connect_kwargs = { 'key_filename': 'id_rsa'})
# SSH の設定ファイル指定
#
Config.ssh_config_path = 'ssh_config'

hosts=('192.168.19.128','192.168.19.129')

# SingleThread Run
print('--- SingleThread Run ---')
for host in hosts:
  con = Connection(host)
  print(con.host)
  con.run('hostname') 

# SingleThread Group Run
print('--- SingleThread Group Run ---')
result = SerialGroup('192.168.19.128','192.168.19.129').run('hostname')

# MultiThread Group Run
print('--- MultiThread Group Run ---')
result = ThreadingGroup('192.168.19.128','192.168.19.129').run('hostname')


觉得不错,点个赞?
Sign in to leave a comment.
No Leanote account ? Sign up now.
0 条评论
文章目录