FastHandle is fast operation tools for infrastructure configurations and tests.
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
preparation:fhhome:test.py.html [2017/11/27 21:41] kurihara |
preparation:fhhome:test.py.html [2019/02/12 23:29] kurihara |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ~~NOTOC~~ | ||
[[: | [[: | ||
+ | ====== $FHHOME/ | ||
- | ====== fabfile/ | + | |
+ | |||
+ | |||
+ | ===== fabfile/ | ||
+ | |||
+ | <sxh bash toolbar: | ||
+ | import sys, os, glob, select, importlib, re | ||
+ | from fabric.api import * | ||
+ | from fabric.contrib import files | ||
+ | from datetime import datetime | ||
+ | |||
+ | # | ||
+ | # SSH User | ||
+ | # | ||
+ | hostname = os.uname()[1] | ||
+ | |||
+ | if hostname == " | ||
+ | env.user = ' | ||
+ | env.password = ' | ||
+ | elif hostname == " | ||
+ | env.user = ' | ||
+ | env.password = ' | ||
+ | elif hostname == " | ||
+ | env.user = ' | ||
+ | env.key_filename = ' | ||
+ | # | ||
+ | |||
+ | # | ||
+ | # Variable | ||
+ | # | ||
+ | FHHOME=os.environ[" | ||
+ | |||
+ | env.warn_only = True | ||
+ | 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, | ||
+ | lines = sys.stdin.read().splitlines() | ||
+ | env.hosts = filter(bool, | ||
+ | |||
+ | |||
+ | #FastHandle Operation History to log file | ||
+ | TIME = datetime.now().strftime(' | ||
+ | yymm = datetime.now().strftime(' | ||
+ | |||
+ | f=open(" | ||
+ | |||
+ | if env.hosts == []: | ||
+ | f.write(" | ||
+ | f.write(' | ||
+ | f.write(" | ||
+ | |||
+ | for p in env.hosts: | ||
+ | f.write(" | ||
+ | f.write(' | ||
+ | f.write(" | ||
+ | f.close() | ||
+ | |||
+ | |||
+ | # auto import *.py | ||
+ | # Ref. https:// | ||
+ | pathThisFile = os.path.dirname(os.path.abspath(__file__)) | ||
+ | |||
+ | def loadModule(): | ||
+ | |||
+ | myself = sys.modules[__name__] | ||
+ | |||
+ | #print __name__ | ||
+ | |||
+ | mod_paths = glob.glob(os.path.join(pathThisFile, | ||
+ | for py_file in mod_paths: | ||
+ | mod_name = os.path.splitext(os.path.basename(py_file))[0] | ||
+ | if re.search(" | ||
+ | mod = importlib.import_module(__name__+ " | ||
+ | #for m in mod.__dict__.keys(): | ||
+ | #if not m in [' | ||
+ | # | ||
+ | loadModule() | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | <WRAP box 90%> | ||
+ | [[: | ||
+ | <catlist ..: -noAddPageButton -noHead> | ||
+ | </ | ||
+ | \\ | ||
+ | [[: | ||
+ | [[: | ||
+ | |||
+ | ====== $FHLINUX/fabfile/ | ||
Line 10: | Line 110: | ||
$ echo xx.xx.xx.xx | fab -- sudo cat /etc/shadow | $ echo xx.xx.xx.xx | fab -- sudo cat /etc/shadow | ||
- | $ echo xx.xx.xx.xx | fab local_hostname | + | $ fab local_hostname |
- | $ echo xx.xx.xx.xx | fab auth.test hostname | + | |
+ | $ fab -l |grep test. # check options | ||
+ | |||
+ | $ echo xx.xx.xx.xx | fab test.hostname | ||
+ | $ fhghost.sh " | ||
</ | </ | ||
Line 18: | Line 122: | ||
<sxh bash toolbar: | <sxh bash toolbar: | ||
- | 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 | ||
+ | FHHOME=os.environ[" | ||
+ | |||
+ | # test.local_hostname | ||
@task | @task | ||
def local_hostname(): | def local_hostname(): | ||
local(' | local(' | ||
+ | # test.hostname | ||
@task | @task | ||
def hostname(): | def hostname(): | ||
run(' | run(' | ||
+ | |||
+ | # test.sudo | ||
@task | @task | ||
- | def cat_etc_shadow(): | + | def sudo(): |
+ | """ | ||
sudo(' | sudo(' | ||
+ | |||
+ | |||
+ | # test.arg1: | ||
+ | @task | ||
+ | def arg1(cmd): | ||
+ | """ | ||
+ | run(' | ||
+ | |||
+ | |||
+ | # test.arg2: | ||
+ | @task | ||
+ | def arg2(cmd1, cmd2): | ||
+ | """ | ||
+ | run(' | ||
+ | run(' | ||
+ | run(' | ||
+ | |||
+ | |||
+ | # test.put | ||
+ | @task | ||
+ | def put(): | ||
+ | date = datetime.now().strftime(' | ||
+ | local(' | ||
+ | put('/ | ||
+ | run(' | ||
+ | run(' | ||
+ | |||
+ | # test.get | ||
+ | @task | ||
+ | def get(): | ||
+ | date = datetime.now().strftime(' | ||
+ | run(' | ||
+ | get('/ | ||
+ | local(' | ||
+ | local(' | ||
</ | </ |
My Sites
SNS
Copyright (c) 2024 FastHandle - IT Operations Examples All Rights Reserved.