-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrmcluster.py
40 lines (35 loc) · 1.49 KB
/
rmcluster.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
import argparse
import os
import json, sys
import urllib.request
from pprint import pprint
from pprint import pformat
import rimuapi
# from jsonpath_rw import jsonpath, parse
import objectpath
class Args(object):
def __init__(self):
parser = argparse.ArgumentParser(description="Delete/shutdown all VMs associated with a RimuHosting Kubernetes cluster.")
parser.add_argument("--cluster", required=True, help="Unique id for this cluster. e.g. cluster1")
parser.parse_args(namespace=self)
def run(self):
xx = rimuapi.Api()
# minions first
master = xx.orders('', {'server_type': 'VPS','meta_search': 'com.rimuhosting.kclusterid:'+self.cluster+' com.rimuhosting.kismaster:Y'})
if not master or len(master)==0:
raise Exception("Could not find a master VM for that cluster.")
minions = xx.orders('N', {'server_type': 'VPS','meta_search': 'com.rimuhosting.kclusterid:'+self.cluster+' com.rimuhosting.kisminion:Y'})
output = []
for order in minions:
#print("deleting " + str(order["order_oid"]))
resp = xx.delete(order_oid=order["order_oid"])
output.append(resp)
# then master
for order in master:
#print("deleting " + str(order["order_oid"]))
resp = xx.delete(order_oid=order["order_oid"])
output.append(resp)
print(pformat(output))
if __name__ == '__main__':
args = Args();
args.run()