Created
January 7, 2016 10:48
-
-
Save taeguk/d50945a27d2ea03492ae to your computer and use it in GitHub Desktop.
릴리즈 랩실 자동화를 위한 툴
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import * | |
import sys | |
env.hosts = [] | |
MAX_TRYING_CNT = 3 | |
#trying_cnt = 1 | |
env.password = 'releaseworld' | |
def total_cleanup_old(): | |
for x in range (110, 125): | |
env.hosts.append("[email protected]."+str(x)) | |
execute(test, hosts=env.hosts) | |
###start_function | |
def remote_command(): | |
rmt_cmd([x for x in range(110,114)]) | |
def print_result(ips, success_ips, except_ips, trying_cnt): | |
if trying_cnt > 1: | |
remain_ips = [] | |
except_ips = list(set(ips)-set(success_ips)) | |
else: | |
remain_ips = list(set(ips)-set(success_ips)-set(except_ips)) | |
print "\n+++++++++++++++ F I N I S H +++++++++++++++" | |
print "\n ----- Command Success IPs -----" | |
print success_ips.sort() | |
print "\n ----- Command Fail IPs -----" | |
print except_ips.sort() | |
print "\n ----- Command not performed IPs -----" | |
print remain_ips.sort() | |
print "\n\n" | |
### important function | |
def rmt_cmd(ips): | |
all_ips = ips | |
trying_cnt = 0 | |
while True: | |
trying_cnt+=1 | |
success_ips = [] | |
except_ips = [] | |
for ip in ips: | |
env.hosts = ["[email protected]."+str(ip)] | |
try: | |
execute(command, hosts=env.hosts) | |
except KeyboardInterrupt: | |
print_result(all_ips, success_ips, except_ips, trying_cnt) | |
sys.exit() | |
except: | |
print "\n*******EXCEPTION*******\n" | |
except_ips.append(ip) | |
else: | |
success_ips.append(ip) | |
if len(except_ips) > 0: | |
if trying_cnt < MAX_TRYING_CNT: | |
print "\n[!] ---- Command Fail IPs ----" | |
print except_ips.sort() | |
print "\n[*] Re-Doing to Fail IPs (#"+str(trying_cnt+1)+")\n" | |
ips = except_ips.sort() | |
else: | |
print "\n[!] reach MAX_TRYING_CNT!!!!!!!!!!!!!!" | |
print_result(all_ips, success_ips, except_ips, trying_cnt) | |
break | |
else: | |
print "\n[*] finish!!\n" | |
print_result(all_ips, success_ips, except_ips, trying_cnt) | |
break | |
def command(): | |
run("mkdir hahaha") | |
#run("echo releaseworld | sudo -S softwareupdate --list") | |
#run("echo releaseworld | sudo -S softwareupdate -i -a") | |
#run("echo releaseworld | sudo -S reboot") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment