mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): allow create disk when vm running (#22171)
This commit is contained in:
@@ -1335,6 +1335,10 @@ func (conf ServerChangeConfigSettings) MemChanged() bool {
|
||||
return conf.VmemSize != conf.Old.VmemSize
|
||||
}
|
||||
|
||||
func (conf ServerChangeConfigSettings) InstanceTypeChanged() bool {
|
||||
return len(conf.InstanceType) > 0 && conf.InstanceType != conf.Old.InstanceType
|
||||
}
|
||||
|
||||
func (conf ServerChangeConfigSettings) AddedMem() int {
|
||||
addMem := conf.VmemSize - conf.Old.VmemSize
|
||||
if addMem < 0 {
|
||||
|
||||
@@ -103,8 +103,8 @@ func (self *SAliyunGuestDriver) IsAllowSaveImageOnRunning() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
func (self *SAliyunGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) GetDeployStatus() ([]string, error) {
|
||||
|
||||
@@ -179,7 +179,7 @@ func (self *SAwsGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SAwsGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SAwsGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ func (self *SAzureGuestDriver) IsRebuildRootSupportChangeUEFI() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SAzureGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SAzureGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ func (self *SBaremetalGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_ADMIN}, nil
|
||||
}
|
||||
|
||||
func (self *SBaremetalGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SBaremetalGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return nil, httperrors.NewUnsupportOperationError("Cannot change config for baremtal")
|
||||
}
|
||||
|
||||
|
||||
@@ -174,8 +174,8 @@ func (drv *SBaseGuestDriver) IsRebuildRootSupportChangeUEFI() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (drv *SBaseGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetChangeConfigStatus")
|
||||
func (drv *SBaseGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetChangeInstanceTypeStatus")
|
||||
}
|
||||
|
||||
func (drv *SBaseGuestDriver) ValidateDetachDisk(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, disk *models.SDisk) error {
|
||||
|
||||
@@ -80,7 +80,7 @@ func (self *SCloudpodsGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SCloudpodsGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SCloudpodsGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ func (self *SCtyunGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SCtyunGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SCtyunGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ func (self *SEcloudGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SEcloudGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SEcloudGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ func (self *SESXiGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SESXiGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func (self *SGoogleGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SGoogleGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SGoogleGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func (self *SH3CGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SH3CGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SH3CGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func (self *SHCSGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SHCSGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SHCSGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func (self *SHCSOPGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SHCSOPGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SHCSOPGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ func (self *SHuaweiGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SHuaweiGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ func (self *SHCSOGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SHCSOGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SHCSOGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ func (self *SInCloudSphereGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SInCloudSphereGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SInCloudSphereGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -606,7 +606,7 @@ func (self *SKVMGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SKVMGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ func (self *SNutanixGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SNutanixGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SNutanixGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ func (self *SOpenStackGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING, api.VM_REBUILD_ROOT_FAIL}, nil
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SOpenStackGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ func (self *SProxmoxGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SProxmoxGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SProxmoxGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ func (self *SQcloudGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SQcloudGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SQcloudGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ func (self *SUCloudGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SUCloudGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SUCloudGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ func (self *SVolcengineGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SVolcengineGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SVolcengineGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ func (self *SZStackGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SZStackGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
func (self *SZStackGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2965,15 +2965,7 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
return nil, httperrors.NewBadRequestError("Guest have backup not allow to change config")
|
||||
}
|
||||
|
||||
changeStatus, err := self.GetDriver().GetChangeConfigStatus(self)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("%v", err)
|
||||
}
|
||||
if !utils.IsInStringArray(self.Status, changeStatus) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot change config in %s for %s, requires %s", self.Status, self.GetHypervisor(), changeStatus)
|
||||
}
|
||||
|
||||
_, err = self.GetHost()
|
||||
_, err := self.GetHost()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInvalidStatusError("no valid host")
|
||||
}
|
||||
@@ -2983,6 +2975,16 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
return nil, errors.Wrap(err, "ValidateGuestChangeConfigInput")
|
||||
}
|
||||
|
||||
if confs.CpuChanged() || confs.MemChanged() || confs.InstanceTypeChanged() {
|
||||
changeStatus, err := self.GetDriver().GetChangeInstanceTypeStatus()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("%v", err)
|
||||
}
|
||||
if !utils.IsInStringArray(self.Status, changeStatus) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot change config in %s for %s, requires %s", self.Status, self.GetHypervisor(), changeStatus)
|
||||
}
|
||||
}
|
||||
|
||||
if self.PowerStates == api.VM_POWER_STATES_ON && (confs.CpuChanged() || confs.MemChanged()) {
|
||||
confs, err = self.GetDriver().ValidateGuestHotChangeConfigInput(ctx, self, confs)
|
||||
if err != nil {
|
||||
@@ -2990,6 +2992,16 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
}
|
||||
|
||||
if len(confs.Create) > 0 {
|
||||
attachStatus, err := self.GetDriver().GetAttachDiskStatus()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("%v", err)
|
||||
}
|
||||
if !utils.IsInStringArray(self.Status, attachStatus) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot attach disk in %s for %s, requires %s", self.Status, self.GetHypervisor(), attachStatus)
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("%s", jsonutils.Marshal(confs).String())
|
||||
|
||||
pendingUsage := &SQuota{}
|
||||
|
||||
@@ -141,7 +141,7 @@ type IGuestDriver interface {
|
||||
GetAttachDiskStatus() ([]string, error)
|
||||
GetRebuildRootStatus() ([]string, error)
|
||||
IsAllowSaveImageOnRunning() bool
|
||||
GetChangeConfigStatus(guest *SGuest) ([]string, error)
|
||||
GetChangeInstanceTypeStatus() ([]string, error)
|
||||
GetDeployStatus() ([]string, error)
|
||||
ValidateResizeDisk(guest *SGuest, disk *SDisk, storage *SStorage) error
|
||||
CanKeepDetachDisk() bool
|
||||
|
||||
Reference in New Issue
Block a user