qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請?jiān)L問 http://qaseven.github.io/

          Fabric-Python知名批量自動化部署/測試模塊

           #Fabric# Python知名開源自動化部署模塊Fabric,強(qiáng)烈推薦給各位!(運(yùn)維,測試…均可以用它實(shí)現(xiàn)無比具有想象力的任務(wù))他主要用于對設(shè)備/服務(wù)器批量執(zhí)行任務(wù)(同時更換500臺服務(wù)器的密碼、同時更新或者重啟500臺虛擬機(jī))~安裝和使用也極其方便,沒有什么中間代碼,沒有架構(gòu),沒有內(nèi)幕!
            或許對于批量自動化部署而言,這是一個很大很大的福音。
            我們來看一個VPSee提供的案例:
          #!/usr/bin/python
          # -*- coding: utf-8 -*-
          from fabric.api import *
          import string
          from random import choice
          import socket
          import paramiko
          env.user = 'root'
          env.password = 'root'
          env.hosts = [ 'grid00', 'grid01', 'grid02', 'grid03', 'grid04', 'grid05']
          @task
          @parallel
          def 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 '%s\n%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' % host
          timeout = socket.getdefaulttimeout()
          socket.setdefaulttimeout(1)
          up = True
          try:
          paramiko.Transport((host, 22))
          except Exception, e:
          up = False
          print '%s down, %s' % (host, e)
          finally:
          socket.setdefaulttimeout(timeout)
          return up

          posted on 2014-01-10 09:36 順其自然EVO 閱讀(533) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學(xué)習(xí)

          <2014年1月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 邢台市| 新密市| 馆陶县| 台山市| 岑巩县| 关岭| 高唐县| 新田县| 托克逊县| 汝州市| 鄯善县| 西丰县| 清丰县| 微山县| 宝丰县| 太和县| 华容县| 岑溪市| 东辽县| 安丘市| 乌拉特中旗| 盐亭县| 安岳县| 建始县| 汶上县| 洛阳市| 南平市| 灯塔市| 叶城县| 东乡县| 清水县| 鲁山县| 溆浦县| 哈巴河县| 定安县| 班玛县| 凤台县| 裕民县| 会宁县| 平阳县| 察雅县|