From: bhangare Date: Fri, 3 Feb 2017 10:50:23 +0000 (-0800) Subject: Changes in vimconn_vmware.py : Patch to get DHCP leased addresses for Isolated networ... X-Git-Tag: v1.1.0~6 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=df7e95c60b0ca6d2114848fed1ab496a4f25a627;p=osm%2FRO.git Changes in vimconn_vmware.py : Patch to get DHCP leased addresses for Isolated networks from NSX manager edges Signed-off-by: bhangare --- diff --git a/vimconn_vmware.py b/vimconn_vmware.py index 6e7059c5..3e81f513 100644 --- a/vimconn_vmware.py +++ b/vimconn_vmware.py @@ -1665,28 +1665,33 @@ class vimconnector(vimconn.vimconnector): mac_ip_addr={} rheaders = {'Content-Type': 'application/xml'} + iso_edges = ['edge-2','edge-3','edge-6','edge-7','edge-8','edge-9','edge-10'] try: - resp = requests.get(self.nsx_manager + '/api/4.0/edges/edge-2/dhcp/leaseInfo', - 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': - mac_addr = elem.text - if (elem.tag)=='ipAddress': - ip_addr = elem.text - if (mac_addr) is not None: - mac_ip_addr[mac_addr]= ip_addr - self.logger.debug("NSX Manager DHCP Lease info: mac_ip_addr : {}".format(mac_ip_addr)) - else: - self.logger.debug("Error occurred while getting DHCP lease info from NSX Manager: {}".format(resp.content)) + for edge in iso_edges: + nsx_api_url = '/api/4.0/edges/'+ edge +'/dhcp/leaseInfo' + self.logger.debug("refresh_vms_status: NSX Manager url: {}".format(nsx_api_url)) + + 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': + mac_addr = elem.text + if (elem.tag)=='ipAddress': + ip_addr = elem.text + if (mac_addr) is not None: + mac_ip_addr[mac_addr]= ip_addr + self.logger.debug("NSX Manager DHCP Lease info: mac_ip_addr : {}".format(mac_ip_addr)) + else: + self.logger.debug("Error occurred while getting DHCP lease info from NSX Manager: {}".format(resp.content)) except KeyError: self.logger.debug("Error in response from NSX Manager {}".format(KeyError.message)) self.logger.debug(traceback.format_exc())