-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (54 loc) · 1.52 KB
/
main.py
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
import sys
import re
from vnc_api import vnc_api
from cfgm_common.exceptions import RefsExistError
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
self.items.pop()
def printitm(self):
print(self.items)
def isEmpty(self):
return self.items == []
def peek(self):
return self.items[len(self.items)-1]
def delete_recursively(client, stk, del_uuid):
try:
_, res_type = client.id_to_fq_name_type(del_uuid)
print(res_type, del_uuid)
client._object_delete(res_type, id = del_uuid)
except RefsExistError as err:
#print (str(err))
stk.push(del_uuid)
stk.printitm()
uuids = re.findall('([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})', str(err))
print(uuids)
for uuid in uuids:
delete_recursively(client, stk, uuid)
except NoIdError:
print("Uuid has already been deleted")
def delete_by_uuid(client, del_uuid):
try:
_, res_type = client.id_to_fq_name_type(del_uuid)
print(res_type, del_uuid)
client._object_delete(res_type, id = del_uuid)
except RefsExistError as err:
print (str(err))
def main():
stk = Stack()
client = vnc_api.VncApi("127.0.0.1", 8082, False)
delete_recursively(client, stk, str(sys.argv[1]))
print("I am dumping all stack")
stk.printitm()
print("I just dunped all stack")
while stk.isEmpty() == False:
print("Am clearing stack")
pend_uuid = stk.peek()
print("Pending uuid: " , pend_uuid)
delete_by_uuid(client, pend_uuid)
stk.pop()
if __name__ == "__main__":
main()