mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix(region): support cloudpods vm disk driver (#24224)
This commit is contained in:
@@ -93,7 +93,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260123023413-f5d35910430c
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075459-3ec00d1b9a21
|
||||
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
|
||||
|
||||
@@ -1272,8 +1272,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.20260123023413-f5d35910430c h1:x+vf8gAXmf1CYfMTKO7BAdXa1a8iMpffNUW0B3P3wNg=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260123023413-f5d35910430c/go.mod h1:GdAwZ78fiqj13i2r1zNuE/D6YOlhh2q4jZjuyHiZTq8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075459-3ec00d1b9a21 h1:GkrzAex/dRluALnjwQ027ET1op5JW/REivQ4Y4cAcjc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075459-3ec00d1b9a21/go.mod h1:GdAwZ78fiqj13i2r1zNuE/D6YOlhh2q4jZjuyHiZTq8=
|
||||
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=
|
||||
|
||||
@@ -128,6 +128,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信息,重置密码时引发空指针访问
|
||||
@@ -153,6 +157,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,11 +383,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) {
|
||||
|
||||
@@ -517,22 +517,45 @@ func (self *SRegion) CreateInstance(hostId, hypervisor string, opts *cloudprovid
|
||||
if opts.BillingCycle != nil {
|
||||
input.Duration = opts.BillingCycle.String()
|
||||
}
|
||||
input.Disks = append(input.Disks, &api.DiskConfig{
|
||||
image, err := self.GetImage(opts.ExternalImageId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetImage")
|
||||
}
|
||||
imageId := opts.ExternalImageId
|
||||
if image.DiskFormat == "iso" {
|
||||
input.Cdrom = opts.ExternalImageId
|
||||
imageId = ""
|
||||
}
|
||||
sysDisk := &api.DiskConfig{
|
||||
Index: 0,
|
||||
ImageId: opts.ExternalImageId,
|
||||
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.Networks = append(input.Networks, &api.NetworkConfig{
|
||||
Index: 0,
|
||||
|
||||
Vendored
+1
-1
@@ -1589,7 +1589,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.20260123023413-f5d35910430c
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260203075459-3ec00d1b9a21
|
||||
## explicit; go 1.21
|
||||
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