from progressbar import Percentage, Bar, ETA, FileTransferSpeed, ProgressBar
import vimconn
from progressbar import Percentage, Bar, ETA, FileTransferSpeed, ProgressBar
import vimconn
# we have two case if we want to initialize VDC ID or VDC name at run time
# tenant_name provided but no tenant id
# we have two case if we want to initialize VDC ID or VDC name at run time
# tenant_name provided but no tenant id
else:
raise vimconn.vimconnException("Tenant name indicated but not present in vcloud director.")
# case two we have tenant_id but we don't have tenant name so we find and set it.
else:
raise vimconn.vimconnException("Tenant name indicated but not present in vcloud director.")
# case two we have tenant_id but we don't have tenant name so we find and set it.
"""Obtain flavor details from the VIM
Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } #TODO to concrete
"""
"""Obtain flavor details from the VIM
Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } #TODO to concrete
"""
raise vimconn.vimconnNotFoundException("Flavor not found.")
flavorlist.pop(flavor_id, None)
return flavor_id
def new_image(self, image_dict):
raise vimconn.vimconnNotFoundException("Flavor not found.")
flavorlist.pop(flavor_id, None)
return flavor_id
def new_image(self, image_dict):
Adds a tenant image to VIM
Returns:
200, image-id if the image is created
<0, message if there is an error
Adds a tenant image to VIM
Returns:
200, image-id if the image is created
<0, message if there is an error
def upload_ovf(self, vca=None, catalog_name=None, image_name=None, media_file_name=None,
description='', progress=False, chunk_bytes=128 * 1024):
"""
Uploads a OVF file to a vCloud catalog
def upload_ovf(self, vca=None, catalog_name=None, image_name=None, media_file_name=None,
description='', progress=False, chunk_bytes=128 * 1024):
"""
Uploads a OVF file to a vCloud catalog
:param media_file_name: (str): The name of the local media file to upload.
:return: (bool) True if the media file was successfully uploaded, false otherwise.
"""
os.path.isfile(media_file_name)
statinfo = os.stat(media_file_name)
:param media_file_name: (str): The name of the local media file to upload.
:return: (bool) True if the media file was successfully uploaded, false otherwise.
"""
os.path.isfile(media_file_name)
statinfo = os.stat(media_file_name)
# find a catalog entry where we upload OVF.
# create vApp Template and check the status if vCD able to read OVF it will respond with appropirate
# find a catalog entry where we upload OVF.
# create vApp Template and check the status if vCD able to read OVF it will respond with appropirate
return None
def new_vminstance(self, name=None, description="", start=False, image_id=None, flavor_id=None, net_list={},
return None
def new_vminstance(self, name=None, description="", start=False, image_id=None, flavor_id=None, net_list={},
- vapp_uuid = self.get_vappid(vca.get_vdc(self.tenant_name), name)
- if vapp_uuid is not None:
- return vapp_uuid
+ # vapp_uuid = self.get_vappid(vca.get_vdc(self.tenant_name), name)
+ # if vapp_uuid is not None:
+ # return vapp_uuid
# we check for presence of VDC, Catalog entry and Flavor.
vdc = vca.get_vdc(self.tenant_name)
# we check for presence of VDC, Catalog entry and Flavor.
vdc = vca.get_vdc(self.tenant_name)
primary_net_name = None
if net_list is not None and len(net_list) > 0:
primary_net = net_list[0]
if primary_net is None:
raise vimconn.vimconnUnexpectedResponse("new_vminstance(): Failed network list is empty.".format(name))
primary_net_name = None
if net_list is not None and len(net_list) > 0:
primary_net = net_list[0]
if primary_net is None:
raise vimconn.vimconnUnexpectedResponse("new_vminstance(): Failed network list is empty.".format(name))
# use: 'data', 'bridge', 'mgmt'
# create vApp. Set vcpu and ram based on flavor id.
# use: 'data', 'bridge', 'mgmt'
# create vApp. Set vcpu and ram based on flavor id.
- vapptask = vca.create_vapp(self.tenant_name, name, templateName,
+ vapptask = vca.create_vapp(self.tenant_name, full_name, templateName,
self.get_catalogbyid(image_id, catalogs),
network_name=primary_net_name, # can be None if net_list None
network_mode='bridged',
self.get_catalogbyid(image_id, catalogs),
network_name=primary_net_name, # can be None if net_list None
network_mode='bridged',
vm_cpus=vm_cpus, # can be None if flavor is None
vm_memory=vm_memory) # can be None if flavor is None
if vapptask is None or vapptask is False:
vm_cpus=vm_cpus, # can be None if flavor is None
vm_memory=vm_memory) # can be None if flavor is None
if vapptask is None or vapptask is False:
if type(vapptask) is VappTask:
vca.block_until_completed(vapptask)
# we should have now vapp in undeployed state.
if type(vapptask) is VappTask:
vca.block_until_completed(vapptask)
# we should have now vapp in undeployed state.
vca.block_until_completed(deploytask)
# check if vApp deployed and if that the case return vApp UUID otherwise -1
vca.block_until_completed(deploytask)
# check if vApp deployed and if that the case return vApp UUID otherwise -1
- vm_dict = {'status': None, 'error_msg': None, 'vim_info': None, 'interfaces': []}
- vm_dict['status'] = vcdStatusCode2manoFormat[the_vapp.me.get_status()]
- vm_dict['error_msg'] = vcdStatusCode2manoFormat[the_vapp.me.get_status()]
- vm_dict['vim_info'] = yaml.safe_dump(the_vapp.get_vms_details())
+ vm_dict = {'status': vcdStatusCode2manoFormat[the_vapp.me.get_status()],
+ 'error_msg': vcdStatusCode2manoFormat[the_vapp.me.get_status()],
+ 'vim_info': yaml.safe_dump(the_vapp.get_vms_details()), 'interfaces': []}
for vapp_network in vm_app_networks:
for vm_network in vapp_network:
if vm_network['name'] == vmname:
for vapp_network in vm_app_networks:
for vm_network in vapp_network:
if vm_network['name'] == vmname:
+ interface = {"mac_address": vm_network['mac'],
+ "vim_net_id": self.get_network_name_by_id(vm_network['network_name']),
+ "vim_interface_id": vm_network['network_name'],
+ 'ip_address': vm_network['ip']}
- interface["mac_address"] = vm_network['mac']
- interface["vim_net_id"] = self.get_network_name_by_id(vm_network['network_name'])
- interface["vim_interface_id"] = vm_network['network_name']
- interface['ip_address'] = vm_network['ip']
vm_dict["interfaces"].append(interface)
# add a vm to vm dict
vms_dict.setdefault(vmuuid, vm_dict)
vm_dict["interfaces"].append(interface)
# add a vm to vm dict
vms_dict.setdefault(vmuuid, vm_dict)
# NOT USED METHODS in current version
def host_vim2gui(self, host, server_dict):
# NOT USED METHODS in current version
def host_vim2gui(self, host, server_dict):
raise vimconn.vimconnNotImplemented("Should have implemented this")
def get_hosts(self, vim_tenant):
raise vimconn.vimconnNotImplemented("Should have implemented this")
def get_hosts(self, vim_tenant):
raise vimconn.vimconnNotImplemented("Should have implemented this")
def get_processor_rankings(self):
raise vimconn.vimconnNotImplemented("Should have implemented this")
def get_processor_rankings(self):
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_host(self, host_data):
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_host(self, host_data):
'''Returns status code of the VIM response'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_external_port(self, port_data):
'''Returns status code of the VIM response'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_external_port(self, port_data):
'''Returns the port identifier'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_external_network(self, net_name, net_type):
'''Returns the port identifier'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_external_network(self, net_name, net_type):
'''Returns the network identifier'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def connect_port_network(self, port_id, network_id, admin=False):
'''Returns the network identifier'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def connect_port_network(self, port_id, network_id, admin=False):
'''Returns status code of the VIM response'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_vminstancefromJSON(self, vm_data):
'''Returns status code of the VIM response'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
def new_vminstancefromJSON(self, vm_data):
'''Returns the instance identifier'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
'''Returns the instance identifier'''
raise vimconn.vimconnNotImplemented("Should have implemented this")
- content = self.create_network_rest(network_name=network_name,
+ new_network_name = [network_name, '-', str(uuid.uuid4())]
+ content = self.create_network_rest(network_name=''.join(new_network_name),
parsed_respond['created'] = created_section.text
network_section = xmlroot_respond.find('vm:NetworkConfigSection/vm:NetworkConfig', namespace_vm)
parsed_respond['created'] = created_section.text
network_section = xmlroot_respond.find('vm:NetworkConfigSection/vm:NetworkConfig', namespace_vm)
if link.attrib['rel'] == 'screen:acquireTicket':
parsed_respond['acquireTicket'] = link.attrib
if link.attrib['rel'] == 'screen:acquireMksTicket':
if link.attrib['rel'] == 'screen:acquireTicket':
parsed_respond['acquireTicket'] = link.attrib
if link.attrib['rel'] == 'screen:acquireMksTicket':