forked from simonccc/kopsrox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkopsrox.py
executable file
·101 lines (82 loc) · 1.74 KB
/
kopsrox.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
import os, sys
sys.path[0:0] = ['lib/']
from termcolor import cprint
# check file exists
if not os.path.isfile('kopsrox.ini'):
import kopsrox_ini as kopsrox_ini
kopsrox_ini.init_kopsrox_ini()
exit(0)
# kopsrox verbs and commands
cmds = {
"image": {
"info" : '',
"create" : '',
"destroy": '',
},
"cluster": {
"info" : '',
"create" : '',
"update" : '',
"destroy" : '',
"kubectl" : 'cmd',
"kubeconfig" : '',
},
"etcd": {
"snapshot" : '',
"restore" : 'snapshot',
"list" : '',
"prune" : '',
},
}
# create list of verbs
verbs = list(cmds)
def kmsg(msg):
cprint('kopsrox', "blue",attrs=["bold"], end='')
cprint('::', "cyan", end='' )
print(msg)
# print list of verbs
def verbs_help():
kmsg('kopsrox [verb] [command]')
cprint('verbs:', "yellow", attrs=["bold"])
for i in verbs:
print(' * ',i)
# print verbs cmds
def cmds_help(verb):
kmsg(verb+' [command]')
print('commands:')
for i in list(cmds[verb]):
print(' * ',i)
# handle verb
try:
# check for 1st argument
if (sys.argv[1]):
# map 1st arg to verb
verb = str(sys.argv[1])
# if verb not found in cmds dict
if not verb in verbs:
exit()
except:
verbs_help()
exit()
# handle command
try:
# 2nd arg
if (sys.argv[2]):
# map 2nd arg to cmd
cmd = sys.argv[2]
# if cmd not in list of commands
if not cmd in list(cmds[verb]):
exit()
except:
cmds_help(verb)
exit()
# handle args
try:
if cmds[verb][cmd] and sys.argv[3]:
pass
except:
kmsg('kopsrox ' + verb + ' ' + cmd + ' [' + cmds[verb][cmd] + ']')
exit(0)
# run passed verb
exec_verb = __import__('verb_' + verb)