Skip to content

Commit

Permalink
fix(region): zettakit isolate device capability (#21717)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Nov 29, 2024
1 parent 460d150 commit 7b96f7b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ require (
k8s.io/cri-api v0.22.17
k8s.io/klog/v2 v2.20.0
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241128072830-0574df058206
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241129125903-ab677fafe3dd
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20240930100528-1671a2d0d22f
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241128072830-0574df058206 h1:+rHMXfo83atsceTG3oZnOHCpI7LWBDdoB/I3GEND/ZM=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241128072830-0574df058206/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241129125903-ab677fafe3dd h1:HpbqBLtDRNthHEeMUwrD054tOxNTwlcg3SVZ70Bm8fg=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241129125903-ab677fafe3dd/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
Expand Down
12 changes: 12 additions & 0 deletions pkg/compute/guestdrivers/managedvirtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,18 @@ func (drv *SManagedVirtualizedGuestDriver) RemoteDeployGuestForCreate(ctx contex
}
}

devs, err := guest.GetIsolatedDevices()
if err != nil {
return nil, errors.Wrapf(err, "GetIsolatedDevices")
}
desc.IsolateDevices = []cloudprovider.SIsolateDevice{}
for _, dev := range devs {
desc.IsolateDevices = append(desc.IsolateDevices, cloudprovider.SIsolateDevice{
Id: dev.ExternalId,
Name: dev.Name,
})
}

var iVM cloudprovider.ICloudVM = nil
iVM, err = func() (cloudprovider.ICloudVM, error) {
lockman.LockObject(ctx, guest)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/guestdrivers/zettakit.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (self *SZettaKitGuestDriver) GetProvider() string {
}

func (self *SZettaKitGuestDriver) DoScheduleSKUFilter() bool {
return true
return false
}

func (self *SZettaKitGuestDriver) DoScheduleStorageFilter() bool {
Expand Down
11 changes: 8 additions & 3 deletions pkg/compute/models/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ func getIsolatedDeviceInfo(ctx context.Context, userCred mcclient.TokenCredentia
}
hosts := hostQuery.SubQuery()

q := devices.Query(devices.Field("model"), devices.Field("dev_type"), devices.Field("nvme_size_mb"))
q := devices.Query(hosts.Field("host_type"), devices.Field("model"), devices.Field("dev_type"), devices.Field("nvme_size_mb"))
q = q.Filter(sqlchemy.NotIn(devices.Field("dev_type"), []string{api.USB_TYPE, api.NIC_TYPE}))
if zone != nil {
q = q.Join(hosts, sqlchemy.Equals(devices.Field("host_id"), hosts.Field("id")))
Expand All @@ -871,7 +871,7 @@ func getIsolatedDeviceInfo(ctx context.Context, userCred mcclient.TokenCredentia
sqlchemy.IsNullOrEmpty(hosts.Field("manager_id")),
))
}*/
q = q.GroupBy(devices.Field("model"), devices.Field("dev_type"), devices.Field("nvme_size_mb"))
q = q.GroupBy(hosts.Field("host_type"), devices.Field("model"), devices.Field("dev_type"), devices.Field("nvme_size_mb"))

rows, err := q.Rows()
if err != nil {
Expand All @@ -886,7 +886,8 @@ func getIsolatedDeviceInfo(ctx context.Context, userCred mcclient.TokenCredentia
var sizeMB int
var vdev bool
var hypervisor string
rows.Scan(&m, &t, &sizeMB)
var hostType string
rows.Scan(&hostType, &m, &t, &sizeMB)

if m == "" {
continue
Expand All @@ -900,6 +901,10 @@ func getIsolatedDeviceInfo(ctx context.Context, userCred mcclient.TokenCredentia
hypervisor = api.HYPERVISOR_KVM
}

if hostType == api.HOST_TYPE_ZETTAKIT {
hypervisor = api.HYPERVISOR_ZETTAKIT
}

gpus = append(gpus, PCIDevModelTypes{m, t, sizeMB, vdev, hypervisor})

if !utils.IsInStringArray(m, gpuModels) {
Expand Down
16 changes: 15 additions & 1 deletion pkg/compute/models/cloudsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,9 +1263,23 @@ func (self *SGuest) SyncVMIsolateDevices(ctx context.Context, userCred mcclient.
if err != nil {
return err
}
devs, err := self.GetIsolatedDevices()
if err != nil {
return errors.Wrapf(err, "GetIsolatedDevices")
}
for i := range devs {
if !utils.IsInStringArray(devs[i].ExternalId, externalIds) {
_, err = db.Update(&devs[i], func() error {
devs[i].GuestId = ""
return nil
})
if err != nil {
return err
}
}
}
sq := HostManager.Query("id").Equals("manager_id", host.ManagerId).SubQuery()
q := IsolatedDeviceManager.Query().In("host_id", sq).In("external_id", externalIds)
devs := []SIsolatedDevice{}
err = db.FetchModelObjects(IsolatedDeviceManager, q, &devs)
if err != nil {
return err
Expand Down
32 changes: 17 additions & 15 deletions pkg/compute/models/isolated_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,21 +1245,20 @@ func (man *SIsolatedDeviceManager) GetSpecShouldCheckStatus(query *jsonutils.JSO
}

func (man *SIsolatedDeviceManager) BatchGetModelSpecs(statusCheck bool) (jsonutils.JSONObject, error) {
hostQ := HostManager.Query()
q := man.Query("vendor_device_id", "model", "dev_type")
if statusCheck {
q = q.IsNullOrEmpty("guest_id")
hostQ = hostQ.Equals("status", api.BAREMETAL_RUNNING).IsTrue("enabled").
In("host_type", []string{api.HOST_TYPE_HYPERVISOR, api.HOST_TYPE_CONTAINER, api.HOST_TYPE_ZETTAKIT})
}
hostSQ := hostQ.SubQuery()
q.Join(hostSQ, sqlchemy.Equals(q.Field("host_id"), hostSQ.Field("id")))

q.GroupBy(q.Field("vendor_device_id"), q.Field("model"), q.Field("dev_type"))
q.AppendField(hostSQ.Field("host_type"))
q.GroupBy(hostSQ.Field("host_type"), q.Field("vendor_device_id"), q.Field("model"), q.Field("dev_type"))
q.AppendField(sqlchemy.COUNT("*"))

if statusCheck {
hostQ := HostManager.Query().Equals("status", api.BAREMETAL_RUNNING).IsTrue("enabled").
In("host_type", []string{api.HOST_TYPE_HYPERVISOR, api.HOST_TYPE_CONTAINER})
hostSQ := hostQ.SubQuery()
q.Join(hostSQ, sqlchemy.Equals(q.Field("host_id"), hostSQ.Field("id")))
}

rows, err := q.Rows()
if err != nil {
return nil, errors.Wrap(err, "failed get specs")
Expand All @@ -1268,22 +1267,22 @@ func (man *SIsolatedDeviceManager) BatchGetModelSpecs(statusCheck bool) (jsonuti
res := jsonutils.NewDict()

for rows.Next() {
var vendorDeviceId, m, t string
var hostType, vendorDeviceId, m, t string
var count int
if err := rows.Scan(&vendorDeviceId, &m, &t, &count); err != nil {
if err := rows.Scan(&vendorDeviceId, &m, &t, &hostType, &count); err != nil {
return nil, errors.Wrap(err, "get model spec scan rows")
}
vendor := GetVendorByVendorDeviceId(vendorDeviceId)
specKeys := man.getSpecKeys(vendor, m, t)
specKey := GetSpecIdentKey(specKeys)
spec := man.getSpecByRows(vendorDeviceId, m, t, &count)
spec := man.getSpecByRows(hostType, vendorDeviceId, m, t, &count)
res.Set(specKey, spec)
}

return res, nil
}

func (man *SIsolatedDeviceManager) getSpecByRows(vendorDeviceId, model, devType string, count *int) *jsonutils.JSONDict {
func (man *SIsolatedDeviceManager) getSpecByRows(hostType, vendorDeviceId, model, devType string, count *int) *jsonutils.JSONDict {
var vdev bool
var hypervisor string
if utils.IsInStringArray(devType, api.VITRUAL_DEVICE_TYPES) {
Expand All @@ -1294,6 +1293,9 @@ func (man *SIsolatedDeviceManager) getSpecByRows(vendorDeviceId, model, devType
} else {
hypervisor = api.HYPERVISOR_KVM
}
if hostType == api.HOST_TYPE_ZETTAKIT {
hypervisor = api.HYPERVISOR_ZETTAKIT
}

ret := jsonutils.NewDict()
ret.Set("virtual_dev", jsonutils.NewBool(vdev))
Expand All @@ -1318,17 +1320,17 @@ type GpuSpec struct {
}

func (self *SIsolatedDevice) GetSpec(statusCheck bool) *jsonutils.JSONDict {
host := self.getHost()
if statusCheck {
if len(self.GuestId) > 0 {
return nil
}
host := self.getHost()
if host.Status != api.BAREMETAL_RUNNING || !host.GetEnabled() ||
(host.HostType != api.HOST_TYPE_HYPERVISOR && host.HostType != api.HOST_TYPE_CONTAINER) {
(host.HostType != api.HOST_TYPE_HYPERVISOR && host.HostType != api.HOST_TYPE_CONTAINER && host.HostType != api.HOST_TYPE_ZETTAKIT) {
return nil
}
}
return IsolatedDeviceManager.getSpecByRows(self.VendorDeviceId, self.Model, self.DevType, nil)
return IsolatedDeviceManager.getSpecByRows(host.HostType, self.VendorDeviceId, self.Model, self.DevType, nil)
}

func (self *SIsolatedDevice) GetGpuSpec() *GpuSpec {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241128072830-0574df058206
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241129125903-ab677fafe3dd
## explicit; go 1.21
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
Expand Down
7 changes: 7 additions & 0 deletions vendor/yunion.io/x/cloudmux/pkg/cloudprovider/instance.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b96f7b

Please sign in to comment.