More Py3 conversion work
diff --git a/osm_ro/vmwarecli.py b/osm_ro/vmwarecli.py
index 89f7807..4583a65 100755
--- a/osm_ro/vmwarecli.py
+++ b/osm_ro/vmwarecli.py
@@ -67,13 +67,13 @@
from pyvcloud import Http
import logging
-from . import vimconn
+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 @@
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 @@
vm_table.add_row(entry)
- print(vm_table)
+ print vm_table
def print_org(org_dict=None):
@@ -182,7 +182,7 @@
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 @@
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 @@
return
try:
vdcs_dict = {}
- if 'vdcs' in org_dict:
+ if org_dict.has_key('vdcs'):
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 @@
return
try:
network_dict = {}
- if 'networks' in org_dict:
+ if org_dict.has_key('networks'):
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 @@
print_vdc_list(org_dict=org_dict)
print_network_list(org_dict=org_dict)
- if 'catalogs' in org_dict:
+ if org_dict.has_key('catalogs'):
catalogs_dict = org_dict['catalogs']
catalog_table = PrettyTable(['catalog uuid', 'catalog name'])
@@ -298,7 +298,7 @@
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 print_network_details(network_dict=None):
try:
- network_table = PrettyTable(list(network_dict.keys()))
- entry = [list(network_dict.values())]
+ network_table = PrettyTable(network_dict.keys())
+ entry = [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 @@
try:
for element in generic_dict:
- table = PrettyTable(list(element.keys()))
- entry = [list(element.values())]
+ table = PrettyTable(element.keys())
+ entry = [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 @@
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 @@
# if request name based we need find UUID
# TODO optimize it or move to external function
if not namespace.uuid:
- if 'networks' not in myorg:
- print(("Network {} is undefined in vcloud director for org {} vdc {}".format(namespace.network_name,
+ if not myorg.has_key('networks'):
+ 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 @@
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 @@
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 @@
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 @@
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 @@
if namespace.vcdvdc is None:
while True:
- vcduser = eval(input("Enter vcd username: "))
+ vcduser = input("Enter vcd username: ")
if vcduser is not None and len(vcduser) > 0:
break
else:
@@ -619,7 +619,7 @@
if namespace.vcdpassword is None:
while True:
- vcdpasword = eval(input("Please enter vcd password: "))
+ vcdpasword = input("Please enter vcd password: ")
if vcdpasword is not None and len(vcdpasword) > 0:
break
else:
@@ -627,7 +627,7 @@
if namespace.vcdhost is None:
while True:
- vcdhost = eval(input("Please enter vcd host name or ip: "))
+ vcdhost = input("Please enter vcd host name or ip: ")
if vcdhost is not None and len(vcdhost) > 0:
break
else:
@@ -635,7 +635,7 @@
if namespace.vcdorg is None:
while True:
- vcdorg = eval(input("Please enter vcd organization name: "))
+ vcdorg = input("Please enter vcd organization name: ")
if vcdorg is not None and len(vcdorg) > 0:
break
else:
@@ -797,7 +797,7 @@
namespace = parser.parse_args()
# put command_line args to mapping
- command_line_args = {k: v for k, v in list(vars(namespace).items()) if v}
+ command_line_args = {k: v for k, v in vars(namespace).items() if v}
d = defaults.copy()
d.update(os.environ)