mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-07 06:02:09 +08:00
fix(region): allow delete aliyun prepaid vm (#19767)
This commit is contained in:
2
go.mod
2
go.mod
@@ -90,7 +90,7 @@ require (
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
k8s.io/cri-api v0.22.17
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240319073545-977c1b80b962
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240321094619-9614dc43aa9b
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1212,8 +1212,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.20240319073545-977c1b80b962 h1:Wl9tal5cFRvZwlDVMxVPrGvjhMjBFSv+18/VAVyQSV0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240319073545-977c1b80b962/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240321094619-9614dc43aa9b h1:M6R0Rp/zOJEAREMTVzuiPXEf6e25Ozh71JbZ4UuphyE=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240321094619-9614dc43aa9b/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -1480,7 +1480,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.20240319073545-977c1b80b962
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240321094619-9614dc43aa9b
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
42
vendor/yunion.io/x/cloudmux/pkg/multicloud/aliyun/instance.go
generated
vendored
42
vendor/yunion.io/x/cloudmux/pkg/multicloud/aliyun/instance.go
generated
vendored
@@ -21,6 +21,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
alierr "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -826,23 +828,45 @@ func (self *SRegion) DeployVM(instanceId string, opts *cloudprovider.SInstanceDe
|
||||
}
|
||||
|
||||
func (self *SInstance) DeleteVM(ctx context.Context) error {
|
||||
// 未到期包年包月实例需要先转换到按量计费后, 进行删除
|
||||
if self.GetBillingType() == billing_api.BILLING_TYPE_PREPAID && self.GetExpiredAt().After(time.Now()) {
|
||||
err := self.host.zone.region.ConvertVmPostpaid([]string{self.InstanceId})
|
||||
if err != nil {
|
||||
log.Warningf("convert vm %s to postpaid error: %v", self.InstanceId, err)
|
||||
}
|
||||
}
|
||||
for {
|
||||
err := self.host.zone.region.DeleteVM(self.InstanceId)
|
||||
if err != nil {
|
||||
if isError(err, "IncorrectInstanceStatus.Initializing") {
|
||||
log.Infof("The instance is initializing, try later ...")
|
||||
time.Sleep(10 * time.Second)
|
||||
} else {
|
||||
log.Errorf("DeleteVM fail: %s", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
e, ok := errors.Cause(err).(*alierr.ServerError)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
switch e.ErrorCode() {
|
||||
case "IncorrectInstanceStatus.Initializing":
|
||||
time.Sleep(10 * time.Second)
|
||||
case "LastTokenProcessing": // 等待转换按量付费完成
|
||||
time.Sleep(10 * time.Second)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
return cloudprovider.WaitDeleted(self, 10*time.Second, 300*time.Second) // 5minutes
|
||||
}
|
||||
|
||||
func (self *SRegion) ConvertVmPostpaid(instanceIds []string) error {
|
||||
params := map[string]string{
|
||||
"RegionId": self.RegionId,
|
||||
"InstanceIds": jsonutils.Marshal(instanceIds).String(),
|
||||
"InstanceChargeType": "PostPaid",
|
||||
"ClientToken": utils.GenRequestId(20),
|
||||
}
|
||||
_, err := self.ecsRequest("ModifyInstanceChargeType", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SRegion) UpdateVM(instanceId string, input cloudprovider.SInstanceUpdateOptions, osType string) error {
|
||||
/*
|
||||
api: ModifyInstanceAttribute
|
||||
|
||||
Reference in New Issue
Block a user