-
Notifications
You must be signed in to change notification settings - Fork 1
/
ovh-delete-vip.py
51 lines (48 loc) · 1.77 KB
/
ovh-delete-vip.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
import json
import ovh
import time
import random
import threading
import time
exec(compile(open("config.py", "rb").read(), "config.py", 'exec'))
client = ovh.Client(
endpoint=API_ENDPOINT, # Endpoint of API
application_key=APPKEY, # Application Key
application_secret=APPSEC, # Application Secret
consumer_key=USERKEY, # Consumer Key
)
macwhitelist = []
ipwhitelist = []
def task_holder():
while True:
count = 0
tasklistjson = client.get('/dedicated/server/' + SRV_NAME + '/task',
status='todo',
)
for taskitem in tasklistjson:
count = count + 1
#print("TASK REMAIN: " + str(count))
if (count < CONN_TASK_CTRL):
return 0
time.sleep(2)
def main():
print("This script will delete all virtualMac under " + SRV_NAME + " except following whitelist")
print("IP White List: " + str(ipwhitelist))
print("MAC White List: " + str(macwhitelist))
print("To Cancel, Press Ctrl+C in 3 Seconds")
time.sleep(3)
macjson = client.get('/dedicated/server/' + SRV_NAME + '/virtualMac')
for macitem in macjson:
if str(macitem) not in macwhitelist:
print("MAC:" + macitem)
ipjson = client.get('/dedicated/server/' + SRV_NAME + '/virtualMac/' + macitem + '/virtualAddress')
for ipitem in ipjson:
if str(ipitem) not in ipwhitelist:
thread = threading.Thread(target=task_holder)
thread.start()
thread.join()
print("IP:" + ipitem)
client.delete('/dedicated/server/' + SRV_NAME + '/virtualMac/' + macitem + '/virtualAddress/' + ipitem)
time.sleep(1)
if __name__ == '__main__':
main()