fix(region): support use cached iso image for create cloudpods vm (#20685)

This commit is contained in:
屈轩
2024-06-30 22:22:07 +08:00
committed by GitHub
parent 67332c2e78
commit c333a80cfa
2 changed files with 21 additions and 1 deletions
+11
View File
@@ -19,6 +19,7 @@ import (
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/cloudinit"
"yunion.io/x/pkg/util/rbacscope"
"yunion.io/x/pkg/utils"
@@ -166,3 +167,13 @@ func (self *SCloudpodsGuestDriver) GetInstanceCapability() cloudprovider.SInstan
func (self *SCloudpodsGuestDriver) GetMinimalSysDiskSizeGb() int {
return options.Options.DefaultDiskSizeMB / 1024
}
func (self *SCloudpodsGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
if len(input.UserData) > 0 {
_, err := cloudinit.ParseUserData(input.UserData)
if err != nil {
return nil, err
}
}
return input, nil
}
+10 -1
View File
@@ -516,9 +516,18 @@ func (self *SRegion) CreateInstance(hostId, hypervisor string, opts *cloudprovid
if opts.BillingCycle != nil {
input.Duration = opts.BillingCycle.String()
}
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 = ""
}
input.Disks = append(input.Disks, &api.DiskConfig{
Index: 0,
ImageId: opts.ExternalImageId,
ImageId: imageId,
DiskType: api.DISK_TYPE_SYS,
SizeMb: opts.SysDisk.SizeGB * 1024,
Backend: opts.SysDisk.StorageType,