Пример #1
0
    def _test_get_element_associated_class(self, fields=None):
        mock_conn = mock.MagicMock()
        _wqlutils.get_element_associated_class(
            mock_conn, mock.sentinel.class_name,
            element_instance_id=mock.sentinel.instance_id,
            fields=fields)

        expected_fields = ", ".join(fields) if fields else '*'
        expected_query = (
            "SELECT %(expected_fields)s FROM %(class_name)s "
            "WHERE InstanceID LIKE '%(instance_id)s%%'" %
            {'expected_fields': expected_fields,
             'class_name': mock.sentinel.class_name,
             'instance_id': mock.sentinel.instance_id})
        mock_conn.query.assert_called_once_with(expected_query)
Пример #2
0
    def _test_get_element_associated_class(self, fields=None):
        mock_conn = mock.MagicMock()
        _wqlutils.get_element_associated_class(
            mock_conn, mock.sentinel.class_name,
            element_instance_id=mock.sentinel.instance_id,
            fields=fields)

        expected_fields = ", ".join(fields) if fields else '*'
        expected_query = (
            "SELECT %(expected_fields)s FROM %(class_name)s "
            "WHERE InstanceID LIKE '%(instance_id)s%%'" %
            {'expected_fields': expected_fields,
             'class_name': mock.sentinel.class_name,
             'instance_id': mock.sentinel.instance_id})
        mock_conn.query.assert_called_once_with(expected_query)
Пример #3
0
    def _update_planned_vm_disk_resources(self, conn_v2_local, planned_vm,
                                          vm_name, disk_paths_remote):
        updated_resource_setting_data = []
        sasds = _wqlutils.get_element_associated_class(
            self._compat_conn,
            self._CIM_RES_ALLOC_SETTING_DATA_CLASS,
            element_uuid=planned_vm.Name)
        for sasd in sasds:
            if (sasd.ResourceType == 17 and sasd.ResourceSubType
                    == "Microsoft:Hyper-V:Physical Disk Drive"
                    and sasd.HostResource):
                # Replace the local disk target with the correct remote one
                old_disk_path = sasd.HostResource[0]
                new_disk_path = disk_paths_remote.pop(sasd.path().RelPath)

                LOG.debug(
                    "Replacing host resource "
                    "%(old_disk_path)s with "
                    "%(new_disk_path)s on planned VM %(vm_name)s", {
                        'old_disk_path': old_disk_path,
                        'new_disk_path': new_disk_path,
                        'vm_name': vm_name
                    })
                sasd.HostResource = [new_disk_path]
                updated_resource_setting_data.append(sasd.GetText_(1))

        LOG.debug("Updating remote planned VM disk paths for VM: %s", vm_name)
        vsmsvc = conn_v2_local.Msvm_VirtualSystemManagementService()[0]
        (res_settings, job_path, ret_val) = vsmsvc.ModifyResourceSettings(
            ResourceSettings=updated_resource_setting_data)
        self._jobutils.check_ret_val(ret_val, job_path)
Пример #4
0
    def _bind_security_rules(self, port, sg_rules):
        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)

        # Add the ACL only if it don't already exist.
        add_acls = []
        processed_sg_rules = []
        weights = self._get_new_weights(sg_rules, acls)
        index = 0

        for sg_rule in sg_rules:
            filtered_acls = self._filter_security_acls(sg_rule, acls)
            if filtered_acls:
                # ACL already exists.
                continue

            acl = self._create_security_acl(sg_rule, weights[index])
            add_acls.append(acl)
            index += 1

            # append sg_rule the acls list, to make sure that the same rule
            # is not processed twice.
            processed_sg_rules.append(sg_rule)

        if add_acls:
            self._jobutils.add_multiple_virt_features(add_acls, port)

            # caching the Security Group Rules that have been processed and
            # added to the port. The list should only be used to check the
            # existence of rules, nothing else.
            acls.extend(processed_sg_rules)
Пример #5
0
    def remove_pci_device(self, vm_name, vendor_id, product_id):
        """Removes the given PCI device from the given VM.

        :param vm_name: the name of the VM from which the PCI device will be
            attached from.
        :param vendor_id: the PCI device's vendor ID.
        :param product_id: the PCI device's product ID.
        """
        vmsettings = self._lookup_vm_check(vm_name)

        pattern = re.compile(
            "^(.*)VEN_%(vendor_id)s&DEV_%(product_id)s&(.*)$" % {
                'vendor_id': vendor_id, 'product_id': product_id})

        pci_sds = _wqlutils.get_element_associated_class(
            self._conn, self._PCI_EXPRESS_SETTING_DATA,
            vmsettings.InstanceID)
        pci_sds = [sd for sd in pci_sds if pattern.match(sd.HostResource[0])]

        if pci_sds:
            self._jobutils.remove_virt_resource(pci_sds[0])
        else:
            LOG.debug("PCI device with vendor ID %(vendor_id)s and "
                      "%(product_id)s is not attached to %(vm_name)s",
                      {'vendor_id': vendor_id, 'product_id': product_id,
                       'vm_name': vm_name})
Пример #6
0
    def _bind_security_rules(self, port, sg_rules):
        acls = _wqlutils.get_element_associated_class(
            self._conn,
            self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)

        # Add the ACL only if it don't already exist.
        add_acls = []
        processed_sg_rules = []
        weights = self._get_new_weights(sg_rules, acls)
        index = 0

        for sg_rule in sg_rules:
            filtered_acls = self._filter_security_acls(sg_rule, acls)
            if filtered_acls:
                # ACL already exists.
                continue

            acl = self._create_security_acl(sg_rule, weights[index])
            add_acls.append(acl)
            index += 1

            # append sg_rule the acls list, to make sure that the same rule
            # is not processed twice.
            processed_sg_rules.append(sg_rule)

        if add_acls:
            self._jobutils.add_multiple_virt_features(add_acls, port)

            # caching the Security Group Rules that have been processed and
            # added to the port. The list should only be used to check the
            # existence of rules, nothing else.
            acls.extend(processed_sg_rules)
Пример #7
0
    def add_vtpm(self, vm_name, pdk_filepath, shielded):
        """Adds a vtpm and enables it with encryption or shielded option."""

        vm = self._lookup_vm_check(vm_name)

        msps_pfp = self._conn_msps.Msps_ProvisioningFileProcessor
        provisioning_file = msps_pfp.PopulateFromFile(pdk_filepath)[0]
        # key_protector: array of bytes
        key_protector = provisioning_file.KeyProtector
        # policy_data: array of bytes
        policy_data = provisioning_file.PolicyData

        security_profile = _wqlutils.get_element_associated_class(
            self._conn, self._SECURITY_SETTING_DATA,
            element_uuid=vm.ConfigurationID)[0]

        security_profile.EncryptStateAndVmMigrationTraffic = True
        security_profile.TpmEnabled = True
        security_profile.ShieldingRequested = shielded

        sec_profile_serialized = security_profile.GetText_(1)
        (job_path, ret_val) = self._sec_svc.SetKeyProtector(
            key_protector, sec_profile_serialized)
        self._jobutils.check_ret_val(ret_val, job_path)

        (job_path, ret_val) = self._sec_svc.SetSecurityPolicy(
            policy_data, sec_profile_serialized)
        self._jobutils.check_ret_val(ret_val, job_path)

        (job_path, ret_val) = self._sec_svc.ModifySecuritySettings(
            sec_profile_serialized)
        self._jobutils.check_ret_val(ret_val, job_path)
Пример #8
0
    def _update_planned_vm_disk_resources(self, conn_v2_local,
                                          planned_vm, vm_name,
                                          disk_paths_remote):
        updated_resource_setting_data = []
        sasds = _wqlutils.get_element_associated_class(
            self._compat_conn, self._CIM_RES_ALLOC_SETTING_DATA_CLASS,
            element_uuid=planned_vm.Name)
        for sasd in sasds:
            if (sasd.ResourceType == 17 and sasd.ResourceSubType ==
                    "Microsoft:Hyper-V:Physical Disk Drive" and
                    sasd.HostResource):
                # Replace the local disk target with the correct remote one
                old_disk_path = sasd.HostResource[0]
                new_disk_path = disk_paths_remote.pop(sasd.path().RelPath)

                LOG.debug("Replacing host resource "
                          "%(old_disk_path)s with "
                          "%(new_disk_path)s on planned VM %(vm_name)s",
                          {'old_disk_path': old_disk_path,
                           'new_disk_path': new_disk_path,
                           'vm_name': vm_name})
                sasd.HostResource = [new_disk_path]
                updated_resource_setting_data.append(sasd.GetText_(1))

        LOG.debug("Updating remote planned VM disk paths for VM: %s",
                  vm_name)
        vsmsvc = conn_v2_local.Msvm_VirtualSystemManagementService()[0]
        (res_settings, job_path, ret_val) = vsmsvc.ModifyResourceSettings(
            ResourceSettings=updated_resource_setting_data)
        self._jobutils.check_ret_val(ret_val, job_path)
