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
verify=vca.verify,
logger=vca.logger)
if response.status_code == requests.codes.ok:
- print response.content
+ print(response.content)
return response.content
return None
vm_table.add_row(entry)
- print vm_table
+ print(vm_table)
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):
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
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())
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))
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'])
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))
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())
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())
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)
# 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']
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):
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
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
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
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:
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:
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:
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:
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)