运维我理想状态 更新实践一_第1张图片

运维我理想状态 更新实践一_第2张图片


实践:

fabric-code:

from fabric.api import *
env.roledefs ={
    "git-server" : ["[email protected]"],
    "ktmgame" : ["[email protected]"]
}
env.password = '*******'
@roles("ktmgame")
def GoMaster(poduce_branch_name,git_dir="/opt/git"):
    with cd(git_dir):
        GMcommand = "git checkout "+poduce_branch_name
        run(GMcommand)
@roles("ktmgame")
def UpdateVersion(develop_branch_name,git_dir="/opt/git",remote="origin"):
    with cd(git_dir):
        UVcommand = "git fetch origin;git checkout -b "+develop_branch_name+" "+remote+"/"+develop_branch_name
        run(UVcommand)

操作-回到生产版本:

(fab)[root@Zwhset-Os Autonoc]# fab GoMaster:poduce_branch_name="master",git_dir="/ktmgame/ktgame"
[[email protected]] Executing task 'GoMaster'
[[email protected]] run: git checkout master
[[email protected]] out: Switched to branch 'master'
[[email protected]] out:
Done.


操作-更新到开发版本:

(fab)[root@Zwhset-Os Autonoc]# fab UpdateVersion:develop_branch_name="master20130619"
[[email protected]] Executing task 'UpdateVersion'
[[email protected]] run: git fetch origin;git checkout -b master20130619 origin/master20130619
[[email protected]] out: Address 192.168.100.38 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
[[email protected]] out:
[[email protected]] out: [email protected]'s password:
[[email protected]] out: Permission denied, please try again.
[[email protected]] out:
[[email protected]] out: [email protected]'s password:
[[email protected]] out: From ssh://192.168.100.38/opt/git/ktmgame
[[email protected]] out:    53e6db6..216dc29  master     -> origin/master
[[email protected]] out:  * [new branch]      master20130619 -> origin/master20130619
[[email protected]] out: Branch master20130619 set up to track remote branch master20130619 from origin.
[[email protected]] out: Switched to a new branch 'master20130619'
[[email protected]] out:
Done.

同样,我管理的一台web也按照我的操作而进行变更。so,我的工作就可以在一个shell里简单的开展啦。