+ def get_physical_network_by_name(self, physical_network_name):
+ '''
+ Methos returns uuid of physical network which passed
+ Args:
+ physical_network_name: physical network name
+ Returns:
+ UUID of physical_network_name
+ '''
+ try:
+ client_as_admin = self.connect_as_admin()
+ if not client_as_admin:
+ raise vimconn.vimconnConnectionException("Failed to connect vCD.")
+ url_list = [self.url, '/api/admin/vdc/', self.tenant_id]
+ vm_list_rest_call = ''.join(url_list)
+
+ if client_as_admin._session:
+ headers = {'Accept':'application/*+xml;version=' + API_VERSION,
+ 'x-vcloud-authorization': client_as_admin._session.headers['x-vcloud-authorization']}
+
+ response = self.perform_request(req_type='GET',
+ url=vm_list_rest_call,
+ headers=headers)
+
+ provider_network = None
+ available_network = None
+ add_vdc_rest_url = None
+
+ if response.status_code != requests.codes.ok:
+ self.logger.debug("REST API call {} failed. Return status code {}".format(vm_list_rest_call,
+ response.status_code))
+ return None
+ else:
+ try:
+ vm_list_xmlroot = XmlElementTree.fromstring(response.content)
+ for child in vm_list_xmlroot:
+
+ if child.tag.split("}")[1] == 'ProviderVdcReference':
+ provider_network = child.attrib.get('href')
+ # application/vnd.vmware.admin.providervdc+xml
+ if child.tag.split("}")[1] == 'Link':
+ if child.attrib.get('type') == 'application/vnd.vmware.vcloud.orgVdcNetwork+xml' \
+ and child.attrib.get('rel') == 'add':
+ add_vdc_rest_url = child.attrib.get('href')
+ except:
+ self.logger.debug("Failed parse respond for rest api call {}".format(vm_list_rest_call))
+ self.logger.debug("Respond body {}".format(response.content))
+ return None
+
+ # find pvdc provided available network
+ response = self.perform_request(req_type='GET',
+ url=provider_network,
+ headers=headers)
+
+ if response.status_code != requests.codes.ok:
+ self.logger.debug("REST API call {} failed. Return status code {}".format(vm_list_rest_call,
+ response.status_code))
+ return None
+
+ try:
+ vm_list_xmlroot = XmlElementTree.fromstring(response.content)
+ for child in vm_list_xmlroot.iter():
+ if child.tag.split("}")[1] == 'AvailableNetworks':
+ for networks in child.iter():
+ if networks.attrib.get('href') is not None and networks.attrib.get('name') is not None:
+ if networks.attrib.get('name') == physical_network_name:
+ network_url = networks.attrib.get('href')
+ available_network = network_url[network_url.rindex('/')+1:]
+ break
+ except Exception as e:
+ return None
+
+ return available_network
+ except Exception as e:
+ self.logger.error("Error while getting physical network: {}".format(e))
+