-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlisttemplates.py
More file actions
executable file
·39 lines (29 loc) · 1.28 KB
/
listtemplates.py
File metadata and controls
executable file
·39 lines (29 loc) · 1.28 KB
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
#!/usr/bin/python
import sys
import CloudStack
import time
from termcolor import colored
from urllib2 import urlopen, HTTPError
import cloudconstants as k
cloudstack = CloudStack.Client(API_URI, YOUR_API_KEY, YOUR_API_SECRET)
if len(sys.argv) < 2:
tmpltype = 'community'
else:
tmpltype = sys.argv[1]
if tmpltype.lower() not in ['community', 'featured', 'self', 'executable']:
sys.exit("Invalid option. Valid options are 'community', 'featured', 'self', 'executable'")
# args = {'templatefilter': tmpltype.lower(), 'projectid': '-1'}
args = {'templatefilter': tmpltype.lower(), 'listall': '-1', 'projectid': '-1'}
tmpls = cloudstack.listTemplates(args)
print "\nAvailable Templates for Template Type:",
sys.stdout.flush()
print '%s' % colored(tmpltype.upper(), attrs=['bold'])
print "================================================="
header = ['project', 'id', 'zone', 'name']
print colored(header[0].ljust(35) + header[1].center(42) + header[2].center(13)+ header[3].center(45) + '\n', attrs=['bold', 'underline'])
for tmpl in tmpls:
if tmpl.get('project'):
pname = tmpl['project']
else:
pname = '--|___________ Shared ____________|'
print "%s %s %s %s\n" % (pname[:35].ljust(37, '-'), tmpl['id'][:42].ljust(42), tmpl['zonename'][:8].ljust(8), tmpl['ostypename'])