-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptscmd.py
51 lines (41 loc) · 1.6 KB
/
scriptscmd.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 cmd
import sys
class scriptscmd(cmd.Cmd):
def __init__(self, api, completekey='tab', stdin=None, stdout=None):
cmd.Cmd.__init__(self, completekey='tab', stdin=None, stdout=None)
self.api = api
self.prompt = 'Scalr>'
self.intro = 'Script Console\nBy Michael Chenetz\n--------------'
def help_listenv(self):
print ('Lists all available environments')
def do_listenv(self):
print('Environments: ')
for env in self.api.listEnvironments():
print str(env['id']) + '. ' + env['name']
def help_list(self):
print ('Lists All Scripts')
print ('cmd: list')
def do_list(self, null):
print ('Scripts: ')
for list in self.api.listScripts():
print str(list['id']) + '. ' + list['name']
def help_getscript(self):
print('Get latest version of a script')
print('cmd: getscript')
print('cmd: getscript [Script ID]')
print('cmd: getscript [Script Name]')
def do_getscript(self, cmd):
if not cmd:
self.do_list(self)
cmd = input('Select Scripts: ')
if cmd:
if type(cmd) is int:
print(self.api.getScriptVersion(cmd, self.api.getLatestScriptVersion(cmd))['body'])
elif type(cmd) is str:
print(self.api.getScriptVersion(self.api.getIdFromName(cmd), self.api.getLatestScriptVersion(self.api.getIdFromName(cmd)))['body'])
def help_exit(self):
print ('Exits application')
def do_exit(self, null):
sys.exit(0)
def postloop(self):
print ('Goodbye')