Пример #9
0
    def _set_vm_memory(self, vmsetting, memory_mb, memory_per_numa_node,
                       dynamic_memory_ratio):
        mem_settings = _wqlutils.get_element_associated_class(
            self._conn, self._MEMORY_SETTING_DATA_CLASS,
            element_instance_id=vmsetting.InstanceID)[0]

        max_mem = int(memory_mb)
        mem_settings.Limit = max_mem

        if dynamic_memory_ratio > 1:
            mem_settings.DynamicMemoryEnabled = True
            # Must be a multiple of 2
            reserved_mem = min(
                int(max_mem / dynamic_memory_ratio) >> 1 << 1,
                max_mem)
        else:
            mem_settings.DynamicMemoryEnabled = False
            reserved_mem = max_mem

        mem_settings.Reservation = reserved_mem
        # Start with the minimum memory
        mem_settings.VirtualQuantity = reserved_mem

        if memory_per_numa_node:
            # One memory block is 1 MB.
            mem_settings.MaxMemoryBlocksPerNumaNode = memory_per_numa_node

        self._jobutils.modify_virt_resource(mem_settings)
Пример #10
0
 def is_secure_vm(self, instance_name):
     inst_id = self.get_vm_id(instance_name)
     security_profile = _wqlutils.get_element_associated_class(
         self._conn, self._SECURITY_SETTING_DATA, element_uuid=inst_id)
     if security_profile:
         return security_profile[0].EncryptStateAndVmMigrationTraffic
     return False
Пример #11
0
    def _set_vm_memory(self, vmsetting, memory_mb, memory_per_numa_node,
                       dynamic_memory_ratio):
        mem_settings = _wqlutils.get_element_associated_class(
            self._compat_conn,
            self._MEMORY_SETTING_DATA_CLASS,
            element_instance_id=vmsetting.InstanceID)[0]

        max_mem = int(memory_mb)
        mem_settings.Limit = max_mem

        if dynamic_memory_ratio > 1:
            mem_settings.DynamicMemoryEnabled = True
            # Must be a multiple of 2
            reserved_mem = min(
                int(max_mem / dynamic_memory_ratio) >> 1 << 1, max_mem)
        else:
            mem_settings.DynamicMemoryEnabled = False
            reserved_mem = max_mem

        mem_settings.Reservation = reserved_mem
        # Start with the minimum memory
        mem_settings.VirtualQuantity = reserved_mem

        if memory_per_numa_node:
            # One memory block is 1 MB.
            mem_settings.MaxMemoryBlocksPerNumaNode = memory_per_numa_node

        self._jobutils.modify_virt_resource(mem_settings)
Пример #12
0
    def get_vnic_metrics(self, vm_name):
        ports = self._get_vm_resources(vm_name, self._PORT_ALLOC_SET_DATA)
        vnics = self._get_vm_resources(vm_name, self._SYNTH_ETH_PORT_SET_DATA)

        metrics_def_in = self._metrics_defs[self._NET_IN_METRICS]
        metrics_def_out = self._metrics_defs[self._NET_OUT_METRICS]

        for port in ports:
            vnic = [v for v in vnics if port.Parent == v.path_()][0]
            port_acls = _wqlutils.get_element_associated_class(
                self._conn,
                self._PORT_ALLOC_ACL_SET_DATA,
                element_instance_id=port.InstanceID)

            metrics_value_instances = self._get_metrics_value_instances(
                port_acls, self._BASE_METRICS_VALUE)
            metrics_values = self._sum_metrics_values_by_defs(
                metrics_value_instances, [metrics_def_in, metrics_def_out])

            yield {
                'rx_mb': metrics_values[0],
                'tx_mb': metrics_values[1],
                'element_name': vnic.ElementName,
                'address': vnic.Address
            }
