mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Automatic merge from release/2.4.0 -> release/2.5.0
* commit '7d693d7f33ca9a72cf679e33150879234e210e20': 允许删除阿里云过期包年包月主机 修正: 1. 阿里云client空指针错误,通过wrapper隐藏 2. clean storage cached image处理异常情况 3. server purge不能purge带eip的主机
This commit is contained in:
@@ -305,7 +305,15 @@ func (sr *SSyncRange) normalizeZoneIds() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
sr.Zone[i] = obj.GetId()
|
||||
zone := obj.(*SZone)
|
||||
region := zone.GetRegion()
|
||||
if region == nil {
|
||||
continue
|
||||
}
|
||||
sr.Zone[i] = zone.GetId()
|
||||
if !utils.IsInStringArray(region.Id, sr.Region) {
|
||||
sr.Region = append(sr.Region, region.Id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -320,7 +328,22 @@ func (sr *SSyncRange) normalizeHostIds() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
sr.Host[i] = obj.GetId()
|
||||
host := obj.(*SHost)
|
||||
zone := host.GetZone()
|
||||
if zone == nil {
|
||||
continue
|
||||
}
|
||||
region := zone.GetRegion()
|
||||
if region == nil {
|
||||
continue
|
||||
}
|
||||
sr.Host[i] = host.GetId()
|
||||
if !utils.IsInStringArray(zone.Id, sr.Zone) {
|
||||
sr.Zone = append(sr.Zone, zone.Id)
|
||||
}
|
||||
if !utils.IsInStringArray(region.Id, sr.Region) {
|
||||
sr.Region = append(sr.Region, region.Id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -331,18 +354,24 @@ func (sr *SSyncRange) Normalize() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
sr.Region = make([]string, 0)
|
||||
}
|
||||
if sr.Zone != nil && len(sr.Zone) > 0 {
|
||||
err := sr.normalizeZoneIds()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
sr.Zone = make([]string, 0)
|
||||
}
|
||||
if sr.Host != nil && len(sr.Host) > 0 {
|
||||
err := sr.normalizeHostIds()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
sr.Host = make([]string, 0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -760,9 +760,20 @@ func (self *SDisk) StartDiskSaveTask(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
func (self *SDisk) ValidateDeleteCondition(ctx context.Context) error {
|
||||
return self.validateDeleteCondition(ctx, false)
|
||||
}
|
||||
|
||||
func (self *SDisk) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return self.validateDeleteCondition(ctx, true)
|
||||
}
|
||||
|
||||
func (self *SDisk) validateDeleteCondition(ctx context.Context, isPurge bool) error {
|
||||
if self.GetGuestDiskCount() > 0 {
|
||||
return httperrors.NewNotEmptyError("Virtual disk used by virtual servers")
|
||||
}
|
||||
if !isPurge && self.IsValidPrePaid() {
|
||||
return httperrors.NewForbiddenError("not allow to delete prepaid disk in valid status")
|
||||
}
|
||||
return self.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx)
|
||||
}
|
||||
|
||||
@@ -1278,7 +1289,7 @@ func (self *SDisk) AllowPerformPurge(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
func (self *SDisk) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
err := self.ValidatePurgeCondition(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ func (self *SStoragecachedimage) ValidateDeleteCondition(ctx context.Context) er
|
||||
return httperrors.NewResourceBusyError("Active download session not expired")
|
||||
}
|
||||
image := self.GetCachedimage()
|
||||
if !image.canDeleteLastCache() {
|
||||
if image != nil && !image.canDeleteLastCache() {
|
||||
return httperrors.NewResourceBusyError("Cannot delete the last cache")
|
||||
}
|
||||
return self.SJointResourceBase.ValidateDeleteCondition(ctx)
|
||||
@@ -253,8 +253,10 @@ func (self *SStoragecachedimage) markDeleting(ctx context.Context, userCred mccl
|
||||
cache := self.GetStoragecache()
|
||||
image := self.GetCachedimage()
|
||||
|
||||
lockman.LockJointObject(ctx, cache, image)
|
||||
defer lockman.ReleaseJointObject(ctx, cache, image)
|
||||
if image != nil {
|
||||
lockman.LockJointObject(ctx, cache, image)
|
||||
defer lockman.ReleaseJointObject(ctx, cache, image)
|
||||
}
|
||||
|
||||
if !isForce && !utils.IsInStringArray(self.Status,
|
||||
[]string{CACHED_IMAGE_STATUS_READY, CACHED_IMAGE_STATUS_DELETING, CACHED_IMAGE_STATUS_CACHE_FAILED}) {
|
||||
|
||||
@@ -345,13 +345,20 @@ func (self *SStoragecache) PerformUncacheImage(ctx context.Context, userCred mcc
|
||||
}
|
||||
isForce := jsonutils.QueryBoolean(data, "is_force", false)
|
||||
|
||||
var imageId string
|
||||
image, err := CachedimageManager.getImageInfo(ctx, userCred, imageStr, isForce)
|
||||
if err != nil {
|
||||
log.Infof("image %s not found %s", imageStr, err)
|
||||
return nil, httperrors.NewImageNotFoundError(imageStr)
|
||||
if !isForce {
|
||||
return nil, httperrors.NewImageNotFoundError(imageStr)
|
||||
} else {
|
||||
imageId = imageStr
|
||||
}
|
||||
} else {
|
||||
imageId = image.Id
|
||||
}
|
||||
|
||||
scimg := StoragecachedimageManager.GetStoragecachedimage(self.Id, image.Id)
|
||||
scimg := StoragecachedimageManager.GetStoragecachedimage(self.Id, imageId)
|
||||
if scimg == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("storage not cache image")
|
||||
}
|
||||
@@ -366,7 +373,7 @@ func (self *SStoragecache) PerformUncacheImage(ctx context.Context, userCred mcc
|
||||
return nil, httperrors.NewInvalidStatusError("Fail to mark cache status: %s", err)
|
||||
}
|
||||
|
||||
err = self.StartImageUncacheTask(ctx, userCred, image.Id, isForce, "")
|
||||
err = self.StartImageUncacheTask(ctx, userCred, imageId, isForce, "")
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -67,8 +67,14 @@ func (self *GuestDeleteTask) OnGuestStopComplete(ctx context.Context, obj db.ISt
|
||||
eip, _ := guest.GetEip()
|
||||
if eip != nil && eip.Mode != models.EIP_MODE_INSTANCE_PUBLICIP {
|
||||
// detach floating EIP only
|
||||
self.SetStage("on_eip_dissociate_complete", nil)
|
||||
eip.StartEipDissociateTask(ctx, self.UserCred, self.GetTaskId())
|
||||
if jsonutils.QueryBoolean(self.Params, "purge", false) {
|
||||
// purge locally
|
||||
eip.Dissociate(ctx, self.UserCred)
|
||||
self.OnEipDissociateComplete(ctx, guest, nil)
|
||||
} else {
|
||||
self.SetStage("on_eip_dissociate_complete", nil)
|
||||
eip.StartEipDissociateTask(ctx, self.UserCred, self.GetTaskId())
|
||||
}
|
||||
} else {
|
||||
self.OnEipDissociateComplete(ctx, obj, nil)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func _jsonRequest(client *sdk.Client, domain string, version string, apiName str
|
||||
}
|
||||
req.Scheme = "https"
|
||||
|
||||
resp, err := client.ProcessCommonRequest(req)
|
||||
resp, err := processCommonRequest(client, req)
|
||||
if err != nil {
|
||||
log.Errorf("request error %s", err)
|
||||
return nil, err
|
||||
|
||||
@@ -616,7 +616,7 @@ func (self *SRegion) doStopVM(instanceId string, isForce bool) error {
|
||||
|
||||
func (self *SRegion) doDeleteVM(instanceId string) error {
|
||||
params := make(map[string]string)
|
||||
params["TerminateSubscription"] = "false"
|
||||
params["TerminateSubscription"] = "true" // terminate expired prepaid instance
|
||||
params["Force"] = "true"
|
||||
return self.instanceOperation(instanceId, "DeleteInstance", params)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
|
||||
)
|
||||
|
||||
func processCommonRequest(client *sdk.Client, req *requests.CommonRequest) (response *responses.CommonResponse, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Errorf("client.ProcessCommonRequest error: %s", r)
|
||||
// debug.PrintStack()
|
||||
response = nil
|
||||
jsonError := jsonutils.NewDict()
|
||||
jsonError.Add(jsonutils.NewString("SignatureNonceUsed"), "Code")
|
||||
err = errors.New(jsonError.String())
|
||||
}
|
||||
}()
|
||||
return client.ProcessCommonRequest(req)
|
||||
}
|
||||
Reference in New Issue
Block a user