FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


Sidebar


Top     SiteMap

Manager Server

Target Server

$FHHOME/bin/xxx.sh | xxxx.exp













.

os:linux:ope:index.html



This is an old revision of the document!


Top#OS Management

OS Operation (ope.py)

$FHHOME/fabfile/ope.py


Operation

$ echo xx.xx.xx.xx | fab auth.pro -- hostname
$ echo xx.xx.xx.xx | fab auth.pro -- sudo cat /etc/shadow

$ fab  -l |grep ope.
$ echo xx.xx.xx.xx | fab  auth.pro  ope.check_user01


ope.py

$FHHOME/fabfile/ope.py

import sys
from fabric.api import *
from fabric.contrib import files
from fabric.operations import open_shell

FHHOME=os.environ["FHHOME"]

#------------------------------------------------------------------
# ope.put
#     fab auth.pro ope.put:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm
#------------------------------------------------------------------
@task
def put(local,remote):
    """fab auth.pro ope.scp:/home/fasthandle/rpm/abc.rpm,/tmp/abc.rpm"""
    put("%s", "%s" % (local,remote))


#------------------------------------------------------------------
# ope.ssh
#     fab auth.pro ope.ssh:"sudo vi /etc/hosts"
#------------------------------------------------------------------
@task
def ssh():
    '''fab auth.pro ope.ssh '''
    open_shell("hostname")


#------------------------------------------------------------------
# ope.sshcmd
#     fab auth.pro ope.ssh:"sudo vi /etc/hosts"
#------------------------------------------------------------------
@task
def sshcmd(cmd):
    '''fab auth.pro ope.sshcmd:"sudo vi /etc/hosts" '''
    open_shell("%s" % cmd)


#------------------------------------------------------------------
# ope.sudo_vi
#     fab -H x.x.x.x auth.pro ope.vi:/etc/hosts
#
# WARNING: open_shell didn't use 'echo x.x.x.x |fab ' and 'fhghost.sh'
#
#------------------------------------------------------------------
@task
def sudo_vi(file):
    """fab auth.pro ope.vi:/etc/hosts"""
    open_shell("sudo_vi %s && exit" % (file))



#------------------------------------------------------------------
# ope.cp_p_1dayago(file)
#     fab auth.pro ope.cp_p_1dayago:/etc/hosts
#------------------------------------------------------------------
@task
def cp_p_1dayago(file):
    """fab auth.pro  cp_p_1dayago:/etc/host,/etc/hosts"""
    sudo("cp -p %s %s.`date -d '1day ago' +%Y%m%d`") % (file, file))



#------------------------------------------------------------------
# ope.reboot
#------------------------------------------------------------------
@task 
def reboot():
    sudo("shutdown -r now", warn_only=True)

#------------------------------------------------------------------
# ope.shutdown
#------------------------------------------------------------------
@task 
def shutdown():
    run("shutdown -h now", warn_only=True)







Top#OS Management



os/linux/ope/index.html.1516723334.txt.gz ยท Last modified: 2018/01/24 01:02 by kurihara