Features 5648 5650 5651
[osm/RO.git] / osm_ro / vimconn_vmware.py
index f99ef65..9c26574 100644 (file)
@@ -671,6 +671,9 @@ class vimconnector(vimconn.vimconnector):
             networks = self.vca.get_networks(vdc.get_name())
             filter_dict = {}
 
             networks = self.vca.get_networks(vdc.get_name())
             filter_dict = {}
 
+            if not networks:
+                vimconn.vimconnNotFoundException("Network {} not found".format(net_id))
+
             for network in networks:
                 vdc_network_id = network.get_id().split(":")
                 if len(vdc_network_id) == 4 and vdc_network_id[3] == net_id:
             for network in networks:
                 vdc_network_id = network.get_id().split(":")
                 if len(vdc_network_id) == 4 and vdc_network_id[3] == net_id:
@@ -686,9 +689,16 @@ class vimconnector(vimconn.vimconnector):
                     filter_dict["type"] = "bridge"
                     self.logger.debug("Returning {}".format(filter_dict))
                     return filter_dict
                     filter_dict["type"] = "bridge"
                     self.logger.debug("Returning {}".format(filter_dict))
                     return filter_dict
-        except:
+            else:
+                raise vimconn.vimconnNotFoundException("Network {} not found".format(net_id))
+
+        except Exception as e:
             self.logger.debug("Error in get_network")
             self.logger.debug(traceback.format_exc())
             self.logger.debug("Error in get_network")
             self.logger.debug(traceback.format_exc())
+            if isinstance(e, vimconn.vimconnException):
+                raise
+            else:
+                raise vimconn.vimconnNotFoundException("Failed : Network not found {} ".format(e))
 
         return filter_dict
 
 
         return filter_dict
 
@@ -791,7 +801,7 @@ class vimconnector(vimconn.vimconnector):
         new_flavor=flavor_data
         ram = flavor_data.get(FLAVOR_RAM_KEY, 1024)
         cpu = flavor_data.get(FLAVOR_VCPUS_KEY, 1)
         new_flavor=flavor_data
         ram = flavor_data.get(FLAVOR_RAM_KEY, 1024)
         cpu = flavor_data.get(FLAVOR_VCPUS_KEY, 1)
-        disk = flavor_data.get(FLAVOR_DISK_KEY, 1)
+        disk = flavor_data.get(FLAVOR_DISK_KEY, 0)
 
         if not isinstance(ram, int):
             raise vimconn.vimconnException("Non-integer value for ram")
 
         if not isinstance(ram, int):
             raise vimconn.vimconnException("Non-integer value for ram")
@@ -1388,9 +1398,9 @@ class vimconnector(vimconn.vimconnector):
                     the VLAN tag to be used. In case net_id is provided, the internal network vlan is used for tagging VF
                 'type': (mandatory) can be one of:
                     'virtual', in this case always connected to a network of type 'net_type=bridge'
                     the VLAN tag to be used. In case net_id is provided, the internal network vlan is used for tagging VF
                 'type': (mandatory) can be one of:
                     'virtual', in this case always connected to a network of type 'net_type=bridge'
-                     'PF' (passthrough): depending on VIM capabilities it can be connected to a data/ptp network ot it
+                     'PCI-PASSTHROUGH' or 'PF' (passthrough): depending on VIM capabilities it can be connected to a data/ptp network ot it
                            can created unconnected
                            can created unconnected
-                     'VF' (SRIOV with VLAN tag): same as PF for network connectivity.
+                     'SR-IOV' or 'VF' (SRIOV with VLAN tag): same as PF for network connectivity.
                      'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs
                             are allocated on the same physical NIC
                 'bw': (optional) only for PF/VF/VFnotShared. Minimal Bandwidth required for the interface in GBPS
                      'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs
                             are allocated on the same physical NIC
                 'bw': (optional) only for PF/VF/VFnotShared. Minimal Bandwidth required for the interface in GBPS
@@ -1564,9 +1574,9 @@ class vimconnector(vimconn.vimconnector):
         reserve_memory = False
 
         for net in net_list:
         reserve_memory = False
 
         for net in net_list:
-            if net["type"]=="PF":
+            if net["type"] == "PF" or net["type"] == "PCI-PASSTHROUGH":
                 pci_devices_info.append(net)
                 pci_devices_info.append(net)
-            elif  (net["type"]=="VF" or  net["type"]=="VFnotShared") and 'net_id'in net:
+            elif (net["type"] == "VF" or net["type"] == "SR-IOV" or net["type"] == "VFnotShared") and 'net_id'in net:
                 sriov_net_info.append(net)
 
         #Add PCI
                 sriov_net_info.append(net)
 
         #Add PCI
@@ -1670,11 +1680,15 @@ class vimconnector(vimconn.vimconnector):
                             self.vca.block_until_completed(task)
                         # connect network to VM - with all DHCP by default
 
                             self.vca.block_until_completed(task)
                         # connect network to VM - with all DHCP by default
 
