fix(region): support delete huawei prepaid resource (#20031)

This commit is contained in:
屈轩
2024-04-16 18:08:15 +08:00
committed by GitHub
parent 53ae0e2f02
commit 3c5f09fdab
8 changed files with 32 additions and 6 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240414044510-9b337f813b2e
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240416095227-3e37fc917f65
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
+2 -2
View File
@@ -1204,8 +1204,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.20240414044510-9b337f813b2e h1:Zqw7V6qufsqQoZZY24vr3RcZckzmtevO+7J6H7RyeuE=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240414044510-9b337f813b2e/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240416095227-3e37fc917f65 h1:TyUeqGO9VvE0+I4mGshrsUP/Zxy7FYdlY9oAL96OXCs=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240416095227-3e37fc917f65/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=
+1 -1
View File
@@ -1472,7 +1472,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.20240414044510-9b337f813b2e
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240416095227-3e37fc917f65
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+3
View File
@@ -451,6 +451,9 @@ func (rds *SDBInstance) GetIDBInstanceAccounts() ([]cloudprovider.ICloudDBInstan
}
func (rds *SDBInstance) Delete() error {
if rds.GetBillingType() == billing_api.BILLING_TYPE_PREPAID {
return rds.region.CancelResourcesSubscription([]string{rds.Id})
}
return rds.region.DeleteDBInstance(rds.Id)
}
+3
View File
@@ -295,6 +295,9 @@ func (self *SDisk) GetAccessPath() string {
}
func (self *SDisk) Delete(ctx context.Context) error {
if self.GetBillingType() == billing_api.BILLING_TYPE_PREPAID {
return self.storage.zone.region.CancelResourcesSubscription([]string{self.ID})
}
disk, err := self.storage.zone.region.GetDisk(self.GetId())
if err != nil {
if errors.Cause(err) == cloudprovider.ErrNotFound {
+5 -2
View File
@@ -139,9 +139,9 @@ func (self *SEipAddress) GetInternetChargeType() string {
func (self *SEipAddress) GetBillingType() string {
if len(self.BillingInfo) > 0 {
return billing_api.BILLING_TYPE_POSTPAID
return billing_api.BILLING_TYPE_PREPAID
}
return billing_api.BILLING_TYPE_PREPAID
return billing_api.BILLING_TYPE_POSTPAID
}
func (self *SEipAddress) GetCreatedAt() time.Time {
@@ -153,6 +153,9 @@ func (self *SEipAddress) GetExpiredAt() time.Time {
}
func (self *SEipAddress) Delete() error {
if self.GetBillingType() == billing_api.BILLING_TYPE_PREPAID {
return self.region.CancelResourcesSubscription([]string{self.Id})
}
return self.region.DeallocateEIP(self.Id)
}
@@ -501,6 +501,9 @@ func (self *SElasticcache) Restart() error {
}
func (self *SElasticcache) Delete() error {
if self.GetBillingType() == billing_api.BILLING_TYPE_PREPAID {
return self.region.CancelResourcesSubscription([]string{self.InstanceID})
}
_, err := self.region.delete(SERVICE_DCS, "instances/"+self.GetId())
return err
}
+14
View File
@@ -570,9 +570,23 @@ func (self *SInstance) StopVM(ctx context.Context, opts *cloudprovider.ServerSto
}
func (self *SInstance) DeleteVM(ctx context.Context) error {
if self.GetBillingType() == billing_api.BILLING_TYPE_PREPAID {
return self.host.zone.region.CancelResourcesSubscription([]string{self.ID})
}
return self.host.zone.region.DeleteVM(self.GetId())
}
func (self *SRegion) CancelResourcesSubscription(resourceIds []string) error {
params := map[string]interface{}{
"resource_ids": resourceIds,
"unsubscribe_type": 1,
"unsubscribe_reason_type": 5,
"unsubscribe_reason": "cloudpods auto delete prepaid resources",
}
_, err := self.post(SERVICE_BSS, "orders/subscriptions/resources/unsubscribe", params)
return err
}
func (self *SInstance) UpdateVM(ctx context.Context, input cloudprovider.SInstanceUpdateOptions) error {
return self.host.zone.region.UpdateVM(self.GetId(), input)
}