补充参数顺序:必选参数、默认参数、可变参数、关键字参数。
hosts_nodes为一个list中的元素为字典
[{'label': 'edb1.yuchai.com(10.10.182.11)', 'open': True, 'inode': True, 'checkbox': False, 'id': '5714bc22b4b24604a45452fd2cca38b0', 'branch': [{'label': '/dev/dm-7(Linux device-mapper (multipath)[/dev/dm-7,asm_data2],110.00GB)', 'checked': False, 'checkbox': True, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/dm-4(Linux device-mapper (multipath)[/dev/dm-4,asm_data1],100.00GB)', 'checked': False, 'checkbox': True, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/dm-8(Linux device-mapper (multipath)[/dev/dm-8,asm_reco3],28.00GB)', 'checked': False, 'checkbox': True, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/dm-5(Linux device-mapper (multipath)[/dev/dm-5,asm_reco2],26.00GB)', 'checked': False, 'checkbox': True, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/dm-3(Linux device-mapper (multipath)[/dev/dm-3,asm_data3],90.00GB)', 'checked': False, 'checkbox': True, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdx(MSFT Virtual HD[/dev/sdx],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdy(MSFT Virtual HD[/dev/sdy],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdv(MSFT Virtual HD[/dev/sdv],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdw(MSFT Virtual HD[/dev/sdw],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdt(MSFT Virtual HD[/dev/sdt],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdu(MSFT Virtual HD[/dev/sdu],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdr(MSFT Virtual HD[/dev/sdr],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sds(MSFT Virtual HD[/dev/sds],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdp(MSFT Virtual HD[/dev/sdp],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdq(MSFT Virtual HD[/dev/sdq],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdn(MSFT Virtual HD[/dev/sdn],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdo(MSFT Virtual HD[/dev/sdo],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdl(MSFT Virtual HD[/dev/sdl],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdm(MSFT Virtual HD[/dev/sdm],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdj(MSFT Virtual HD[/dev/sdj],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdk(MSFT Virtual HD[/dev/sdk],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdh(MSFT Virtual HD[/dev/sdh],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdi(MSFT Virtual HD[/dev/sdi],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdf(MSFT Virtual HD[/dev/sdf],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdg(MSFT Virtual HD[/dev/sdg],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdd(MSFT Virtual HD[/dev/sdd],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sde(MSFT Virtual HD[/dev/sde],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sdb(MSFT Virtual HD[/dev/sdb],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sdc(MSFT Virtual HD[/dev/sdc],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/dm-6(Linux device-mapper (multipath)[/dev/dm-6,asm_reco1],24.00GB)', 'checked': False, 'checkbox': True, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sda(VMware Virtual disk[/dev/sda],200.00GB)(启动盘)', 'checked': False, 'checkbox': True, 'id': '96500000000000000000000000000000', 'disabled': False}]}, {'label': 'edb2.yuchai.com(10.10.182.12)', 'open': True, 'inode': True, 'checkbox': False, 'id': 'ddc16df57e314d1a8751b660c33f7fd5', 'branch': [{'label': '/dev/dm-7(Linux device-mapper (multipath)[/dev/dm-7,asm_reco3],28.00GB)', 'checked': False, 'checkbox': True, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/dm-4(Linux device-mapper (multipath)[/dev/dm-4,asm_data3],90.00GB)', 'checked': False, 'checkbox': True, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/dm-8(Linux device-mapper (multipath)[/dev/dm-8,asm_reco2],26.00GB)', 'checked': False, 'checkbox': True, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/dm-5(Linux device-mapper (multipath)[/dev/dm-5,asm_data2],110.00GB)', 'checked': False, 'checkbox': True, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/dm-3(Linux device-mapper (multipath)[/dev/dm-3,asm_data1],100.00GB)', 'checked': False, 'checkbox': True, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sdx(MSFT Virtual HD[/dev/sdx],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdy(MSFT Virtual HD[/dev/sdy],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdv(MSFT Virtual HD[/dev/sdv],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdw(MSFT Virtual HD[/dev/sdw],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdt(MSFT Virtual HD[/dev/sdt],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdu(MSFT Virtual HD[/dev/sdu],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdr(MSFT Virtual HD[/dev/sdr],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sds(MSFT Virtual HD[/dev/sds],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdp(MSFT Virtual HD[/dev/sdp],26.00GB)', 'checkbox': False, 'id': '7414c9a235bbb6ce320000005f303030', 'disabled': False}, {'label': '/dev/sdq(MSFT Virtual HD[/dev/sdq],28.00GB)', 'checkbox': False, 'id': '0d20768434bbb6ce310000005f303030', 'disabled': False}, {'label': '/dev/sdn(MSFT Virtual HD[/dev/sdn],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdo(MSFT Virtual HD[/dev/sdo],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdl(MSFT Virtual HD[/dev/sdl],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdm(MSFT Virtual HD[/dev/sdm],24.00GB)', 'checkbox': False, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sdj(MSFT Virtual HD[/dev/sdj],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdk(MSFT Virtual HD[/dev/sdk],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdh(MSFT Virtual HD[/dev/sdh],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdi(MSFT Virtual HD[/dev/sdi],90.00GB)', 'checkbox': False, 'id': 'ea84950318b3d8b2310000005f303030', 'disabled': False}, {'label': '/dev/sdf(MSFT Virtual HD[/dev/sdf],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdg(MSFT Virtual HD[/dev/sdg],110.00GB)', 'checkbox': False, 'id': '93b02a2519b3d8b2320000005f303030', 'disabled': False}, {'label': '/dev/sdd(MSFT Virtual HD[/dev/sdd],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sde(MSFT Virtual HD[/dev/sde],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sdb(MSFT Virtual HD[/dev/sdb],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/sdc(MSFT Virtual HD[/dev/sdc],100.00GB)', 'checkbox': False, 'id': '3d97001e17b3d8b2300000005f303030', 'disabled': False}, {'label': '/dev/dm-6(Linux device-mapper (multipath)[/dev/dm-6,asm_reco1],24.00GB)', 'checked': False, 'checkbox': True, 'id': 'da33e39933bbb6ce300000005f303030', 'disabled': False}, {'label': '/dev/sda(VMware Virtual disk[/dev/sda],200.00GB)(启动盘)', 'checked': False, 'checkbox': True, 'id': '96500000000000000000000000000000', 'disabled': False}]}]
def match_rac_disks(hosts_nodes):
result = list()
select_checked = list()
for j in hosts_nodes:
for k in j['branch']:
if 'checked' in k:
k['map_disk_lab'] = j['label']
k['host_ident'] = j['id']
select_checked.append(k)
for i in range(len(select_checked)):
if len(select_checked) != 0:
tmp = list()
tmp2 = list()
tmp.append(select_checked[0])
tmp2.append(0)
for j in range(1, len(select_checked)):
if select_checked[0]['id'] == select_checked[j]['id']:
tmp.append(select_checked[j])
tmp2.append(j)
result.append(tmp)
for index, s in enumerate(tmp2):
del select_checked[s - index]
else:
break
return result
x.py
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--kvmparams",default='params.json', help="path for test source")
args = parser.parse_args()
with open(args.kvmparams, 'r') as f:
key_info = json.loads(f.read())
Main(key_info).start()
shell 下调用
python x.py --kvmparams params.json