mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
fix(region): support cloudpods vm disk driver (#24220)
This commit is contained in:
@@ -103,7 +103,7 @@ require (
|
||||
k8s.io/cri-api v0.28.15
|
||||
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.20260123023305-3637fbeb5a74
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075440-033648c3d921
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
@@ -1665,8 +1665,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.20260123023305-3637fbeb5a74 h1:t/JcnzfXFKsQPyt+CUvLK1gfftHGhZBs8/0rhKa4MI4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260123023305-3637fbeb5a74/go.mod h1:aWRX5Phwz3nbHUNnIAm1oVogjguXPYDDgCOy/9Hnnvk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075440-033648c3d921 h1:EigYkJlFuM0jxFhil+n0P9QJ5mszpFtacvVo2PMthFU=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075440-033648c3d921/go.mod h1:aWRX5Phwz3nbHUNnIAm1oVogjguXPYDDgCOy/9Hnnvk=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
|
||||
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -133,6 +133,10 @@ func (drv *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Context
|
||||
config.SysDisk.SizeGB = int(math.Ceil(float64(disk.DiskSize) / 1024))
|
||||
config.SysDisk.Iops = disk.Iops
|
||||
config.SysDisk.Throughput = disk.Throughput
|
||||
if gds, err := disk.GetGuestDisk(); err == nil {
|
||||
config.SysDisk.Driver = gds.Driver
|
||||
config.SysDisk.CacheMode = gds.CacheMode
|
||||
}
|
||||
cache := storage.GetStoragecache()
|
||||
imageId := disk.GetTemplateId()
|
||||
//避免因同步过来的instance没有对应的imagecache信息,重置密码时引发空指针访问
|
||||
@@ -158,6 +162,10 @@ func (drv *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Context
|
||||
Throughput: disk.Throughput,
|
||||
Name: disk.Name,
|
||||
}
|
||||
if gds, err := disk.GetGuestDisk(); err == nil {
|
||||
dataDisk.Driver = gds.Driver
|
||||
dataDisk.CacheMode = gds.CacheMode
|
||||
}
|
||||
config.DataDisks = append(config.DataDisks, dataDisk)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,11 +387,24 @@ func (manager *SDiskManager) QueryDistinctExtraFields(q *sqlchemy.SQuery, resour
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SDisk) GetGuestDiskCount() (int, error) {
|
||||
func (disk *SDisk) GetGuestDiskQuery() *sqlchemy.SQuery {
|
||||
guestdisks := GuestdiskManager.Query()
|
||||
guests := GuestManager.Query().SubQuery()
|
||||
guestdisks = guestdisks.Join(guests, sqlchemy.Equals(guestdisks.Field("guest_id"), guests.Field("id")))
|
||||
return guestdisks.Equals("disk_id", self.Id).CountWithError()
|
||||
return guestdisks.Equals("disk_id", disk.Id)
|
||||
}
|
||||
|
||||
func (self *SDisk) GetGuestDiskCount() (int, error) {
|
||||
return self.GetGuestDiskQuery().CountWithError()
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetGuestDisk() (*SGuestdisk, error) {
|
||||
guestdisk := &SGuestdisk{}
|
||||
err := disk.GetGuestDiskQuery().First(guestdisk)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "First")
|
||||
}
|
||||
return guestdisk, nil
|
||||
}
|
||||
|
||||
func (self *SDisk) isAttached() (bool, error) {
|
||||
|
||||
@@ -531,22 +531,36 @@ func (region *SRegion) CreateInstance(hostId, hypervisor string, opts *cloudprov
|
||||
input.Cdrom = opts.ExternalImageId
|
||||
imageId = ""
|
||||
}
|
||||
input.Disks = append(input.Disks, &api.DiskConfig{
|
||||
sysDisk := &api.DiskConfig{
|
||||
Index: 0,
|
||||
ImageId: imageId,
|
||||
DiskType: api.DISK_TYPE_SYS,
|
||||
SizeMb: opts.SysDisk.SizeGB * 1024,
|
||||
Backend: opts.SysDisk.StorageType,
|
||||
Storage: opts.SysDisk.StorageExternalId,
|
||||
})
|
||||
}
|
||||
if len(opts.SysDisk.Driver) > 0 {
|
||||
sysDisk.Driver = opts.SysDisk.Driver
|
||||
}
|
||||
if len(opts.SysDisk.CacheMode) > 0 {
|
||||
sysDisk.Cache = opts.SysDisk.CacheMode
|
||||
}
|
||||
input.Disks = append(input.Disks, sysDisk)
|
||||
for idx, disk := range opts.DataDisks {
|
||||
input.Disks = append(input.Disks, &api.DiskConfig{
|
||||
dataDisk := &api.DiskConfig{
|
||||
Index: idx + 1,
|
||||
DiskType: api.DISK_TYPE_DATA,
|
||||
SizeMb: disk.SizeGB * 1024,
|
||||
Backend: disk.StorageType,
|
||||
Storage: disk.StorageExternalId,
|
||||
})
|
||||
}
|
||||
if len(disk.Driver) > 0 {
|
||||
dataDisk.Driver = disk.Driver
|
||||
}
|
||||
if len(disk.CacheMode) > 0 {
|
||||
dataDisk.Cache = disk.CacheMode
|
||||
}
|
||||
input.Disks = append(input.Disks, dataDisk)
|
||||
}
|
||||
input.IsolatedDevices = []*api.IsolatedDeviceConfig{}
|
||||
for _, dev := range input.IsolatedDevices {
|
||||
|
||||
Vendored
+1
-1
@@ -2251,7 +2251,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.20260123023305-3637fbeb5a74
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075440-033648c3d921
|
||||
## explicit; go 1.24
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+2
@@ -102,6 +102,8 @@ type SDiskInfo struct {
|
||||
StorageType string
|
||||
SizeGB int
|
||||
Iops int
|
||||
Driver string
|
||||
CacheMode string
|
||||
Name string
|
||||
// aws gp3 only
|
||||
Throughput int
|
||||
|
||||
Reference in New Issue
Block a user