- return sriovInfo
-
- def get_host_and_sriov_devices(self, content, no_of_vfs):
- """
- Method to get the details of SRIOV devices infromation on all hosts
-
- Args:
- content - vSphere host object
- no_of_vfs - number of pci VFs needed on host
-
- Returns:
- array of SRIOV devices and host object
- """
- host_obj = None
- sriov_device_objs = None
- try:
- if content:
- container = content.viewManager.CreateContainerView(content.rootFolder,
- [vim.HostSystem], True)
- for host in container.view:
- devices = self.get_sriov_devices(host, no_of_vfs)
- if devices:
- host_obj = host
- sriov_device_objs = devices
- break
- except Exception as exp:
- self.logger.error("Error {} occurred while finding SRIOV devices on host: {}".format(exp, host_obj))
-
- return host_obj, sriov_device_objs
-
- def add_sriov_to_vm(self, content, vm_obj, host_obj, network_name, sriov_device):
- """
- Method to add SRIOV adapter to vm
-
- Args:
- host_obj - vSphere host object
- vm_obj - vSphere vm object
- content - vCenter content object
- network_name - name of distributed virtaul portgroup
- sriov_device - SRIOV device info
-
- Returns:
- task object
- """
- devices = []
- vnic_label = "sriov nic"
- try:
- dvs_portgr = self.get_dvport_group(network_name)
- network_name = dvs_portgr.name
- nic = vim.vm.device.VirtualDeviceSpec()
- # VM device
- nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
- nic.device = vim.vm.device.VirtualSriovEthernetCard()
- nic.device.addressType = 'assigned'
- # nic.device.key = 13016
- nic.device.deviceInfo = vim.Description()
- nic.device.deviceInfo.label = vnic_label
- nic.device.deviceInfo.summary = network_name
- nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
-
- nic.device.backing.network = self.get_obj(content, [vim.Network], network_name)
- nic.device.backing.deviceName = network_name
- nic.device.backing.useAutoDetect = False
- nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
- nic.device.connectable.startConnected = True
- nic.device.connectable.allowGuestControl = True
-
- nic.device.sriovBacking = vim.vm.device.VirtualSriovEthernetCard.SriovBackingInfo()
- nic.device.sriovBacking.physicalFunctionBacking = vim.vm.device.VirtualPCIPassthrough.DeviceBackingInfo()
- nic.device.sriovBacking.physicalFunctionBacking.id = sriov_device.id
-
- devices.append(nic)
- vmconf = vim.vm.ConfigSpec(deviceChange=devices)
- task = vm_obj.ReconfigVM_Task(vmconf)
- return task
- except Exception as exp:
- self.logger.error("Error {} occurred while adding SRIOV adapter in VM: {}".format(exp, vm_obj))
- return None
-
- def create_dvPort_group(self, network_name):
- """
- Method to create disributed virtual portgroup
-
- Args:
- network_name - name of network/portgroup
-
- Returns:
- portgroup key
- """
- try:
- new_network_name = [network_name, '-', str(uuid.uuid4())]
- network_name = ''.join(new_network_name)
- vcenter_conect, content = self.get_vcenter_content()
-
- dv_switch = self.get_obj(content, [vim.DistributedVirtualSwitch], self.dvs_name)
- if dv_switch:
- dv_pg_spec = vim.dvs.DistributedVirtualPortgroup.ConfigSpec()
- dv_pg_spec.name = network_name
-
- dv_pg_spec.type = vim.dvs.DistributedVirtualPortgroup.PortgroupType.earlyBinding
- dv_pg_spec.defaultPortConfig = vim.dvs.VmwareDistributedVirtualSwitch.VmwarePortConfigPolicy()
- dv_pg_spec.defaultPortConfig.securityPolicy = vim.dvs.VmwareDistributedVirtualSwitch.SecurityPolicy()
- dv_pg_spec.defaultPortConfig.securityPolicy.allowPromiscuous = vim.BoolPolicy(value=False)
- dv_pg_spec.defaultPortConfig.securityPolicy.forgedTransmits = vim.BoolPolicy(value=False)
- dv_pg_spec.defaultPortConfig.securityPolicy.macChanges = vim.BoolPolicy(value=False)
-
- task = dv_switch.AddDVPortgroup_Task([dv_pg_spec])
- self.wait_for_vcenter_task(task, vcenter_conect)
-
- dvPort_group = self.get_obj(content, [vim.dvs.DistributedVirtualPortgroup], network_name)
- if dvPort_group:
- self.logger.info("Created disributed virtaul port group: {}".format(dvPort_group))
- return dvPort_group.key
- else:
- self.logger.debug("No disributed virtual switch found with name {}".format(network_name))