Merge "Make print py3 compatible"
This commit is contained in:
commit
a074c661e4
@ -65,8 +65,8 @@ def main():
|
||||
options, days_old = _parse_args()
|
||||
|
||||
if not os.path.exists(BASE):
|
||||
print >> sys.stderr, "error: '%s' doesn't exist. Make sure you're"\
|
||||
" running this on the dom0." % BASE
|
||||
sys.stderr.write("error: '%s' doesn't exist. Make sure you're"\
|
||||
" running this on the dom0." % BASE)
|
||||
sys.exit(1)
|
||||
|
||||
lockpaths_removed = 0
|
||||
@ -89,8 +89,8 @@ def main():
|
||||
removed += 1
|
||||
|
||||
if options.verbose:
|
||||
print 'Removing old lock: %03d %s' % (lock_age_days,
|
||||
lockpath)
|
||||
print('Removing old lock: %03d %s' % (lock_age_days,
|
||||
lockpath))
|
||||
|
||||
if not options.dry_run:
|
||||
os.unlink(lockpath)
|
||||
@ -100,23 +100,23 @@ def main():
|
||||
nspaths_removed += 1
|
||||
|
||||
if options.verbose:
|
||||
print 'Removing empty namespace: %s' % nspath
|
||||
print('Removing empty namespace: %s' % nspath)
|
||||
|
||||
if not options.dry_run:
|
||||
try:
|
||||
os.rmdir(nspath)
|
||||
except OSError, e:
|
||||
if e.errno == errno.ENOTEMPTY:
|
||||
print >> sys.stderr, "warning: directory '%s'"\
|
||||
" not empty" % nspath
|
||||
sys.stderr.write("warning: directory '%s'"\
|
||||
" not empty" % nspath)
|
||||
else:
|
||||
raise
|
||||
|
||||
if options.dry_run:
|
||||
print "** Dry Run **"
|
||||
print("** Dry Run **")
|
||||
|
||||
print "Total locks removed: ", lockpaths_removed
|
||||
print "Total namespaces removed: ", nspaths_removed
|
||||
print("Total locks removed: ", lockpaths_removed)
|
||||
print("Total namespaces removed: ", nspaths_removed)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -60,9 +60,9 @@ def main():
|
||||
dry_run=CONF.dry_run)
|
||||
|
||||
if '--verbose' in sys.argv:
|
||||
print '\n'.join(destroyed)
|
||||
print('\n'.join(destroyed))
|
||||
|
||||
print "Destroyed %d cached VDIs" % len(destroyed)
|
||||
print("Destroyed %d cached VDIs" % len(destroyed))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -79,7 +79,7 @@ def main():
|
||||
# Parse out UUID
|
||||
instance_uuid = name_label.replace('instance-', '')[:36]
|
||||
if not uuidutils.is_uuid_like(instance_uuid):
|
||||
print "error: name label '%s' wasn't UUID-like" % name_label
|
||||
print("error: name label '%s' wasn't UUID-like" % name_label)
|
||||
continue
|
||||
|
||||
vdi_type = vdi_rec['name_description']
|
||||
@ -92,11 +92,11 @@ def main():
|
||||
vdi_type, instance)
|
||||
|
||||
if CONF.verbose:
|
||||
print "Setting other_config for instance_uuid=%s vdi_uuid=%s" % (
|
||||
instance_uuid, vdi_rec['uuid'])
|
||||
print("Setting other_config for instance_uuid=%s vdi_uuid=%s" % (
|
||||
instance_uuid, vdi_rec['uuid']))
|
||||
|
||||
if CONF.dry_run:
|
||||
print "Dry run completed"
|
||||
print("Dry run completed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -26,7 +26,7 @@ DOM0_CLEANUP_SCRIPT = "/tmp/destroy_cache_vdis"
|
||||
def run(cmd):
|
||||
ret = subprocess.call(cmd, shell=True)
|
||||
if ret != 0:
|
||||
print >> sys.stderr, "Command exited non-zero: %s" % cmd
|
||||
sys.stderr.write("Command exited non-zero: %s" % cmd)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
@ -59,8 +59,8 @@ def migrate_server(server_name):
|
||||
stdout, stderr = proc.communicate()
|
||||
status = stdout.strip()
|
||||
if status.upper() != 'VERIFY_RESIZE':
|
||||
print >> sys.stderr, "Server %(server_name)s failed to rebuild"\
|
||||
% locals()
|
||||
sys.stderr.write("Server %(server_name)s failed to rebuild"\
|
||||
% locals())
|
||||
return False
|
||||
|
||||
# Confirm the resize
|
||||
@ -90,8 +90,8 @@ def rebuild_server(server_name, snapshot_name):
|
||||
stdout, stderr = proc.communicate()
|
||||
status = stdout.strip()
|
||||
if status != 'ACTIVE':
|
||||
print >> sys.stderr, "Server %(server_name)s failed to rebuild"\
|
||||
% locals()
|
||||
sys.stderr.write("Server %(server_name)s failed to rebuild"\
|
||||
% locals())
|
||||
return False
|
||||
|
||||
return True
|
||||
@ -146,7 +146,7 @@ def main():
|
||||
for test in args.tests:
|
||||
test_func = globals().get("test_%s" % test)
|
||||
if not test_func:
|
||||
print >> sys.stderr, "test '%s' not found" % test
|
||||
sys.stderr.write("test '%s' not found" % test)
|
||||
sys.exit(1)
|
||||
|
||||
contexts = [(x, args) for x in range(args.num_runs)]
|
||||
@ -163,7 +163,7 @@ def main():
|
||||
result = "SUCCESS" if success else "FAILED"
|
||||
|
||||
duration = time.time() - start_time
|
||||
print "%s, finished in %.2f secs" % (result, duration)
|
||||
print("%s, finished in %.2f secs" % (result, duration))
|
||||
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
|
@ -62,7 +62,7 @@ def execute(cmd, ok_exit_codes=None):
|
||||
|
||||
|
||||
def usage():
|
||||
print "usage: %s <SR PATH> <print|delete|move>" % sys.argv[0]
|
||||
print("usage: %s <SR PATH> <print|delete|move>" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ def main():
|
||||
|
||||
if action == 'move':
|
||||
if len(sys.argv) < 4:
|
||||
print "error: must specify where to move bad VHDs"
|
||||
print("error: must specify where to move bad VHDs")
|
||||
sys.exit(1)
|
||||
|
||||
bad_vhd_path = sys.argv[3]
|
||||
@ -111,7 +111,7 @@ def main():
|
||||
|
||||
for bad_leaf in bad_leaves:
|
||||
for bad_vhd in walk_vhds(bad_leaf):
|
||||
print bad_vhd
|
||||
print(bad_vhd)
|
||||
if action == "print":
|
||||
pass
|
||||
elif action == "delete":
|
||||
|
@ -132,7 +132,7 @@ def print_xen_object(obj_type, obj, indent_level=0, spaces_per_indent=4):
|
||||
name_label = ""
|
||||
msg = "%(obj_type)s (%(uuid)s) '%(name_label)s'" % locals()
|
||||
indent = " " * spaces_per_indent * indent_level
|
||||
print "".join([indent, msg])
|
||||
print("".join([indent, msg]))
|
||||
|
||||
|
||||
def _find_vdis_connected_to_vm(xenapi, connected_vdi_uuids):
|
||||
@ -247,38 +247,38 @@ def list_orphaned_vdis(vdi_uuids):
|
||||
"""List orphaned VDIs."""
|
||||
for vdi_uuid in vdi_uuids:
|
||||
if CONF.verbose:
|
||||
print "ORPHANED VDI (%s)" % vdi_uuid
|
||||
print("ORPHANED VDI (%s)" % vdi_uuid)
|
||||
else:
|
||||
print vdi_uuid
|
||||
print(vdi_uuid)
|
||||
|
||||
|
||||
def clean_orphaned_vdis(xenapi, vdi_uuids):
|
||||
"""Clean orphaned VDIs."""
|
||||
for vdi_uuid in vdi_uuids:
|
||||
if CONF.verbose:
|
||||
print "CLEANING VDI (%s)" % vdi_uuid
|
||||
print("CLEANING VDI (%s)" % vdi_uuid)
|
||||
|
||||
vdi_ref = call_xenapi(xenapi, 'VDI.get_by_uuid', vdi_uuid)
|
||||
try:
|
||||
call_xenapi(xenapi, 'VDI.destroy', vdi_ref)
|
||||
except XenAPI.Failure, exc:
|
||||
print >> sys.stderr, "Skipping %s: %s" % (vdi_uuid, exc)
|
||||
sys.stderr.write("Skipping %s: %s" % (vdi_uuid, exc))
|
||||
|
||||
|
||||
def list_orphaned_instances(orphaned_instances):
|
||||
"""List orphaned instances."""
|
||||
for vm_ref, vm_rec, orphaned_instance in orphaned_instances:
|
||||
if CONF.verbose:
|
||||
print "ORPHANED INSTANCE (%s)" % orphaned_instance.name
|
||||
print("ORPHANED INSTANCE (%s)" % orphaned_instance.name)
|
||||
else:
|
||||
print orphaned_instance.name
|
||||
print(orphaned_instance.name)
|
||||
|
||||
|
||||
def clean_orphaned_instances(xenapi, orphaned_instances):
|
||||
"""Clean orphaned instances."""
|
||||
for vm_ref, vm_rec, instance in orphaned_instances:
|
||||
if CONF.verbose:
|
||||
print "CLEANING INSTANCE (%s)" % instance.name
|
||||
print("CLEANING INSTANCE (%s)" % instance.name)
|
||||
|
||||
cleanup_instance(xenapi, instance, vm_ref, vm_rec)
|
||||
|
||||
@ -304,10 +304,10 @@ def main():
|
||||
|
||||
if command == "list-vdis":
|
||||
if CONF.verbose:
|
||||
print "Connected VDIs:\n"
|
||||
print("Connected VDIs:\n")
|
||||
orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi)
|
||||
if CONF.verbose:
|
||||
print "\nOrphaned VDIs:\n"
|
||||
print("\nOrphaned VDIs:\n")
|
||||
list_orphaned_vdis(orphaned_vdi_uuids)
|
||||
elif command == "clean-vdis":
|
||||
orphaned_vdi_uuids = find_orphaned_vdi_uuids(xenapi)
|
||||
@ -321,7 +321,7 @@ def main():
|
||||
elif command == "test":
|
||||
doctest.testmod()
|
||||
else:
|
||||
print "Unknown command '%s'" % command
|
||||
print("Unknown command '%s'" % command)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user