forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print-custom-templates
executable file
·42 lines (34 loc) · 1.14 KB
/
print-custom-templates
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
#!/usr/bin/python
# Print out custom template UUIDs in CLI comma-separated minimal format
# (c) Anil Madhavapeddy, Citrix Systems Inc, 2008
import atexit
import XenAPI
import os, sys, time
def logout():
try:
session.xenapi.session.logout()
except:
pass
atexit.register(logout)
def main(argv):
try:
session = XenAPI.xapi_local()
session.xenapi.login_with_password("", "", "1.0", "xen-api-scripts-custom-template")
templates = session.xenapi.VM.get_all_records_where('field "is_a_template" = "true" and field "is_a_snapshot" = "false"' )
except:
print >> sys.stderr, "Error retrieving template list"
sys.exit(1)
output=[]
for tmplref in templates.keys():
tmplrec = templates[tmplref]
try:
if not tmplrec['other_config'].has_key('default_template'):
output.append(tmplrec['uuid'])
elif tmplrec['other_config']['default_template'] != true:
output.append(tmplrec['uuid'])
except:
pass
print(str.join(',', output))
session.xenapi.logout()
if __name__ == "__main__":
main(sys.argv[1:])