为应对爆盘风险,每个部门都分配了多套存储与相应的配额。但当部门存储使用率高时,需要频繁调整配额,这造成了高度重复的工作、时间浪费以及误操作风险。为满足这一需求,我们提出了一种新的配置方法。各业务线根据指定格式编写调整需求,提交给运维,随后运维执行即可。这一流程极大地节省了运维人力,同时也显著降低了误操作风险。通过这种方式,我们在满足需求的同时提升了效率,创造了更加可靠的环境。
[toc]
isilon-荣之联存储配额调整自动化
说明
因避免爆盘的风险,每个部门对应有多套存储与相应配额,然、当各部门对应存储使用率高的时候需要去调整配额 ,每次带来的重复性较高,耗用时间较大,误操作概率较大。出于这样的需求,把配置提出来,各业务线调整需求,按指定格式,写好后提交给运维。执行行即可。这样大大节省运维人力的投入,也降底了误操作的概率。
python 实现逻辑
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.colors import red,green,yellow
from fabric.api import env ,local, run, task , hosts ,execute , parallel,roles,serial,get,put,cd,prefix,warn_only
import time
import re
################ 注意安全开关 ##################
switch = 'on'
SERVER_CACHE = '/tmp/reXMin/'
##############区域1isi存储登录点#################
TESTSTORAGE1_HOST = 'xxx.xxx.xx.221'
TESTSTORAGE2_HOST = 'xxx.xxx.xx.231'
TESTSTORAGE3_HOST = 'xxx.xxx.xx.234'
TESTSTORAGE4_HOST = 'xxx.xxx.xx.159'
BJPROJECT_HOST = 'xxx.xxx.xx.199'
PROJECT_HOST = 'xxx.xxx.xx.178'
TESTWORK_HOST = 'xxx.xxx.xx.222'
PUBLIC_HOST = 'xxx.xxx.xx.150'
DIR_HOME_HOST = 'xxx.xxx.xx.150'
##############区域1容之联存储登录点###############
TESTSTORAGE6_TESTSTORAGEHEAD_HOST = 'xxx.xxx.xx.7'
TESTSTORAGE5_LOGIN07_HOST = 'xxx.xxx.xx.7'
PDD_LOGIN07_HOST = 'xxx.xxx.xx.7'
XXM_LOGIN07_HOST = 'xxx.xxx.xx.7'
XXXJ1_LOGIN07_HOST = 'xxx.xxx.xx.7'
TCX1X_LOGIN07_HOST = 'xxx.xxx.xx.7'
LOADTAN1_LOGIN07_HOST = 'xxx.xxx.xx.7'
LOADTAN2_LOGIN07_HOST = 'xxx.xxx.xx.7'
TESTSTORAGENAS01_LOGIN07_HOST = 'xxx.xxx.xx.7'
##############区域2isi存储登录点#################
XM2_HOST = 'xxx.xxx.xx.236'
#############区域2容之联存储登录点################
XM1_XMHEAD_HOST = 'xxx.xxx.xx.1'
XM3_XMHEAD_HOST = 'xxx.xxx.xx.1'
STORAGE_USER = 'user1'
STORAGE_PASSWD = 'TestO.09c1'
env.roledefs = {
'TESTSTORAGE1': [TESTSTORAGE1_HOST],
'TESTSTORAGE2': [TESTSTORAGE2_HOST],
'TESTSTORAGE3': [TESTSTORAGE3_HOST],
'TESTSTORAGE4': [TESTSTORAGE4_HOST],
'bjPROJECT': [BJPROJECT_HOST],
'PROJECT': [PROJECT_HOST],
'TESTWORK': [TESTWORK_HOST],
'public': [PUBLIC_HOST],
'DIR_HOME': [DIR_HOME_HOST],
'TESTSTORAGE6': [TESTSTORAGE6_TESTSTORAGEHEAD_HOST],
'TESTSTORAGE5': [TESTSTORAGE5_LOGIN07_HOST],
'TESTCDD': [TESTCDD_LOGIN07_HOST],
'RMX1': [RMX1_LOGIN07_HOST],
'XXJ1': [XXJ1_LOGIN07_HOST],
'TCX1': [TCX1_LOGIN07_HOST],
'TAN1': [TAN1_LOGIN07_HOST],
'TAN2': [TAN2_LOGIN07_HOST],
'TESTSTORAGEnas01': [TESTSTORAGENAS01_LOGIN07_HOST],
'XM2': [XM2_HOST],
'XM1': [XM1_XMHEAD_HOST],
'XM3': [XM3_XMHEAD_HOST],
}
LOGING_USER = 'Test'
ISILON_PASSWD = 'test'
env.passwords = {
LOGING_USER + '@' + TESTSTORAGE1_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + TESTSTORAGE2_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + TESTSTORAGE3_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + TESTSTORAGE4_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + TESTWORK_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + PUBLIC_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + DIR_HOME_HOST +':22': ISILON_PASSWD,
LOGING_USER + '@' + BJPROJECT_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + PROJECT_HOST + ':22': ISILON_PASSWD,
LOGING_USER + '@' + XM2_HOST + ':22': ISILON_PASSWD,
}
env.key_filename = '~/.ssh/id_rsa'
env.user = LOGING_USER
rongzhiian_command_get = 'quota list'
isi_command_get = "isi quota quotas list | grep -w '{}' | awk \'{{print $5}}\'"
isi_command_set = 'isi quota quotas modify {} directory --hard-threshold {}'
rongzhiian_command_set = 'quota set'
create_bash = 'create_bash_expect.sh'
storage_name = {
'TESTSTORAGE1': 'TESTSTORAGEPROJECT1',
'TESTSTORAGE2': 'TESTSTORAGEPROJECT2',
'TESTSTORAGE3': 'TESTSTORAGEPROJECT3',
'TESTSTORAGE4': 'TESTSTORAGEPROJECT4',
'BJPROJECT': 'BJPROJECT',
'PROJECT': 'PROJECT',
'TESTWORK': 'TESTWORK',
'PUBLIC': 'PUBLIC',
'DIR_HOME': 'dirhome',
'TESTSTORAGE6': 'TESTSTORAGEPROJECT6',
'TESTSTORAGE5': 'TESTSTORAGEPROJECT5',
'TESTCDD': 'TESTCDD',
'RMX1': 'RMX1',
'XXJ1': 'XXJ1',
'TCX1': 'TCX1',
'TAN1': 'TAN1',
'TAN2': 'TAN2',
'TESTSTORAGENAS01': 'TESTSTORAGENAS01',
'XM2': 'XMPROJECT2',
'XM3': 'XMPROJECT3',
'XM1': 'XMPROJECT1',
}
def switch_on(run_set):
if switch == 'off':
print(run_set)
if switch == 'on':
run(run_set)
def prompt_file_list():
prompt_file = open('change_storage.txt')
prompt_file_read = prompt_file.readlines()
for print_prompt in prompt_file_read:
print(red(print_prompt.replace('\n',"")))
check_file_list = input(green("请核对您的存储修改列表信息,如果有误请输入'q|quit|Q|QUIT'退出: "))
if check_file_list == 'q' or check_file_list == 'quit' or check_file_list == 'Q' or check_file_list == 'QUIT':
exit('100')
draw_list = []
for draw_cut in range(len(prompt_file_read)):
if '---' in prompt_file_read[draw_cut] and '增加量' in prompt_file_read[draw_cut]:
draw_list = prompt_file_read[1:draw_cut]
draw_re_list = []
for draw_list_tuple in draw_list:
re_draw_list_tuple = re.sub(' +',' ',draw_list_tuple)
draw_re_list.append(re_draw_list_tuple.strip().replace(" ",",").replace("\t",","))
for draw_cut in range(len(prompt_file_read)):
if '---' in prompt_file_read[draw_cut] and '增加量' in prompt_file_read[draw_cut]:
add_list = prompt_file_read[draw_cut+1:]
add_re_list = []
for add_list_tuple in add_list:
re_add_list_tuple = re.sub(' +',' ',add_list_tuple)
add_re_list.append(re_add_list_tuple.strip().replace(" ",",").replace("\t",","))
return [draw_re_list,add_re_list]
def mkdir_server_cache():
mkdir_command = '[ -d {} ] || mkdir {}'.format(SERVER_CACHE,SERVER_CACHE)
run(mkdir_command)
def repliace_bash_file(command,ip_list):
replace_bash_file = 'bash_expect.sh'
replace_bash_file_create = create_bash
replace_bash_read = open(replace_bash_file, "r")
replace_bash_write = open(replace_bash_file_create, "w")
with replace_bash_read as f:
read = f.read()
read = read.replace('$COMMAND$',command)
read = read.replace('$IP_LIST$',ip_list)
with replace_bash_write as f:
f.write(read)
def repliace_auth_bash_file(command,ip_list):
replace_bash_file = 'auth_bash_expect.sh'
replace_bash_file_create = create_bash
replace_bash_read = open(replace_bash_file, "r")
replace_bash_write = open(replace_bash_file_create, "w")
with replace_bash_read as f:
read = f.read()
read = read.replace('$COMMAND$',command)
read = read.replace('$IP_LIST$',ip_list)
read = read.replace("$USER$",STORAGE_USER)
read = read.replace("$PASSWD$",STORAGE_PASSWD)
with replace_bash_write as f:
f.write(read)
def print_change_message(source_quota,source_size,change_size,):
print(source_quota,source_size,change_size)
print(green("您的配额路径是:") + red(str(source_quota)) + green(" ,原大小是:") + red(str(str(source_size)+"TB")) \
+ green(" ,将调整为:") + red(str(change_size)+"TB"))
time.sleep(2)
#
def print_change_message(source_quota,source_size,change_size,):
print(source_quota,source_size,change_size)
print(green("您的配额路径是:") + red(str(source_quota)) + green(" ,原大小是:") + red(str(str(source_size)+"TB")) \
+ green(" ,将调整为:") + red(str(change_size)+"TB"))
time.sleep(2)
#
# def print_change_message(source_quota,source_size,change_size,):
# print(green("您的配额路径是:") + red(source_quota) + green(" ,原大小是:") + red(str(source_size+"TB")) \
# + green(" ,将调整为:") + red(str(change_size)+"TB"))
# time.sleep(2.3)
################################ 容之联存储(TESTSTORAGE) ###################################
@roles('TESTSTORAGEnas01')
@parallel
def set_TESTSTORAGEnas01(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'xtvol'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.35'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TESTSTORAGENAS01'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['TESTSTORAGENAS01'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('TAN2')
@parallel
def set_TAN2(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol2'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.227'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TAN2'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['TAN2'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('TAN1')
@parallel
def set_TAN1(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'xtvol1'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.227'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TAN1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['TAN1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('TCX1')
@parallel
def set_TCX1(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol2mirror'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.251'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TCX1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['TCX1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('XXJ1')
@parallel
def set_XXJ1(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol1mirror'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.251'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['XXJ1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['XXJ1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('RMX1')
@parallel
def set_RMX1(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol2'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.251'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['RMX1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['RMX1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('TESTCDD')
@parallel
def set_TESTCDD(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol1'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/xtcli -l 10.1.100.251'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TAN1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['TAN1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('TESTSTORAGE5')
@parallel
def set_TESTSTORAGE5(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol1'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/alamocli -l 10.1.100.192 -c'
repliace_auth_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TAN1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $4}}\'".format(SERVER_CACHE,storage_name['TAN1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_auth_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('TESTSTORAGE6')
@parallel
def set_TESTSTORAGE6(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol1'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/PUBLIC/software/public/System/Python-2.7.6/bin/alamocli -l 10.1.190.1 -c'
repliace_auth_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['TESTSTORAGE6'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $4}}\'".format(SERVER_CACHE,storage_name['TESTSTORAGE6'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_auth_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
################################ 容之联存储(XM) ###################################
@roles('XM1')
@parallel
def set_XM1(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'vol1'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/client_NL/Python2.7/bin/xtcli -l 10.2.100.1'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['XM1'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['XM1'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
@roles('XM3')
@parallel
def set_XM3(size,dir,item,source_quota):
mkdir_server_cache()
vol = 'xtvol'
command = rongzhiian_command_get + ' ' + vol
ip_list = '/client_NL/Python2.7/bin/xtcli -l 10.2.100.11'
repliace_bash_file(command,ip_list)
put(create_bash,SERVER_CACHE)
run_size='expect {}{} > {}{}'.format(SERVER_CACHE,create_bash,SERVER_CACHE,storage_name['XM3'])
get_size="cat {}{} | grep -w '{}' | awk \'{{print $2}}\'".format(SERVER_CACHE,storage_name['XM3'],dir)
run(run_size)
now_size=run(get_size).replace('TB',"").replace("T","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "TB"
command = "{} {} {} {}".format(rongzhiian_command_set,vol,'/'+dir,last_set_size)
repliace_bash_file(command,ip_list)
put(create_bash, SERVER_CACHE)
run_set = 'expect {}{}'.format(SERVER_CACHE,create_bash)
local('cat ' + create_bash)
switch_on(run_set)
################################ ISI存储(TESTSTORAGE) ###################################
# @roles('DIR_HOME')
# @parallel
# def set_home(size,dir,item,source_quota):
# mkdir_server_cache()
# get_size = isi_command_get.format(dir)
# now_size=run(get_size).replace('TB',"").replace("T","")
# print(now_size)
# if item == 'add':
# set_size = float(now_size) + float(size)
# if item == 'reduction':
# set_size = float(now_size) - float(size)
# print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
# last_set_size = str(set_size) + "TB"
# run_set = isi_command_set.format(dir,last_set_size)
# print(run_set)
# @roles('public')
# @parallel
# def set_public(size,dir,item,source_quota):
# mkdir_server_cache()
# get_size = isi_command_get.format(dir)
# now_size=run(get_size).replace('TB',"").replace("T","")
# print(now_size)
# if item == 'add':
# set_size = float(now_size) + float(size)
# if item == 'reduction':
# set_size = float(now_size) - float(size)
# print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
# last_set_size = str(set_size) + "TB"
# run_set = isi_command_set.format(dir,last_set_size)
# print(run_set)
@roles('PROJECT')
@parallel
def set_PROJECT(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@roles('PROJECT')
@parallel
def set_PROJECT(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@roles('bjPROJECT')
@parallel
def set_bjPROJECT(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@roles('TESTSTORAGE4')
@parallel
def set_TESTSTORAGE4(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@roles('TESTSTORAGE3')
@parallel
def set_TESTSTORAGE3(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@roles('TESTSTORAGE2')
@parallel
def set_TESTSTORAGE2(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@roles('TESTSTORAGE1')
@parallel
def set_TESTSTORAGE1(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
print(get_size)
# if 'GB' or 'G' in get_size:
# gb_now_size = run(get_size).replace('GB',"").replace("G","").replace("\r\n-\r\n-\r\n-\r\n-","").replace("-","").replace("\n","").replace(" ","")
# now_size = float(gb_now_size)/1024
# else:
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
# now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
# if item == 'add':
# set_size = float(now_size) + float(size)
# print(str(set_size))
# if item == 'reduction':
# set_size = float(now_size) - float(size)
# print_change_message(source_quota=source_quota,source_size=now_size,change_size=str(set_size))
print(set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
################################ ISI存储(TESTSTORAGE) ###################################
@roles('XM2')
@parallel
def set_XM2(size,dir,item,source_quota):
mkdir_server_cache()
get_size = isi_command_get.format(dir)
now_size=run(get_size).replace('TB',"").replace("T","").replace("\r\n-\r\n-\r\n-\r\n-","")
if item == 'add':
set_size = float(now_size) + float(size)
if item == 'reduction':
set_size = float(now_size) - float(size)
print_change_message(source_quota=source_quota,source_size=now_size,change_size=set_size)
last_set_size = str(set_size) + "T"
run_set = isi_command_set.format(dir,last_set_size)
switch_on(run_set)
@task(name='set_storage')
def set_storage():
prompt_file =prompt_file_list()
####################### 要划出的存储循环 #########################
for storage_draw in prompt_file[0]:
item = 'reduction'
storage_draw_list = storage_draw.split(',')
if storage_draw_list[1][-1] == '/':
storage_draw_list[1] = storage_draw_list[1][:-1]
storage_dir_list = storage_draw_list[1].split('/')
if 'ifs' in storage_draw_list[1]:
dir = storage_draw_list[1]
else:
dir = str(storage_dir_list[2:]).replace("[","").replace("]","").replace(" ","").replace("'","").replace(",","/")
size = storage_draw_list[2]
print(storage_dir_list[1])
############# 容之联存储 ################
if 'ifs' not in storage_draw_list[1]:
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTSTORAGENAS01']:
execute(set_TESTSTORAGEnas01,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TAN2']:
execute(set_TAN2,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TAN1']:
execute(set_TAN1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TCX1']:
execute(set_TCX1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['XXJ1']:
execute(set_XXJ1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['RMX1']:
execute(set_RMX1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTCDD']:
execute(set_TESTCDD,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTSTORAGE5']:
execute(set_TESTSTORAGE5,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTSTORAGE6']:
execute(set_TESTSTORAGE6,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域2' and storage_dir_list[1] == storage_name['XM1']:
execute(set_XM1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域2' and storage_dir_list[1] == storage_name['XM3']:
execute(set_XM3,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if 'ifs' in storage_draw_list[1]:
# if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['DIR_HOME']:
# execute(set_home,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
# if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['PUBLIC']:
# execute(set_public,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['PROJECT']:
execute(set_PROJECT,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['BJPROJECT']:
execute(set_bjPROJECT,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE4']:
execute(set_TESTSTORAGE4,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE3']:
execute(set_TESTSTORAGE3,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE2']:
execute(set_TESTSTORAGE2,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE1']:
execute(set_TESTSTORAGE1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域2' and storage_dir_list[2] == storage_name['XM2']:
execute(set_XM2,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
###################### 要增加的存储循环 #########################
for storage_draw in prompt_file[1]:
item = 'add'
storage_draw_list = storage_draw.split(',')
if storage_draw_list[1][-1] == '/':
storage_draw_list[1] = storage_draw_list[1][:-1]
storage_dir_list = storage_draw_list[1].split('/')
if 'ifs' in storage_draw_list[1]:
dir = storage_draw_list[1]
else:
dir = storage_dir_list[-1]
size = storage_draw_list[2]
############## 容之联存储 ################
if 'ifs' not in storage_draw_list[1]:
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTSTORAGENAS01']:
execute(set_TESTSTORAGEnas01,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TAN2']:
execute(set_TAN2,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TCX1']:
execute(set_TCX1, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TAN1']:
execute(set_TAN1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['XXJ1']:
execute(set_XXJ1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['RMX1']:
execute(set_RMX1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTCDD']:
execute(set_TESTCDD,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTSTORAGE5']:
execute(set_TESTSTORAGE5,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[1] == storage_name['TESTSTORAGE6']:
execute(set_TESTSTORAGE6,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域2' and storage_dir_list[1] == storage_name['XM1']:
execute(set_XM1,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域2' and storage_dir_list[1] == storage_name['XM3']:
execute(set_XM3,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if 'ifs' in storage_draw_list[1]:
# if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['DIR_HOME']:
# execute(set_home,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
# if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['PUBLIC']:
# execute(set_public,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['PROJECT']:
execute(set_PROJECT,size=size,dir=dir,item=item,source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['BJPROJECT']:
execute(set_bjPROJECT, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE4']:
execute(set_TESTSTORAGE4, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE3']:
execute(set_TESTSTORAGE3, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE2']:
execute(set_TESTSTORAGE2, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域1' and storage_dir_list[2] == storage_name['TESTSTORAGE1']:
execute(set_TESTSTORAGE1, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
if storage_draw_list[0] == '区域2' and storage_dir_list[2] == storage_name['XM2']:
execute(set_XM2, size=size, dir=dir, item=item, source_quota=storage_draw_list[1])
expect 调用的触手脚本
#!/usr/bin/expect
spawn $IP_LIST$
expect "(xtcli)"
send "$COMMAND$\r"
expect "(xtcli)"
send "quit\r"
interact
#!/usr/bin/expect
spawn $IP_LIST$
expect "User:"
send "$USER$\r"
expect "Password:"
send "$PASSWD$\r"
expect "(alamocli)"
send "$COMMAND$\r"
expect "(alamocli)"
send "quit\r"
interact
提出的配置
-----------划出量-----------
区域1 /TESTSTORAGE3/PROJECT1 10
区域1 /ifs/TESTSTORAGE2/PROJECT2 10
区域2 /ifs/TESTSTORAGE8/PROJECT10 20
-----------增加量-----------
区域1 /TESTSTORAGE3/PROJECT5 10
区域1 /ifs/TESTSTORAGE2/PROJECT7 10
区域2 /ifs/TESTSTORAGE8/PROJECT4 20
执行
➤ fab -f change_storage.py -l
➤ fab -f change_storage.py set_storage
提醒要做的存储变更
格言
楚汉成皋之战、新汉昆阳之战、袁曹官渡之战、吴魏赤壁之战、吴蜀彝陵之战、秦晋淝水之战等有名的大战,都是双方强弱不同,弱者先让一步,后发制人,因而有战胜的。