forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request xapi-project#5301 from acefei/private/feis/print-c…
…ustom-templates update print-custom-templates to python3
- Loading branch information
Showing
1 changed file
with
15 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/env python3 | ||
# Print out custom template UUIDs in CLI comma-separated minimal format | ||
# (c) Anil Madhavapeddy, Citrix Systems Inc, 2008 | ||
|
||
import atexit | ||
import contextlib | ||
import sys | ||
|
||
import XenAPI | ||
import os, sys, time | ||
|
||
def logout(): | ||
try: | ||
|
||
def logout(session): | ||
with contextlib.suppress(Exception): | ||
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") | ||
atexit.register(logout, session) | ||
|
||
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" | ||
print("Error retrieving template list", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
output=[] | ||
for tmplref in templates.keys(): | ||
for tmplref in templates: | ||
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: | ||
if "default_template" not in tmplrec["other_config"] or tmplrec["other_config"]["default_template"] != 'true': | ||
output.append(tmplrec["uuid"]) | ||
except KeyError: | ||
pass | ||
print(str.join(',', output)) | ||
|
||
print(str.join(",", output)) | ||
session.xenapi.logout() | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) | ||
|
||
|