+
+ def get_edge_details(self):
+ """Get the NSX edge list from NSX Manager
+ Returns list of NSX edges
+ """
+ edge_list = []
+ rheaders = {'Content-Type': 'application/xml'}
+ nsx_api_url = '/api/4.0/edges'
+
+ self.logger.debug("Get edge details from NSX Manager {} {}".format(self.nsx_manager, nsx_api_url))
+
+ try:
+ resp = requests.get(self.nsx_manager + nsx_api_url,
+ auth = (self.nsx_user, self.nsx_password),
+ verify = False, headers = rheaders)
+ if resp.status_code == requests.codes.ok:
+ paged_Edge_List = XmlElementTree.fromstring(resp.text)
+ for edge_pages in paged_Edge_List:
+ if edge_pages.tag == 'edgePage':
+ for edge_summary in edge_pages:
+ if edge_summary.tag == 'pagingInfo':
+ for element in edge_summary:
+ if element.tag == 'totalCount' and element.text == '0':
+ raise vimconn.vimconnException("get_edge_details: No NSX edges details found: {}"
+ .format(self.nsx_manager))
+
+ if edge_summary.tag == 'edgeSummary':
+ for element in edge_summary:
+ if element.tag == 'id':
+ edge_list.append(element.text)
+ else:
+ raise vimconn.vimconnException("get_edge_details: No NSX edge details found: {}"
+ .format(self.nsx_manager))
+
+ if not edge_list:
+ raise vimconn.vimconnException("get_edge_details: "\
+ "No NSX edge details found: {}"
+ .format(self.nsx_manager))
+ else:
+ self.logger.debug("get_edge_details: Found NSX edges {}".format(edge_list))
+ return edge_list
+ else:
+ self.logger.debug("get_edge_details: "
+ "Failed to get NSX edge details from NSX Manager: {}"
+ .format(resp.content))
+ return None
+
+ except Exception as exp:
+ self.logger.debug("get_edge_details: "\
+ "Failed to get NSX edge details from NSX Manager: {}"
+ .format(exp))
+ raise vimconn.vimconnException("get_edge_details: "\
+ "Failed to get NSX edge details from NSX Manager: {}"
+ .format(exp))
+
+
+ def get_ipaddr_from_NSXedge(self, nsx_edges, mac_address):
+ """Get IP address details from NSX edges, using the MAC address
+ PARAMS: nsx_edges : List of NSX edges
+ mac_address : Find IP address corresponding to this MAC address
+ Returns: IP address corrresponding to the provided MAC address
+ """
+
+ ip_addr = None
+ rheaders = {'Content-Type': 'application/xml'}
+
+ self.logger.debug("get_ipaddr_from_NSXedge: Finding IP addr from NSX edge")
+
+ try:
+ for edge in nsx_edges:
+ nsx_api_url = '/api/4.0/edges/'+ edge +'/dhcp/leaseInfo'
+
+ resp = requests.get(self.nsx_manager + nsx_api_url,
+ auth = (self.nsx_user, self.nsx_password),
+ verify = False, headers = rheaders)
+
+ if resp.status_code == requests.codes.ok:
+ dhcp_leases = XmlElementTree.fromstring(resp.text)
+ for child in dhcp_leases:
+ if child.tag == 'dhcpLeaseInfo':
+ dhcpLeaseInfo = child
+ for leaseInfo in dhcpLeaseInfo:
+ for elem in leaseInfo:
+ if (elem.tag)=='macAddress':
+ edge_mac_addr = elem.text
+ if (elem.tag)=='ipAddress':
+ ip_addr = elem.text
+ if edge_mac_addr is not None:
+ if edge_mac_addr == mac_address:
+ self.logger.debug("Found ip addr {} for mac {} at NSX edge {}"
+ .format(ip_addr, mac_address,edge))
+ return ip_addr
+ else:
+ self.logger.debug("get_ipaddr_from_NSXedge: "\
+ "Error occurred while getting DHCP lease info from NSX Manager: {}"
+ .format(resp.content))
+
+ self.logger.debug("get_ipaddr_from_NSXedge: No IP addr found in any NSX edge")
+ return None
+
+ except XmlElementTree.ParseError as Err:
+ self.logger.debug("ParseError in response from NSX Manager {}".format(Err.message), exc_info=True)
+
+