首页 测试 体会 查看内容

Fabric-Python知名批量自动化部署/测试模块

2014-6-25 14:31| 发布者: tianzc| 查看: 392| 评论: 0

摘要:   #Fabric# Python知名开源自动化部署模块Fabric,强烈推荐给各位!(运维,测试…均可以用它实现无比具有想象力的任务)他主要用于对设备/服务器批量执行任务(同时更换500台服务器的密码、同时更新或者重启500台 ...
#!/usr/bin/python# -*- coding: utf-8 -*-from fabric.api import *import stringfrom random import choiceimport socketimport paramikoenv.user = 'root'env.password = 'root'env.hosts = [ 'grid00', 'grid01', 'grid02', 'grid03', 'grid04', 'grid05']@task@paralleldef passwd(user, passwd=False):with settings(hide('running', 'stdout', 'stderr'), warn_only=True):if isup(env.host):if not passwd:passwd = genpass()sudo("echo -e '%sn%s' | passwd %s" % (passwd, passwd, user))def genpass(length=10):return ''.join(choice(string.ascii_letters + string.digits) for _ in range(length))def isup(host):print 'connecting host: %s' % hosttimeout = socket.getdefaulttimeout()socket.setdefaulttimeout(1)up = Truetry:paramiko.Transport((host, 22))except Exception, e:up = Falseprint '%s down, %s' % (host, e)finally:socket.setdefaulttimeout(timeout)return up
  #Fabric# Python知名开源自动化部署模块Fabric,强烈推荐给各位!(运维,测试…均可以用它实现无比具有想象力的任务)他主要用于对设备/服务器批量执行任务(同时更换500台服务器的密码、同时更新或者重启500台虚拟机)~安装和使用也极其方便,没有什么中间代码,没有架构,没有内幕!  或许对于批量自动化部署而言,这是一个很大很大的福音。  我们来看一个VPSee提供的案例:

鲜花

握手

雷人

路过

鸡蛋

扫一扫关注最新动态

毒镜头:老镜头、摄影器材资料库、老镜头样片、摄影
爱评测 aipingce.com  
返回顶部