Пример #13
0
    def enable_remotefx_video_adapter(self, vm_name, monitor_count,
                                      max_resolution, vram_bytes=None):
        vm = self._lookup_vm_check(vm_name, as_vssd=False)

        self._validate_remotefx_params(monitor_count, max_resolution,
                                       vram_bytes=vram_bytes)

        rasds = _wqlutils.get_element_associated_class(
            self._conn, self._CIM_RES_ALLOC_SETTING_DATA_CLASS,
            element_uuid=vm.Name)
        if [r for r in rasds if r.ResourceSubType ==
                self._SYNTH_3D_DISP_CTRL_RES_SUB_TYPE]:
            raise exceptions.HyperVRemoteFXException(
                _("RemoteFX is already configured for this VM"))

        synth_disp_ctrl_res_list = [r for r in rasds if r.ResourceSubType ==
                                    self._SYNTH_DISP_CTRL_RES_SUB_TYPE]
        if synth_disp_ctrl_res_list:
            self._jobutils.remove_virt_resource(synth_disp_ctrl_res_list[0])

        max_res_value = self._remote_fx_res_map.get(max_resolution)
        self._add_3d_display_controller(vm, monitor_count, max_res_value,
                                        vram_bytes)
        if self._vm_has_s3_controller(vm.ElementName):
            s3_disp_ctrl_res = [r for r in rasds if r.ResourceSubType ==
                                self._S3_DISP_CTRL_RES_SUB_TYPE][0]
            s3_disp_ctrl_res.Address = self._DISP_CTRL_ADDRESS_DX_11
            self._jobutils.modify_virt_resource(s3_disp_ctrl_res)
Пример #14
0
 def _get_vm_scsi_controller(self, vmsettings):
     rasds = _wqlutils.get_element_associated_class(
         self._conn, self._RESOURCE_ALLOC_SETTING_DATA_CLASS,
         element_instance_id=vmsettings.InstanceID)
     res = [r for r in rasds
            if r.ResourceSubType == self._SCSI_CTRL_RES_SUB_TYPE][0]
     return res.path_()
Пример #15
0
    def add_vtpm(self, vm_name, pdk_filepath, shielded):
        """Adds a vtpm and enables it with encryption or shielded option."""

        vm = self._lookup_vm_check(vm_name)

        msps_pfp = self._conn_msps.Msps_ProvisioningFileProcessor
        provisioning_file = msps_pfp.PopulateFromFile(pdk_filepath)[0]
        # key_protector: array of bytes
        key_protector = provisioning_file.KeyProtector
        # policy_data: array of bytes
        policy_data = provisioning_file.PolicyData

        security_profile = _wqlutils.get_element_associated_class(
            self._conn, self._SECURITY_SETTING_DATA,
            element_uuid=vm.ConfigurationID)[0]

        security_profile.EncryptStateAndVmMigrationTraffic = True
        security_profile.TpmEnabled = True
        security_profile.ShieldingRequested = shielded

        sec_profile_serialized = security_profile.GetText_(1)
        (job_path, ret_val) = self._sec_svc.SetKeyProtector(
            key_protector, sec_profile_serialized)
        self._jobutils.check_ret_val(ret_val, job_path)

        (job_path, ret_val) = self._sec_svc.SetSecurityPolicy(
            policy_data, sec_profile_serialized)
        self._jobutils.check_ret_val(ret_val, job_path)

        (job_path, ret_val) = self._sec_svc.ModifySecuritySettings(
            sec_profile_serialized)
        self._jobutils.check_ret_val(ret_val, job_path)
Пример #16
0
 def is_secure_vm(self, instance_name):
     inst_id = self.get_vm_id(instance_name)
     security_profile = _wqlutils.get_element_associated_class(
         self._conn, self._SECURITY_SETTING_DATA,
         element_uuid=inst_id)
     if security_profile:
         return security_profile[0].EncryptStateAndVmMigrationTraffic
     return False
Пример #17
0
    def _get_vm_ide_controller(self, vmsettings, ctrller_addr):
        rasds = _wqlutils.get_element_associated_class(
            self._conn, self._RESOURCE_ALLOC_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)
        ide_ctrls = [r for r in rasds
                     if r.ResourceSubType == self._IDE_CTRL_RES_SUB_TYPE
                     and r.Address == str(ctrller_addr)]

        return ide_ctrls[0].path_() if ide_ctrls else None
Пример #18
0
 def _get_vm_serial_ports(self, vmsettings):
     rasds = _wqlutils.get_element_associated_class(
         self._conn, self._SERIAL_PORT_SETTING_DATA_CLASS,
         element_instance_id=vmsettings.InstanceID)
     serial_ports = (
         [r for r in rasds if
          r.ResourceSubType == self._SERIAL_PORT_RES_SUB_TYPE]
     )
     return serial_ports
Пример #19
0
 def _get_vm_serial_ports(self, vmsettings):
     rasds = _wqlutils.get_element_associated_class(
         self._compat_conn,
         self._SERIAL_PORT_SETTING_DATA_CLASS,
         element_instance_id=vmsettings.InstanceID)
     serial_ports = ([
         r for r in rasds
         if r.ResourceSubType == self._SERIAL_PORT_RES_SUB_TYPE
     ])
     return serial_ports
Пример #20
0
    def _get_vm_disks(self, vmsettings):
        rasds = _wqlutils.get_element_associated_class(
            self._conn, self._STORAGE_ALLOC_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)
        disk_resources = [r for r in rasds if
                          r.ResourceSubType in
                          [self._HARD_DISK_RES_SUB_TYPE,
                           self._DVD_DISK_RES_SUB_TYPE]]

        if (self._RESOURCE_ALLOC_SETTING_DATA_CLASS !=
                self._STORAGE_ALLOC_SETTING_DATA_CLASS):
            rasds = _wqlutils.get_element_associated_class(
                self._conn, self._RESOURCE_ALLOC_SETTING_DATA_CLASS,
                element_instance_id=vmsettings.InstanceID)

        volume_resources = [r for r in rasds if
                            r.ResourceSubType == self._PHYS_DISK_RES_SUB_TYPE]

        return (disk_resources, volume_resources)
Пример #21
0
 def _get_vhd_setting_data(self, vm):
     new_resource_setting_data = []
     sasds = _wqlutils.get_element_associated_class(
         self._compat_conn, self._STORAGE_ALLOC_SETTING_DATA_CLASS,
         element_uuid=vm.Name)
     for sasd in sasds:
         if (sasd.ResourceType == 31 and sasd.ResourceSubType ==
                 "Microsoft:Hyper-V:Virtual Hard Disk"):
             new_resource_setting_data.append(sasd.GetText_(1))
     return new_resource_setting_data
Пример #22
0
 def _get_vm_scsi_controller(self, vmsettings):
     rasds = _wqlutils.get_element_associated_class(
         self._conn,
         self._RESOURCE_ALLOC_SETTING_DATA_CLASS,
         element_instance_id=vmsettings.InstanceID)
     res = [
         r for r in rasds
         if r.ResourceSubType == self._SCSI_CTRL_RES_SUB_TYPE
     ][0]
     return res.path_()
Пример #23
0
    def get_vm_dvd_disk_paths(self, vm_name):
        vmsettings = self._lookup_vm_check(vm_name)

        sasds = _wqlutils.get_element_associated_class(
            self._conn, self._STORAGE_ALLOC_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)

        dvd_paths = [sasd.HostResource[0] for sasd in sasds
                     if sasd.ResourceSubType == self._DVD_DISK_RES_SUB_TYPE]

        return dvd_paths
Пример #24
0
    def _get_setting_data_from_port_alloc(self, port_alloc, cache, data_class):
        if port_alloc.InstanceID in cache:
            return cache[port_alloc.InstanceID]

        setting_data = self._get_first_item(
            _wqlutils.get_element_associated_class(
                self._conn, data_class,
                element_instance_id=port_alloc.InstanceID))
        if setting_data:
            cache[port_alloc.InstanceID] = setting_data
        return setting_data
Пример #25
0
    def _get_setting_data_from_port_alloc(self, port_alloc, cache, data_class):
        if port_alloc.InstanceID in cache:
            return cache[port_alloc.InstanceID]

        setting_data = self._get_first_item(
            _wqlutils.get_element_associated_class(
                self._conn, data_class,
                element_instance_id=port_alloc.InstanceID))
        if setting_data:
            cache[port_alloc.InstanceID] = setting_data
        return setting_data
Пример #26
0
    def _get_vm_ide_controller(self, vmsettings, ctrller_addr):
        rasds = _wqlutils.get_element_associated_class(
            self._conn,
            self._RESOURCE_ALLOC_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)
        ide_ctrls = [
            r for r in rasds
            if r.ResourceSubType == self._IDE_CTRL_RES_SUB_TYPE
            and r.Address == str(ctrller_addr)
        ]

        return ide_ctrls[0].path_() if ide_ctrls else None
Пример #27
0
    def remove_all_pci_devices(self, vm_name):
        """Removes all the PCI devices from the given VM.

        :param vm_name: the name of the VM from which all the PCI devices will
            be detached from.
        """
        vmsettings = self._lookup_vm_check(vm_name)

        pci_sds = _wqlutils.get_element_associated_class(
            self._conn, self._PCI_EXPRESS_SETTING_DATA, vmsettings.InstanceID)

        if pci_sds:
            self._jobutils.remove_multiple_virt_resources(pci_sds)
Пример #28
0
    def remove_all_security_rules(self, switch_port_name):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        filtered_acls = [a for a in acls if
                         a.Action is not self._ACL_ACTION_METER]

        if filtered_acls:
            self._jobutils.remove_multiple_virt_features(filtered_acls)

            # clear the cache.
            self._sg_acl_sds[port.ElementName] = []
Пример #29
0
    def is_metrics_collection_allowed(self, switch_port_name):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        if not self._is_port_vm_started(port):
            return False

        # all 4 meter ACLs must be existent first. (2 x direction)
        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_ALLOC_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        acls = [a for a in acls if a.Action == self._ACL_ACTION_METER]
        if len(acls) < 2:
            return False
        return True
Пример #30
0
    def remove_all_security_rules(self, switch_port_name):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        acls = _wqlutils.get_element_associated_class(
            self._conn,
            self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        filtered_acls = [a for a in acls if a.Action != self._ACL_ACTION_METER]

        if filtered_acls:
            self._jobutils.remove_multiple_virt_features(filtered_acls)

            # clear the cache.
            self._sg_acl_sds[port.ElementName] = []
Пример #31
0
    def is_metrics_collection_allowed(self, switch_port_name):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        if not self._is_port_vm_started(port):
            return False

        # all 4 meter ACLs must be existent first. (2 x direction)
        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_ALLOC_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        acls = [a for a in acls if a.Action == self._ACL_ACTION_METER]
        if len(acls) < 2:
            return False
        return True
Пример #32
0
    def get_vm_dvd_disk_paths(self, vm_name):
        vmsettings = self._lookup_vm_check(vm_name)

        sasds = _wqlutils.get_element_associated_class(
            self._conn,
            self._STORAGE_ALLOC_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)

        dvd_paths = [
            sasd.HostResource[0] for sasd in sasds
            if sasd.ResourceSubType == self._DVD_DISK_RES_SUB_TYPE
        ]

        return dvd_paths
Пример #33
0
    def _get_vm_disks(self, vmsettings):
        rasds = _wqlutils.get_element_associated_class(
            self._compat_conn,
            self._STORAGE_ALLOC_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)
        disk_resources = [
            r for r in rasds if r.ResourceSubType in
            [self._HARD_DISK_RES_SUB_TYPE, self._DVD_DISK_RES_SUB_TYPE]
        ]

        if (self._RESOURCE_ALLOC_SETTING_DATA_CLASS !=
                self._STORAGE_ALLOC_SETTING_DATA_CLASS):
            rasds = _wqlutils.get_element_associated_class(
                self._compat_conn,
                self._RESOURCE_ALLOC_SETTING_DATA_CLASS,
                element_instance_id=vmsettings.InstanceID)

        volume_resources = [
            r for r in rasds
            if r.ResourceSubType == self._PHYS_DISK_RES_SUB_TYPE
        ]

        return (disk_resources, volume_resources)
Пример #34
0
    def set_nested_virtualization(self, vm_name, state):
        """Enables nested virtualization for the given VM.

        :param vm_name: the name of the VM.
        :param state: boolean, if True, nested virtualization will be enabled,
            disabled otherwise.
        """
        vmsettings = self._lookup_vm_check(vm_name)
        procsettings = _wqlutils.get_element_associated_class(
            self._conn, self._PROCESSOR_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)[0]

        procsettings.ExposeVirtualizationExtensions = state
        self._jobutils.modify_virt_resource(procsettings)
Пример #35
0
    def add_metrics_collection_acls(self, switch_port_name):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        # Add the ACLs only if they don't already exist
        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_ALLOC_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        for acl_type in [self._ACL_TYPE_IPV4, self._ACL_TYPE_IPV6]:
            for acl_dir in [self._ACL_DIR_IN, self._ACL_DIR_OUT]:
                _acls = self._filter_acls(
                    acls, self._ACL_ACTION_METER, acl_dir, acl_type)

                if not _acls:
                    acl = self._create_acl(
                        acl_dir, acl_type, self._ACL_ACTION_METER)
                    self._jobutils.add_virt_feature(acl, port)
Пример #36
0
    def _get_port_security_acls(self, port):
        """Returns a mutable list of Security Group Rule objects.

        Returns the list of Security Group Rule objects from the cache,
        otherwise it fetches and caches from the port's associated class.
        """

        if port.ElementName in self._sg_acl_sds:
            return self._sg_acl_sds[port.ElementName]

        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        self._sg_acl_sds[port.ElementName] = acls

        return acls
Пример #37
0
    def add_metrics_collection_acls(self, switch_port_name):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        # Add the ACLs only if they don't already exist
        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_ALLOC_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        for acl_type in [self._ACL_TYPE_IPV4, self._ACL_TYPE_IPV6]:
            for acl_dir in [self._ACL_DIR_IN, self._ACL_DIR_OUT]:
                _acls = self._filter_acls(
                    acls, self._ACL_ACTION_METER, acl_dir, acl_type)

                if not _acls:
                    acl = self._create_acl(
                        acl_dir, acl_type, self._ACL_ACTION_METER)
                    self._jobutils.add_virt_feature(acl, port)
Пример #38
0
    def _get_port_security_acls(self, port):
        """Returns a mutable list of Security Group Rule objects.

        Returns the list of Security Group Rule objects from the cache,
        otherwise it fetches and caches from the port's associated class.
        """

        if port.ElementName in self._sg_acl_sds:
            return self._sg_acl_sds[port.ElementName]

        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        self._sg_acl_sds[port.ElementName] = acls

        return acls
Пример #39
0
    def _set_vm_vcpus(self, vmsetting, vcpus_num, vcpus_per_numa_node,
                      limit_cpu_features):
        procsetting = _wqlutils.get_element_associated_class(
            self._conn, self._PROCESSOR_SETTING_DATA_CLASS,
            element_instance_id=vmsetting.InstanceID)[0]

        vcpus = int(vcpus_num)
        procsetting.VirtualQuantity = vcpus
        procsetting.Reservation = vcpus
        procsetting.Limit = 100000  # static assignment to 100%
        procsetting.LimitProcessorFeatures = limit_cpu_features

        if vcpus_per_numa_node:
            procsetting.MaxProcessorsPerNumaNode = vcpus_per_numa_node

        self._jobutils.modify_virt_resource(procsetting)
Пример #40
0
    def remove_security_rules(self, switch_port_name, sg_rules):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        remove_acls = []
        for sg_rule in sg_rules:
            filtered_acls = self._filter_security_acls(sg_rule, acls)
            remove_acls.extend(filtered_acls)

        if remove_acls:
            self._jobutils.remove_multiple_virt_features(remove_acls)

            # remove the old ACLs from the cache.
            new_acls = [a for a in acls if a not in remove_acls]
            self._sg_acl_sds[port.ElementName] = new_acls
Пример #41
0
    def remove_security_rules(self, switch_port_name, sg_rules):
        port = self._get_switch_port_allocation(switch_port_name)[0]

        acls = _wqlutils.get_element_associated_class(
            self._conn, self._PORT_EXT_ACL_SET_DATA,
            element_instance_id=port.InstanceID)
        remove_acls = []
        for sg_rule in sg_rules:
            filtered_acls = self._filter_security_acls(sg_rule, acls)
            remove_acls.extend(filtered_acls)

        if remove_acls:
            self._jobutils.remove_multiple_virt_features(remove_acls)

            # remove the old ACLs from the cache.
            new_acls = [a for a in acls if a not in remove_acls]
            self._sg_acl_sds[port.ElementName] = new_acls
Пример #42
0
    def _set_vm_vcpus(self, vmsetting, vcpus_num, vcpus_per_numa_node,
                      limit_cpu_features):
        procsetting = _wqlutils.get_element_associated_class(
            self._compat_conn,
            self._PROCESSOR_SETTING_DATA_CLASS,
            element_instance_id=vmsetting.InstanceID)[0]

        vcpus = int(vcpus_num)
        procsetting.VirtualQuantity = vcpus
        procsetting.Reservation = vcpus
        procsetting.Limit = 100000  # static assignment to 100%
        procsetting.LimitProcessorFeatures = limit_cpu_features

        if vcpus_per_numa_node:
            procsetting.MaxProcessorsPerNumaNode = vcpus_per_numa_node

        self._jobutils.modify_virt_resource(procsetting)
Пример #43
0
    def get_vm_serial_port_connection(self, vm_name, update_connection=None):
        # TODO(lpetrut): Remove this method after the patch implementing
        # serial console access support merges in Nova.
        vmsettings = self._lookup_vm_check(vm_name)

        rasds = _wqlutils.get_element_associated_class(
            self._conn, self._SERIAL_PORT_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)
        serial_port = (
            [r for r in rasds if
             r.ResourceSubType == self._SERIAL_PORT_RES_SUB_TYPE][0])

        if update_connection:
            serial_port.Connection = [update_connection]
            self._jobutils.modify_virt_resource(serial_port)

        if len(serial_port.Connection) > 0:
            return serial_port.Connection[0]
Пример #44
0
    def get_vm_serial_port_connection(self, vm_name, update_connection=None):
        # TODO(lpetrut): Remove this method after the patch implementing
        # serial console access support merges in Nova.
        vmsettings = self._lookup_vm_check(vm_name)

        rasds = _wqlutils.get_element_associated_class(
            self._compat_conn,
            self._SERIAL_PORT_SETTING_DATA_CLASS,
            element_instance_id=vmsettings.InstanceID)
        serial_port = ([
            r for r in rasds
            if r.ResourceSubType == self._SERIAL_PORT_RES_SUB_TYPE
        ][0])

        if update_connection:
            serial_port.Connection = [update_connection]
            self._jobutils.modify_virt_resource(serial_port)

        if len(serial_port.Connection) > 0:
            return serial_port.Connection[0]
Пример #45
0
    def enable_remotefx_video_adapter(self,
                                      vm_name,
                                      monitor_count,
                                      max_resolution,
                                      vram_bytes=None):
        vm = self._lookup_vm_check(vm_name, as_vssd=False)

        self._validate_remotefx_params(monitor_count,
                                       max_resolution,
                                       vram_bytes=vram_bytes)

        rasds = _wqlutils.get_element_associated_class(
            self._compat_conn,
            self._CIM_RES_ALLOC_SETTING_DATA_CLASS,
            element_uuid=vm.Name)
        if [
                r for r in rasds
                if r.ResourceSubType == self._SYNTH_3D_DISP_CTRL_RES_SUB_TYPE
        ]:
            raise exceptions.HyperVRemoteFXException(
                _("RemoteFX is already configured for this VM"))

        synth_disp_ctrl_res_list = [
            r for r in rasds
            if r.ResourceSubType == self._SYNTH_DISP_CTRL_RES_SUB_TYPE
        ]
        if synth_disp_ctrl_res_list:
            self._jobutils.remove_virt_resource(synth_disp_ctrl_res_list[0])

        max_res_value = self._remote_fx_res_map.get(max_resolution)
        self._add_3d_display_controller(vm, monitor_count, max_res_value,
                                        vram_bytes)
        if self._vm_has_s3_controller(vm.ElementName):
            s3_disp_ctrl_res = [
                r for r in rasds
                if r.ResourceSubType == self._S3_DISP_CTRL_RES_SUB_TYPE
            ][0]
            s3_disp_ctrl_res.Address = self._DISP_CTRL_ADDRESS_DX_11
            self._jobutils.modify_virt_resource(s3_disp_ctrl_res)
Пример #46
0
    def get_vnic_metrics(self, vm_name):
        ports = self._get_vm_resources(vm_name, self._PORT_ALLOC_SET_DATA)
        vnics = self._get_vm_resources(vm_name, self._SYNTH_ETH_PORT_SET_DATA)

        metrics_def_in = self._metrics_defs[self._NET_IN_METRICS]
        metrics_def_out = self._metrics_defs[self._NET_OUT_METRICS]

        for port in ports:
            vnic = [v for v in vnics if port.Parent == v.path_()][0]
            port_acls = _wqlutils.get_element_associated_class(
                self._conn, self._PORT_ALLOC_ACL_SET_DATA,
                element_instance_id=port.InstanceID)

            metrics_value_instances = self._get_metrics_value_instances(
                port_acls, self._BASE_METRICS_VALUE)
            metrics_values = self._sum_metrics_values_by_defs(
                metrics_value_instances, [metrics_def_in, metrics_def_out])

            yield {
                'rx_mb': metrics_values[0],
                'tx_mb': metrics_values[1],
                'element_name': vnic.ElementName,
                'address': vnic.Address
            }
Пример #47
0
 def _get_vm_resources(self, vm_name, resource_class):
     setting_data = self._get_vm_setting_data(vm_name)
     return _wqlutils.get_element_associated_class(
         self._conn,
         resource_class,
         element_instance_id=setting_data.InstanceID)
Пример #48
0
 def _get_vm_resources(self, vm_name, resource_class):
     setting_data = self._get_vm_setting_data(vm_name)
     return _wqlutils.get_element_associated_class(
         self._conn, resource_class,
         element_instance_id=setting_data.InstanceID)