Modified refresh_vms_status for multiple IPs and MAC addresses 47/6147/1
authorkasar <pkasar@vmware.com>
Tue, 15 May 2018 13:15:07 +0000 (06:15 -0700)
committerkasar <pkasar@vmware.com>
Tue, 15 May 2018 13:15:18 +0000 (06:15 -0700)
Change-Id: Ia54d0ee3c6305425658578522cd0dee78005280c
Signed-off-by: kasar <pkasar@vmware.com>
osm_ro/vimconn_vmware.py

index 2a8adaf..e24082c 100644 (file)
@@ -2251,27 +2251,32 @@ class vimconnector(vimconn.vimconnector):
                                    'vim_info': yaml.safe_dump(vm_info), 'interfaces': []}
 
                         # get networks
-                        vm_ip = None
-                        vm_mac = None   
-                        if vm.NetworkConnectionSection.NetworkConnection:
-                            vm_mac = vm.NetworkConnectionSection.NetworkConnection.MACAddress
-                        if vm_ip is None:
-                            if not nsx_edge_list:
-                                nsx_edge_list = self.get_edge_details()
-                                if nsx_edge_list is None:
-                                    raise vimconn.vimconnException("refresh_vms_status:"\
-                                                                      "Failed to get edge details from NSX Manager")
-                            if vm_mac is not None:
-                                vm_ip = self.get_ipaddr_from_NSXedge(nsx_edge_list, vm_mac)
-
-                        network_name = vm.NetworkConnectionSection.NetworkConnection.get('network')    
-                        vm_net_id = self.get_network_id_by_name(network_name)
-                        interface = {"mac_address": vm_mac,
-                                     "vim_net_id": vm_net_id,
-                                     "vim_interface_id": vm_net_id,
-                                     'ip_address': vm_ip}
-
-                        vm_dict["interfaces"].append(interface)
+                        vm_ip= None
+                        vm_mac = None
+                        networks = re.findall('<NetworkConnection needsCustomization=.*?</NetworkConnection>',result)
+                        for network in networks:
+                            mac_s = re.search('<MACAddress>(.*?)</MACAddress>',network)
+                            vm_mac = mac_s.group(1) if mac_s else None
+                            ip_s = re.search('<IpAddress>(.*?)</IpAddress>',network)
+                            vm_ip = ip_s.group(1) if ip_s else None
+
+                            if vm_ip is None:
+                                if not nsx_edge_list:
+                                    nsx_edge_list = self.get_edge_details()
+                                    if nsx_edge_list is None:
+                                        raise vimconn.vimconnException("refresh_vms_status:"\
+                                                                       "Failed to get edge details from NSX Manager")
+                                if vm_mac is not None:
+                                    vm_ip = self.get_ipaddr_from_NSXedge(nsx_edge_list, vm_mac)
+
+                            network_name = vm.NetworkConnectionSection.NetworkConnection.get('network')
+                            vm_net_id = self.get_network_id_by_name(network_name)
+                            interface = {"mac_address": vm_mac,
+                                         "vim_net_id": vm_net_id,
+                                         "vim_interface_id": vm_net_id,
+                                         "ip_address": vm_ip}
+
+                            vm_dict["interfaces"].append(interface)
 
                     # add a vm to vm dict
                     vms_dict.setdefault(vmuuid, vm_dict)