-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteOrphanDiffVdisk.py
More file actions
executable file
·73 lines (56 loc) · 2.55 KB
/
deleteOrphanDiffVdisk.py
File metadata and controls
executable file
·73 lines (56 loc) · 2.55 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
#! /usr/bin/env python
import subprocess
import time
#########################################################################
# getvdis: is a function that return a set on string that represent
# all vdi differential disk from VMs in this xenserver pool
#########################################################################
def getvdis():
'''execute the command that list vdi'''
getvdi_command = subprocess.Popen(['xe', 'vdi-list', 'params=name-label'], stdout=subprocess.PIPE)
'''Create a set that storage all vdi with -diff sufijo'''
vdi_set = set()
for line in getvdi_command.stdout:
if (line != '\n'):
vdi = line.rstrip()[22:]
if vdi[-5:] == "-diff":
vdi_set.add(vdi)
return vdi_set
##########################################################################3
# deleteDifferentialVdis: is a method that delete all differential
# vdis that xenserver don't remove automatically and are
# not assigned to a VM (vbd-uuids is null)
###########################################################################
def deleteDifferentialVdis(vdiName, logfile):
'''execute command that list all differential vdis from a specific vdiName'''
command = subprocess.Popen(['xe', 'vdi-list', 'name-label='+vdiName, 'params=uuid,vbd-uuids'], stdout=subprocess.PIPE)
uuid_set = set()
for line in command.stdout:
if (line != '\n'):
title = line.rstrip()[0:19]
if title[0:4] == 'uuid':
temp_uuid = line.rstrip()[21:57]
else:
if title[4:13] == 'vbd-uuids':
if line.rstrip()[21:57]=='':
uuid_set.add(temp_uuid)
'''once differential vdi are storaged in the set we proceed to delete them'''
'''xe vdi-destroy uuid=uuid '''
for uuid in uuid_set:
comando_borrar = subprocess.Popen(['xe', 'vdi-destroy', 'uuid='+uuid], stdout=subprocess.PIPE)
print comando_borrar.stdout.read()
print ".........Deleting differential with uuid:"+uuid
logfile.write(time.strftime("%c")+': ..................uuid --> '+uuid+'\n')
logfile = open('borradoVDI.log','a')
logfile.write(time.strftime("%c")+': ********* BEGIN *********'+'\n')
for dif in getvdis():
deleteDifferentialVdis(dif, logfile)
print ""
print "--------------------------------------------------"
print "--------------------------------------------------"
print "DELETING DIFFERENTIALS DISK OF --> "+dif
print "--------------------------------------------------"
print "--------------------------------------------------"
logfile.write(time.strftime("%c")+': DELETING DIFERENTIALS DISK OF --> '+dif+'\n')
logfile.write(time.strftime("%c")+': ********* END *********'+'\n')
logfile.close()