X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fvmwarecli.py;h=89f7807b2f0b633fddeef32ab258dd0703ef5140;hb=c4629bd3b12d44dd568240735f8cc546475170a3;hp=4583a651718362436b2c3f315ea47a6cb59f1e74;hpb=bf669b95be698c7ca0e1f43577e27aa355d11228;p=osm%2FRO.git diff --git a/osm_ro/vmwarecli.py b/osm_ro/vmwarecli.py index 4583a651..89f7807b 100755 --- a/osm_ro/vmwarecli.py +++ b/osm_ro/vmwarecli.py @@ -67,13 +67,13 @@ import sys from pyvcloud import Http import logging -import vimconn +from . import vimconn import time import uuid import urllib3 import requests -from vimconn_vmware import vimconnector +from .vimconn_vmware import vimconnector from requests.packages.urllib3.exceptions import InsecureRequestWarning from prettytable import PrettyTable @@ -108,7 +108,7 @@ def delete_network_action(vca=None, network_uuid=None): verify=vca.verify, logger=vca.logger) if response.status_code == requests.codes.ok: - print response.content + print(response.content) return response.content return None @@ -161,7 +161,7 @@ def print_vapp(vapp_dict=None): vm_table.add_row(entry) - print vm_table + print(vm_table) def print_org(org_dict=None): @@ -182,7 +182,7 @@ def print_org(org_dict=None): entry = [k, org_dict[k]] org_table.add_row(entry) - print org_table + print(org_table) def print_vm_list(vm_dict=None): @@ -213,7 +213,7 @@ def print_vm_list(vm_dict=None): entry.append(vm_dict[k]['memoryMB']) entry.append(vm_dict[k]['status']) vm_table.add_row(entry) - print vm_table + print(vm_table) except KeyError: logger.error("wrong key {}".format(KeyError.message)) pass @@ -232,14 +232,14 @@ def print_vdc_list(org_dict=None): return try: vdcs_dict = {} - if org_dict.has_key('vdcs'): + if 'vdcs' in org_dict: vdcs_dict = org_dict['vdcs'] vdc_table = PrettyTable(['vdc uuid', 'vdc name']) for k in vdcs_dict: entry = [k, vdcs_dict[k]] vdc_table.add_row(entry) - print vdc_table + print(vdc_table) except KeyError: logger.error("wrong key {}".format(KeyError.message)) logger.logger.debug(traceback.format_exc()) @@ -259,14 +259,14 @@ def print_network_list(org_dict=None): return try: network_dict = {} - if org_dict.has_key('networks'): + if 'networks' in org_dict: network_dict = org_dict['networks'] network_table = PrettyTable(['network uuid', 'network name']) for k in network_dict: entry = [k, network_dict[k]] network_table.add_row(entry) - print network_table + print(network_table) except KeyError: logger.error("wrong key {}".format(KeyError.message)) @@ -290,7 +290,7 @@ def print_org_details(org_dict=None): print_vdc_list(org_dict=org_dict) print_network_list(org_dict=org_dict) - if org_dict.has_key('catalogs'): + if 'catalogs' in org_dict: catalogs_dict = org_dict['catalogs'] catalog_table = PrettyTable(['catalog uuid', 'catalog name']) @@ -298,7 +298,7 @@ def print_org_details(org_dict=None): entry = [k, catalogs_dict[k]] catalog_table.add_row(entry) - print catalog_table + print(catalog_table) except KeyError: logger.error("wrong key {}".format(KeyError.message)) @@ -368,10 +368,10 @@ def list_actions(vim=None, action=None, namespace=None): def print_network_details(network_dict=None): try: - network_table = PrettyTable(network_dict.keys()) - entry = [network_dict.values()] + network_table = PrettyTable(list(network_dict.keys())) + entry = [list(network_dict.values())] network_table.add_row(entry[0]) - print network_table + print(network_table) except KeyError: logger.error("wrong key {}".format(KeyError.message)) logger.logger.debug(traceback.format_exc()) @@ -381,10 +381,10 @@ def osm_print(generic_dict=None): try: for element in generic_dict: - table = PrettyTable(element.keys()) - entry = [element.values()] + table = PrettyTable(list(element.keys())) + entry = [list(element.values())] table.add_row(entry[0]) - print table + print(table) except KeyError: logger.error("wrong key {}".format(KeyError.message)) logger.logger.debug(traceback.format_exc()) @@ -430,13 +430,13 @@ def view_actions(vim=None, action=None, namespace=None): if not namespace.uuid: vapp_uuid = vim.get_vappid(vdc=namespace.vcdvdc, vapp_name=namespace.vapp_name) if vapp_uuid is None: - print("Can't find vapp by given name {}".format(namespace.vapp_name)) + print(("Can't find vapp by given name {}".format(namespace.vapp_name))) return - print " namespace {}".format(namespace) + print(" namespace {}".format(namespace)) if vapp_dict is not None and namespace.osm: vm_info_dict = vim.get_vminstance(vim_vm_uuid=vapp_uuid) - print vm_info_dict + print(vm_info_dict) if vapp_dict is not None and namespace.osm != True: vapp_dict = vim.get_vapp(vdc_name=namespace.vcdvdc, vapp_name=vapp_uuid, isuuid=True) print_vapp(vapp_dict=vapp_dict) @@ -448,10 +448,10 @@ def view_actions(vim=None, action=None, namespace=None): # if request name based we need find UUID # TODO optimize it or move to external function if not namespace.uuid: - if not myorg.has_key('networks'): - print("Network {} is undefined in vcloud director for org {} vdc {}".format(namespace.network_name, + if 'networks' not in myorg: + print(("Network {} is undefined in vcloud director for org {} vdc {}".format(namespace.network_name, vim.name, - vim.tenant_name)) + vim.tenant_name))) return my_org_net = myorg['networks'] @@ -460,7 +460,7 @@ def view_actions(vim=None, action=None, namespace=None): network_uuid = network break - print print_network_details(network_dict=vim.get_vcd_network(network_uuid=network_uuid)) + print(print_network_details(network_dict=vim.get_vcd_network(network_uuid=network_uuid))) def create_actions(vim=None, action=None, namespace=None): @@ -477,16 +477,16 @@ def create_actions(vim=None, action=None, namespace=None): logger.debug("Creating a network in vcloud director".format(namespace.network_name)) network_uuid = vim.create_network(namespace.network_name) if network_uuid is not None: - print ("Crated new network {} and uuid: {}".format(namespace.network_name, network_uuid)) + print(("Crated new network {} and uuid: {}".format(namespace.network_name, network_uuid))) else: - print ("Failed create a new network {}".format(namespace.network_name)) + print(("Failed create a new network {}".format(namespace.network_name))) elif action == 'vdc' or namespace.action == 'vdc': logger.debug("Creating a new vdc in vcloud director.".format(namespace.vdc_name)) vdc_uuid = vim.create_vdc(namespace.vdc_name) if vdc_uuid is not None: - print ("Crated new vdc {} and uuid: {}".format(namespace.vdc_name, vdc_uuid)) + print(("Crated new vdc {} and uuid: {}".format(namespace.vdc_name, vdc_uuid))) else: - print ("Failed create a new vdc {}".format(namespace.vdc_name)) + print(("Failed create a new vdc {}".format(namespace.vdc_name))) else: return None @@ -519,11 +519,11 @@ def upload_image(vim=None, image_file=None): try: catalog_uuid = vim.get_image_id_from_path(path=image_file, progress=True) if catalog_uuid is not None and validate_uuid4(catalog_uuid): - print("Image uploaded and uuid {}".format(catalog_uuid)) + print(("Image uploaded and uuid {}".format(catalog_uuid))) return True except vimconn.vimconnException as upload_exception: - print("Failed uploaded {} image".format(image_file)) - print("Error Reason: {}".format(upload_exception.message)) + print(("Failed uploaded {} image".format(image_file))) + print(("Error Reason: {}".format(upload_exception.message))) return False @@ -553,22 +553,22 @@ def boot_image(vim=None, image_name=None, vm_name=None): if vim_catalog is None: return None - print (" Booting {} image id {} ".format(vm_name, vim_catalog)) + print((" Booting {} image id {} ".format(vm_name, vim_catalog))) vm_uuid = vim.new_vminstance(name=vm_name, image_id=vim_catalog) if vm_uuid is not None and validate_uuid4(vm_uuid): - print("Image booted and vm uuid {}".format(vm_uuid)) + print(("Image booted and vm uuid {}".format(vm_uuid))) vapp_dict = vim.get_vapp(vdc_name=namespace.vcdvdc, vapp_name=vm_uuid, isuuid=True) if vapp_dict is not None: print_vapp(vapp_dict=vapp_dict) return True except vimconn.vimconnNotFoundException as notFound: - print("Failed boot {} image".format(image_name)) - print(notFound.message) + print(("Failed boot {} image".format(image_name))) + print((notFound.message)) except vimconn.vimconnException as vimconError: - print("Failed boot {} image".format(image_name)) - print(vimconError.message) + print(("Failed boot {} image".format(image_name))) + print((vimconError.message)) except: - print("Failed boot {} image".format(image_name)) + print(("Failed boot {} image".format(image_name))) return False @@ -611,7 +611,7 @@ def vmwarecli(command=None, action=None, namespace=None): if namespace.vcdvdc is None: while True: - vcduser = input("Enter vcd username: ") + vcduser = eval(input("Enter vcd username: ")) if vcduser is not None and len(vcduser) > 0: break else: @@ -619,7 +619,7 @@ def vmwarecli(command=None, action=None, namespace=None): if namespace.vcdpassword is None: while True: - vcdpasword = input("Please enter vcd password: ") + vcdpasword = eval(input("Please enter vcd password: ")) if vcdpasword is not None and len(vcdpasword) > 0: break else: @@ -627,7 +627,7 @@ def vmwarecli(command=None, action=None, namespace=None): if namespace.vcdhost is None: while True: - vcdhost = input("Please enter vcd host name or ip: ") + vcdhost = eval(input("Please enter vcd host name or ip: ")) if vcdhost is not None and len(vcdhost) > 0: break else: @@ -635,7 +635,7 @@ def vmwarecli(command=None, action=None, namespace=None): if namespace.vcdorg is None: while True: - vcdorg = input("Please enter vcd organization name: ") + vcdorg = eval(input("Please enter vcd organization name: ")) if vcdorg is not None and len(vcdorg) > 0: break else: @@ -797,7 +797,7 @@ if __name__ == '__main__': namespace = parser.parse_args() # put command_line args to mapping - command_line_args = {k: v for k, v in vars(namespace).items() if v} + command_line_args = {k: v for k, v in list(vars(namespace).items()) if v} d = defaults.copy() d.update(os.environ)