Skip to content

Commit ead788f

Browse files
authored
fix(region): support stop for change vm config (#24815)
1 parent 8c20090 commit ead788f

40 files changed

Lines changed: 165 additions & 97 deletions

pkg/apis/compute/guests.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,10 @@ type ServerChangeConfigInput struct {
891891
// 内存大小, 1024M, 1G
892892
VmemSize string `json:"vmem_size"`
893893

894+
// 是否强制关机
895+
// 若虚拟机不支持开机调整配置, 则需要指定此参数为true, 强制关机后, 再调整配置, 再启动虚拟机
896+
ForceStop bool `json:"force_stop"`
897+
894898
// 调整完配置后是否自动启动
895899
AutoStart bool `json:"auto_start"`
896900

pkg/compute/guestdrivers/aliyun.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func (self *SAliyunGuestDriver) IsAllowSaveImageOnRunning() bool {
103103
return true
104104
}
105105

106-
func (self *SAliyunGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
107-
return []string{api.VM_READY}, nil
106+
func (self *SAliyunGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
107+
return false, nil
108108
}
109109

110110
func (self *SAliyunGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/aws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ func (self *SAwsGuestDriver) GetRebuildRootStatus() ([]string, error) {
191191
return []string{api.VM_READY, api.VM_RUNNING}, nil
192192
}
193193

194-
func (self *SAwsGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
195-
return []string{api.VM_READY}, nil
194+
func (self *SAwsGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
195+
return false, nil
196196
}
197197

198198
func (self *SAwsGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/azure.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,22 @@ func (self *SAzureGuestDriver) IsRebuildRootSupportChangeUEFI() bool {
102102
return false
103103
}
104104

105-
func (self *SAzureGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
106-
return []string{api.VM_READY, api.VM_RUNNING}, nil
105+
// azureInstanceTypeSupportsResizeWhileRunning 部分 Azure SKU 在开机状态下变更规格易失败,此处做保守判断
106+
func azureInstanceTypeSupportsResizeWhileRunning(instanceType string) bool {
107+
if len(instanceType) == 0 {
108+
return true
109+
}
110+
if strings.HasPrefix(instanceType, "Basic_") || strings.HasPrefix(instanceType, "Standard_A") {
111+
return false
112+
}
113+
return true
114+
}
115+
116+
func (self *SAzureGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
117+
if guest == nil || azureInstanceTypeSupportsResizeWhileRunning(guest.InstanceType) {
118+
return true, nil
119+
}
120+
return false, nil
107121
}
108122

109123
func (self *SAzureGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/baidu.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (self *SBaiduGuestDriver) GetAttachDiskStatus() ([]string, error) {
121121
return []string{api.VM_READY, api.VM_RUNNING}, nil
122122
}
123123

124-
func (self *SBaiduGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
125-
return []string{api.VM_READY}, nil
124+
func (self *SBaiduGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
125+
return false, nil
126126
}
127127

128128
func (self *SBaiduGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/baremetals.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func (self *SBaremetalGuestDriver) GetRebuildRootStatus() ([]string, error) {
123123
return []string{api.VM_READY, api.VM_ADMIN}, nil
124124
}
125125

126-
func (self *SBaremetalGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
127-
return nil, httperrors.NewUnsupportOperationError("Cannot change config for baremtal")
126+
func (self *SBaremetalGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
127+
return false, httperrors.NewUnsupportOperationError("Cannot change config for baremtal")
128128
}
129129

130130
func (self *SBaremetalGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func (drv *SBaseGuestDriver) IsRebuildRootSupportChangeUEFI() bool {
175175
return true
176176
}
177177

178-
func (drv *SBaseGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
179-
return []string{}, fmt.Errorf("This Guest driver dose not implement GetChangeInstanceTypeStatus")
178+
func (drv *SBaseGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
179+
return false, fmt.Errorf("This Guest driver dose not implement IsChangeInstanceTypeWhileRunningSupported")
180180
}
181181

182182
func (drv *SBaseGuestDriver) ValidateDetachDisk(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, disk *models.SDisk) error {

pkg/compute/guestdrivers/cas.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func (self *SCasGuestDriver) GetRebuildRootStatus() ([]string, error) {
100100
return []string{api.VM_READY}, nil
101101
}
102102

103-
func (self *SCasGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
104-
return []string{api.VM_READY}, nil
103+
func (self *SCasGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
104+
return false, nil
105105
}
106106

107107
func (self *SCasGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/cloudpods-baremetals.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func (self *SCloudpodsBaremetalGuestDriver) GetRebuildRootStatus() ([]string, er
123123
return []string{api.VM_READY, api.VM_ADMIN}, nil
124124
}
125125

126-
func (self *SCloudpodsBaremetalGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
127-
return nil, httperrors.NewUnsupportOperationError("Cannot change config for baremtal")
126+
func (self *SCloudpodsBaremetalGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
127+
return false, httperrors.NewUnsupportOperationError("Cannot change config for baremtal")
128128
}
129129

130130
func (self *SCloudpodsBaremetalGuestDriver) GetDeployStatus() ([]string, error) {

pkg/compute/guestdrivers/cloudpods-esxi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ func (self *SCloudpodsESXiGuestDriver) GetAttachDiskStatus() ([]string, error) {
209209
return []string{api.VM_READY, api.VM_RUNNING}, nil
210210
}
211211

212-
func (self *SCloudpodsESXiGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
213-
return []string{api.VM_READY, api.VM_RUNNING}, nil
212+
func (self *SCloudpodsESXiGuestDriver) IsChangeInstanceTypeWhileRunningSupported(guest *models.SGuest) (bool, error) {
213+
return true, nil
214214
}
215215

216216
func (self *SCloudpodsESXiGuestDriver) CanKeepDetachDisk() bool {

0 commit comments

Comments
 (0)