Verified Commit 59723b68 authored by Nate Childers's avatar Nate Childers 🚴

loads of flake8 changes and variables renamed in previous handler

parent aa3e48f0
Pipeline #140118 failed with stages
in 8 seconds
......@@ -47,7 +47,7 @@ def open_session(args):
auth=(args.username, args.password))
if res.status_code == 200:
return session
print "Error establishing vcenter session: " + res
print("Error establishing vcenter session: %s", res)
return False
......@@ -59,7 +59,7 @@ def get_vmid(session, args):
if resp.get("value", None) is not None:
vmid = resp.get("value", None)[0].get("vm", None)
return vmid
print "No value in response? "+resp
print("No value in response? %s", resp)
return None
return None
......@@ -198,7 +198,7 @@ def add_blank_floppy(session, args, vmid):
if res.status_code == 200:
floppy_id = res.json().get("value")
print "added new floppy drive: " + floppy_id
print("added new floppy drive: %s", floppy_id)
return floppy_id
return None
......@@ -218,9 +218,9 @@ def update_library_item_description(session, vcenter, cl_item_id):
if res.status_code == 200:
print "Updated Content Library Item description"
print("Updated Content Library Item description")
return True
print "Failed to update Content Library Item description"
print("Failed to update Content Library Item description")
return None
......@@ -234,8 +234,8 @@ def update_library_item(session, args, cl_item_id, changes):
res = session.patch('https://''/rest/com/vmware/content/library/item/id:'+cl_item_id,
json={"update_spec": changes})
if res.status_code == 200:
print "Updated Content Library item properties"
print changes
print("Updated Content Library item properties")
return True
return None
......@@ -243,13 +243,13 @@ def update_library_item(session, args, cl_item_id, changes):
def delete_vm(session, args, vmid):
keep_vm = os.environ.get('KEEP_SOURCE_VM', False)
if (keep_vm == "True") or (keep_vm is True):
print "Not deleting vm "+args.vm
print("Not deleting vm: %s", args.vm)
return None
'''Deletes the source VM'''
res = session.delete('https://''/rest/vcenter/vm/'+vmid)
if res.status_code == 200:
print "VM "+args.vm+" deleted."
print("VM {} deleted.".format(args.vm))
return True
return None
......@@ -258,7 +258,7 @@ def delete_content_library_item(session, args, cl_item_id):
''' Deletes a content library item '''
res = session.delete('https://''/rest/com/vmware/content/library/item/id:'+cl_item_id)
if res.status_code == 200:
print "Content Library Item Id: {} deleted".format(cl_item_id)
print("Content Library Item Id: {} deleted".format(cl_item_id))
return True
return None
......@@ -267,7 +267,7 @@ def rename_content_library_item(session, args, cl_item_id, name):
''' renames a library item by ID '''
changes = {"name": name}
if update_library_item(session, args, cl_item_id, changes):
print "Content Library Item {} renamed to {}".format(args.cli, name)
print("Content Library Item {} renamed to {}".format(args.cli, name))
return True
return None
......@@ -279,19 +279,19 @@ def deploy_template(session, args, clid, cl_item_id):
to the production template name (e.g. os-version)
previous_cl_item_id = get_content_library_item_id(session,, clid, args.deploy)
old_previous_cl_item_id = get_content_library_item_id(session,, clid, args.deploy + '.previous')
existing_cl_item_id = get_content_library_item_id(session,, clid, args.deploy)
existing_previous_cl_item_id = get_content_library_item_id(session,, clid, args.deploy + '.previous')
print "deploy_template: {} to {}".format(args.cli, args.deploy)
if previous_cl_item_id is not None:
print("deploy_template: {} to {}".format(args.cli, args.deploy))
if existing_cl_item_id is not None:
# remove old .previous content library item
if old_previous_cl_item_id is not None:
print "deploy_template: old {} removed".format(args.deploy + '.previous')
delete_old_previous = delete_content_library_item(session, args, old_previous_cl_item_id)
return delete_old_previous
rename_previous = rename_content_library_item(session, args, previous_cl_item_id, args.deploy + '.previous')
if existing_previous_cl_item_id is not None:
print("deploy_template: old {} removed".format(args.deploy + '.previous'))
delete_previous = delete_content_library_item(session, args, existing_previous_cl_item_id)
return delete_previous
rename_previous = rename_content_library_item(session, args, existing_cl_item_id, args.deploy + '.previous')
if rename_previous is not None:
print "deploy_template: .previous renamed; deploying {} to {}".format(args.cli, args.deploy)
print("deploy_template: .previous renamed; deploying {} to {}".format(args.cli, args.deploy))
rename_target = rename_content_library_item(session, args, cl_item_id, args.deploy)
return rename_target
......@@ -316,15 +316,15 @@ def main():
vmid = get_vmid(session, args)
if cl_item_id is not None:
print "Updating content library item: "+args.cli
print("Updating content library item: {}".format(args.cli))
conversion = update_content_library_item(session, args, cl_id, vmid, cl_item_id)
update_library_item_description(session,, cl_item_id)
print "Creating new content library item."
print("Creating new content library item.")
conversion = convert_vm_to_content_item(session, args, cl_id, vmid)
if conversion is not None:
delete_vm(session, args, vmid)
print "Conversion succesful! deleting: "+args.vm
print("Conversion succesful! deleting: {}".format(args.vm))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment