From e005610391a2e4f2001266c1ff6768a3ebd9d349 Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:53:46 +0800 Subject: [PATCH] fix(region): add hypervisor props on isolated device capabilites (#21321) --- pkg/apis/compute/isolated_device_const.go | 10 ++++++++++ pkg/compute/models/capabilities.go | 16 +++++++++++++++- pkg/compute/models/isolated_devices.go | 12 ++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/pkg/apis/compute/isolated_device_const.go b/pkg/apis/compute/isolated_device_const.go index 032cfb1842..2cd46c11d6 100644 --- a/pkg/apis/compute/isolated_device_const.go +++ b/pkg/apis/compute/isolated_device_const.go @@ -42,6 +42,16 @@ var VALID_PASSTHROUGH_TYPES = []string{ GPU_VGA_TYPE, NVME_PT_TYPE, SRIOV_VGPU_TYPE, LEGACY_VGPU_TYPE, } +var VITRUAL_DEVICE_TYPES = []string{ + LEGACY_VGPU_TYPE, + CONTAINER_DEV_CPH_AMD_GPU, + CONTAINER_DEV_CPH_AOSP_BINDER, + CONTAINER_DEV_NETINT_CA_QUADRA, + CONTAINER_DEV_NETINT_CA_ASIC, + CONTAINER_DEV_NVIDIA_MPS, + CONTAINER_DEV_ASCEND_NPU, +} + var ID_VENDOR_MAP = map[string]string{ NVIDIA_VENDOR_ID: "NVIDIA", AMD_VENDOR_ID: "AMD", diff --git a/pkg/compute/models/capabilities.go b/pkg/compute/models/capabilities.go index 1a134cf264..f824e9a866 100644 --- a/pkg/compute/models/capabilities.go +++ b/pkg/compute/models/capabilities.go @@ -840,6 +840,9 @@ type PCIDevModelTypes struct { Model string DevType string SizeMB int + + VirtualDev bool + Hypervisor string } func getIsolatedDeviceInfo(ctx context.Context, userCred mcclient.TokenCredential, region *SCloudregion, zone *SZone, domainId string) ([]string, []PCIDevModelTypes) { @@ -881,12 +884,23 @@ func getIsolatedDeviceInfo(ctx context.Context, userCred mcclient.TokenCredentia for rows.Next() { var m, t string var sizeMB int + var vdev bool + var hypervisor string rows.Scan(&m, &t, &sizeMB) if m == "" { continue } - gpus = append(gpus, PCIDevModelTypes{m, t, sizeMB}) + if utils.IsInStringArray(t, api.VITRUAL_DEVICE_TYPES) { + vdev = true + } + if utils.IsInStringArray(t, api.VALID_CONTAINER_DEVICE_TYPES) { + hypervisor = api.HYPERVISOR_POD + } else { + hypervisor = api.HYPERVISOR_KVM + } + + gpus = append(gpus, PCIDevModelTypes{m, t, sizeMB, vdev, hypervisor}) if !utils.IsInStringArray(m, gpuModels) { gpuModels = append(gpuModels, m) diff --git a/pkg/compute/models/isolated_devices.go b/pkg/compute/models/isolated_devices.go index f1b3a0098c..ae13a18118 100644 --- a/pkg/compute/models/isolated_devices.go +++ b/pkg/compute/models/isolated_devices.go @@ -952,7 +952,19 @@ func (self *SIsolatedDevice) GetSpec(statusCheck bool) *jsonutils.JSONDict { return nil } } + var vdev bool + var hypervisor string + if utils.IsInStringArray(self.DevType, api.VITRUAL_DEVICE_TYPES) { + vdev = true + } + if utils.IsInStringArray(self.DevType, api.VALID_CONTAINER_DEVICE_TYPES) { + hypervisor = api.HYPERVISOR_POD + } else { + hypervisor = api.HYPERVISOR_KVM + } ret := jsonutils.NewDict() + ret.Set("virtual_dev", jsonutils.NewBool(vdev)) + ret.Set("hypervisor", jsonutils.NewString(hypervisor)) ret.Set("dev_type", jsonutils.NewString(self.DevType)) ret.Set("model", jsonutils.NewString(self.Model)) ret.Set("pci_id", jsonutils.NewString(self.VendorDeviceId))