FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


preparation:fhhome:init.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
preparation:fhhome:init.py.html [2017/11/26 23:46]
kurihara ↷ Page moved from preparation:init.py.html to preparation:scripts:init.py.html
preparation:fhhome:init.py.html [2019/02/13 00:18] (current)
kurihara
Line 1: Line 1:
 [[:index.html#Preparation|Top#Preparation]] [[:index.html#Preparation|Top#Preparation]]
-====== fabfile/__init__.py ======+====== $FHHOME/linux/fabfile/__init__.py ======
  
  
Line 8: Line 8:
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-import sys+import sys, os, glob, select, importlib, re
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
-  +from datetime import datetime 
 + 
 +#====================================================== 
 +# SSH User 
 +#====================================================== 
 +hostname = os.uname()[1] 
 + 
 +if hostname == "fasthandle-1": 
 +    env.user = 'fasthandle' 
 +    env.password = 'fastpass' 
 +elif hostname == "stg-fasthandle-1": 
 +    env.user = 'fasthandle' 
 +    env.password = 'fastpass' 
 +elif hostname == "dev-fasthandle-1": 
 +    env.user = 'fasthandle' 
 +    env.key_filename = '$FHHOME/key/id_rsa.fasthandle.dev-fasthandle-1' 
 +    #env.password = 'passphrase-for-key' 
 + 
 +#====================================================== 
 +# Variable 
 +#====================================================== 
 +FHHOME=os.environ["FHHOME"
 env.warn_only = True env.warn_only = True
 env.port = 22 env.port = 22
 +env.eagerly_disconnect = True
 +
 +#don't create *.pyc without __init__.pyc
 +sys.dont_write_bytecode = True
 +
 +
 +
 +#======================================================
 +#======================================================
 +# standard in for example echo x.x.x.x
 +if select.select([sys.stdin,],[],[],0.0)[0]:
 +    lines = sys.stdin.read().splitlines()
 +    env.hosts = filter(bool, lines)
 +
 +
 +#FastHandle Operation History to log file
 +TIME = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 +yymm = datetime.now().strftime('%Y%m')
 +
 +f=open("%s/log/fab.%s.log" % (FHHOME,yymm) ,"a")
 +
 +if env.hosts == []:
 +  f.write("%s stdin-null " % TIME)
 +  f.write(' '.join(str(p) for p in sys.argv))
 +  f.write("\n")
 +
 +for p in env.hosts:
 +  f.write("%s %s " % (TIME,p))
 +  f.write(' '.join(str(p) for p in sys.argv))
 +  f.write("\n")
 +f.close()
 +
 +
 +# auto import *.py
 +# Ref. https://gist.github.com/fereria/3331554f4c480679716b#file-__init__-py
 +pathThisFile = os.path.dirname(os.path.abspath(__file__))
 +
 +def loadModule():
 +
 +    myself = sys.modules[__name__]
  
-lines = sys.stdin.read().splitlines() +    #print __name__
-env.hosts = filter(bool, lines) +
-print "target hosts: %r" % env.hosts+
  
-import auth +    mod_paths = glob.glob(os.path.join(pathThisFile, '*.py')) 
-import test +    for py_file in mod_paths: 
-import user +        mod_name = os.path.splitext(os.path.basename(py_file))[0] 
-import centos7 +        if re.search(".*__init__.*",mod_name) is None: 
-import checklinux+            mod = importlib.import_module(__name__+ "." + mod_name) 
 +            #for m in mod.__dict__.keys(): 
 +                #if not m in ['__builtins__', '__doc__', '__file__', '__name__', '__package__']: 
 +                    #myself.__dict__[m] = mod.__dict__[m] 
 +loadModule()
 </sxh> </sxh>
  
Line 32: Line 96:
 <WRAP box 90%> <WRAP box 90%>
 [[:index.html#Preparation|Top#Preparation]] [[:index.html#Preparation|Top#Preparation]]
-<catlist -noAddPageButton -noHead -sortAscending>+<catlist ..: -noAddPageButton -noHead>
 </WRAP> </WRAP>
 \\ \\
 [[:index.html#Preparation|Top#Preparation]] [[:index.html#Preparation|Top#Preparation]]


preparation/fhhome/init.py.html.1511707589.txt.gz · Last modified: 2017/11/26 23:46 by kurihara