Changes in vimconn_vmware.py: Fixed Bug ID 121: VMWARE Connector: Return Nic status... 41/841/2
authorbhangare <sbhangare@vmware.com>
Tue, 27 Dec 2016 09:41:28 +0000 (01:41 -0800)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Sat, 31 Dec 2016 15:47:24 +0000 (16:47 +0100)
Signed-off-by: bhangare <sbhangare@vmware.com>
vimconn_vmware.py

index ef3ada5..27583e0 100644 (file)
@@ -1482,8 +1482,8 @@ class vimconnector(vimconn.vimconnector):
                         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'],
+                                             "vim_net_id": self.get_network_id_by_name(vm_network['network_name']),
+                                             "vim_interface_id": self.get_network_id_by_name(vm_network['network_name']),
                                              'ip_address': vm_network['ip']}
                                 # interface['vim_info'] = yaml.safe_dump(vm_network)
                                 vm_dict["interfaces"].append(interface)
@@ -1643,6 +1643,37 @@ class vimconnector(vimconn.vimconnector):
 
         return None
 
+    def get_network_id_by_name(self, network_name=None):
+        """Method gets vcloud director network uuid based on supplied name.
+
+        Args:
+            network_name: network_name
+        Returns:
+            The return network uuid.
+            network_uuid: network_id
+        """
+
+        vca = self.connect()
+        if not vca:
+            raise vimconn.vimconnConnectionException("self.connect() is failed.")
+
+        if not network_name:
+            self.logger.debug("get_network_id_by_name() : Network name is empty")
+            return None
+
+        try:
+            org_dict = self.get_org(self.org_uuid)
+            if org_dict and 'networks' in org_dict:
+                org_network_dict = org_dict['networks']
+                for net_uuid,net_name in org_network_dict.iteritems():
+                    if net_name == network_name:
+                        return net_uuid
+
+        except KeyError as exp:
+            self.logger.debug("get_network_id_by_name() : KeyError- {} ".format(exp))
+
+        return None
+
     def list_org_action(self):
         """
         Method leverages vCloud director and query for available organization for particular user