-                        type_list = ['PF','VF','VFnotShared']
+                        type_list = ('PF', 'PCI-PASSTHROUGH', 'VF', 'SR-IOV', 'VFnotShared')
                         if 'type' in net and net['type'] not in type_list:
                             # fetching nic type from vnf
                             if 'model' in net:
                         if 'type' in net and net['type'] not in type_list:
                             # fetching nic type from vnf
                             if 'model' in net:
-                                nic_type = net['model']
+                                if net['model'].lower() == 'virtio':
+                                    nic_type = 'VMXNET3'
+                                else:
+                                    nic_type = net['model']
+
                                 self.logger.info("new_vminstance(): adding network adapter "\
                                                           "to a network {}".format(nets[0].name))
                                 self.add_network_adapter_to_vms(vapp, nets[0].name,
                                 self.logger.info("new_vminstance(): adding network adapter "\
                                                           "to a network {}".format(nets[0].name))
                                 self.add_network_adapter_to_vms(vapp, nets[0].name,
@@ -4008,39 +4022,31 @@ class vimconnector(vimconn.vimconnector):
                 return if True
         """
         try:
                 return if True
         """
         try:
-            vm_moref_id , vm_vcenter_host , vm_vcenter_username, vm_vcenter_port = self.get_vcenter_info_rest(vmuuid)
-            if vm_moref_id and vm_vcenter_host and vm_vcenter_username:
-                context = None
-                if hasattr(ssl, '_create_unverified_context'):
-                    context = ssl._create_unverified_context()
-                    vcenter_conect = SmartConnect(host=vm_vcenter_host, user=vm_vcenter_username,
-                                  pwd=self.passwd, port=int(vm_vcenter_port),
-                                  sslContext=context)
-                    atexit.register(Disconnect, vcenter_conect)
-                    content = vcenter_conect.RetrieveContent()
-
-                    host_obj, vm_obj = self.get_vm_obj(content ,vm_moref_id)
-                    if vm_obj:
-                        config_spec = vim.vm.ConfigSpec()
-                        config_spec.extraConfig = []
-                        opt = vim.option.OptionValue()
-                        opt.key = 'numa.nodeAffinity'
-                        opt.value = str(paired_threads_id)
-                        config_spec.extraConfig.append(opt)
-                        task = vm_obj.ReconfigVM_Task(config_spec)
-                        if task:
-                            result = self.wait_for_vcenter_task(task, vcenter_conect)
-                            extra_config = vm_obj.config.extraConfig
-                            flag = False
-                            for opts in extra_config:
-                                if 'numa.nodeAffinity' in opts.key:
-                                    flag = True
-                                    self.logger.info("set_numa_affinity: Sucessfully assign numa affinity "\
-                                                             "value {} for vm {}".format(opt.value, vm_obj))
-                            if flag:
-                                return
-                    else:
-                        self.logger.error("set_numa_affinity: Failed to assign numa affinity")
+            vcenter_conect, content = self.get_vcenter_content()
+            vm_moref_id = self.get_vm_moref_id(vmuuid)
+
+            host_obj, vm_obj = self.get_vm_obj(content ,vm_moref_id)
+            if vm_obj:
+                config_spec = vim.vm.ConfigSpec()
+                config_spec.extraConfig = []
+                opt = vim.option.OptionValue()
+                opt.key = 'numa.nodeAffinity'
+                opt.value = str(paired_threads_id)
+                config_spec.extraConfig.append(opt)
+                task = vm_obj.ReconfigVM_Task(config_spec)
+                if task:
+                    result = self.wait_for_vcenter_task(task, vcenter_conect)
+                    extra_config = vm_obj.config.extraConfig
+                    flag = False
+                    for opts in extra_config:
+                        if 'numa.nodeAffinity' in opts.key:
+                            flag = True
+                            self.logger.info("set_numa_affinity: Sucessfully assign numa affinity "\
+                                                     "value {} for vm {}".format(opt.value, vm_obj))
+                        if flag:
+                            return
+            else:
+                self.logger.error("set_numa_affinity: Failed to assign numa affinity")
         except Exception as exp:
             self.logger.error("set_numa_affinity : exception occurred while setting numa affinity "\
                                                        "for VM {} : {}".format(vm_obj, vm_moref_id))
         except Exception as exp:
             self.logger.error("set_numa_affinity : exception occurred while setting numa affinity "\
                                                        "for VM {} : {}".format(vm_obj, vm_moref_id))
@@ -4637,7 +4643,7 @@ class vimconnector(vimconn.vimconnector):
                             for sriov_net in sriov_nets:
                                 network_name = sriov_net.get('net_id')
                                 dvs_portgr_name = self.create_dvPort_group(network_name)
                             for sriov_net in sriov_nets:
                                 network_name = sriov_net.get('net_id')
                                 dvs_portgr_name = self.create_dvPort_group(network_name)
-                                if sriov_net.get('type') == "VF":
+                                if sriov_net.get('type') == "VF" or sriov_net.get('type') == "SR-IOV":
                                     #add vlan ID ,Modify portgroup for vlan ID
                                     self.configure_vlanID(content, vcenter_conect, network_name)
 
                                     #add vlan ID ,Modify portgroup for vlan ID
                                     self.configure_vlanID(content, vcenter_conect, network_name)