-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclean_xiv.py
More file actions
executable file
·83 lines (71 loc) · 2.15 KB
/
clean_xiv.py
File metadata and controls
executable file
·83 lines (71 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
XCLI="/xiv/tools/bin-wrap/xcli.py"
import os
import sys
import subprocess as sp
def get_storage_info(kind):
results = sp.Popen([XCLI, kind, '-z'], stdout=sp.PIPE).stdout.read()
return results
def split_output(indata):
results = []
for line in indata.split('\n'):
if not ('are defined' in line):
data = line.split(' ')[0]
if data != '' :
results.append(data)
return results
def del_command(kind, data):
print "Deleting " + kind + " : " + data
command = " " + XCLI + ' ' + kind + '_delete ' + kind + '=' + data + ' -y'
print command
os.system(command)
def delete_volumes():
devs = split_output(get_storage_info('vol_list'))
if not devs:
print "No Volume(s) to delete."
return
for vol in devs:
data = sp.Popen([XCLI, 'vol_mapping_list', 'vol=' + vol, '-z'], stdout=sp.PIPE).stdout.read()
vhosts = split_output(data)
for host in vhosts:
print 'UnMapping ' + vol + ' from ' + host
cm = XCLI + ' unmap_vol host=' + host + ' vol=' + vol
print (cm)
os.system(cm)
del_command('vol', vol)
def delete_pools():
pools = split_output(get_storage_info('pool_list'))
if not pools:
print "No Pool(s) to delete."
return
for pool in pools:
del_command('pool', pool)
def delete_hosts():
hosts = split_output(get_storage_info('host_list'))
if not hosts:
print "No Host(s) to delete."
return
for host in hosts:
del_command('host', host)
def delete_cluster():
clusters = split_output(get_storage_info('cluster_list'))
if not clusters:
print "No Cluster(s) to delete."
return
for cluster in clusters:
del_command('cluster', cluster)
def main (args):
if not args:
args = 'all'
else:
args = args[0]
if args in ['all', 'vols']:
delete_volumes()
if args in ['all', 'pools']:
delete_pools()
if args in ['all', 'hosts']:
delete_hosts()
if args in ['all', 'clusters']:
delete_cluster()
if __name__ == "__main__":
main(sys.argv[1:])