FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


preparation:fhhome:test.py.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
preparation:fhhome:test.py.html [2017/11/26 23:13]
kurihara
preparation:fhhome:test.py.html [2019/02/13 00:16]
kurihara
Line 1: Line 1:
-====== test.py ======+[[:index.html#Preparation|Top#Preparation]] 
 +====== $FHHOME/$FHLINUX/fabfile/test.py ======
  
 +\\
 +{{INLINETOC}}
 +\\
  
  
 +===== Operation =====
 +<sxh bash toolbar:false gutter:false>
 +$ echo xx.xx.xx.xx | fab -- hostname
 +$ echo xx.xx.xx.xx | fab -- sudo cat /etc/shadow
  
-===== test.py =====+$ fab local_hostname 
 + 
 +$ fab -l |grep test.    # check options 
 + 
 +$ echo xx.xx.xx.xx | fab  test.hostname 
 +$ fhghost.sh "*" hosts/test | fab  test.hostname 
 +</sxh> 
 + 
 +\\ 
 +===== fabfile/test.py =====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-import sys+import sys, os
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
 +from datetime import datetime
  
 +FHLINUX=os.environ["FHLINUX"]
 +
 +# test.local_hostname
 @task @task
 def local_hostname(): def local_hostname():
     local('hostname')     local('hostname')
  
 +# test.hostname
 @task @task
 def hostname(): def hostname():
     run('hostname')     run('hostname')
  
 +
 +# test.sudo
 @task @task
-def cat_etc_shadow():+def sudo(): 
 +    """ sudo cat /etc/shadow """
     sudo('cat /etc/shadow')     sudo('cat /etc/shadow')
 +
 +
 +# test.arg1:hostname
 +@task
 +def arg1(cmd):
 +    """ fab test.arg1:hostname """
 +    run('%s' % cmd)
 +
 +
 +# test.arg2:hostname,whoami
 +@task
 +def arg2(cmd1, cmd2):
 +    """ fab test.arg2:hostname,whoami """
 +    run('%s' % cmd1)
 +    run('%s' % cmd2)
 +    run('%s ; %s' % (cmd1, cmd2) )
 +
 +
 +# test.put
 +@task
 +def put():
 +    date = datetime.now().strftime('%Y%m%d_%H%M')
 +    local('hostname > /tmp/test.%s' % date)
 +    put('/tmp/test.%s' % date, '/tmp/test.%s' % date)
 +    run('ls -lh /tmp/test.%s' % date)
 +    run('cat /tmp/test.%s' % date)
 +
 +# test.get
 +@task
 +def get():
 +    date = datetime.now().strftime('%Y%m%d_%H%M')
 +    run('hostname > /tmp/test.%s' % date)
 +    get('/tmp/test.%s' % date, '/tmp/test.%s' % date)
 +    local('ls -lh /tmp/test.%s' % date)
 +    local('cat /tmp/test.%s' % date)
  
 </sxh> </sxh>
 +
 +
  
  
 \\ \\
 +<WRAP box 90%>
 +[[:index.html#Preparation|Top#Preparation]]
 +<catlist ..: -noAddPageButton -noHead >
 +</WRAP>
 \\ \\
-===== Configuration Test ===== +[[:index.html#Preparation|Top#Preparation]]
-<sxh bash toolbar:false gutter:false> +
-$ echo xx.xx.xx.xx | fab -- hostname +
-$ echo xx.xx.xx.xx fab -- sudo cat /etc/shadow +
-</sxh> +


preparation/fhhome/test.py.html.txt · Last modified: 2019/02/13 00:18 by kurihara