mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(region): check sku request error
This commit is contained in:
@@ -21,6 +21,8 @@ type LoadbalancerCertificateDetails struct {
|
||||
SLoadbalancerCertificate
|
||||
|
||||
LbListenerCount int `json:"lb_listener_count"`
|
||||
// 证书内容是否完整
|
||||
IsComplete bool `json:"is_complete"`
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateResourceInfo struct {
|
||||
|
||||
@@ -1436,6 +1436,7 @@ func (self *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.To
|
||||
LoadbalancerBackendGroupManager,
|
||||
CachedLoadbalancerAclManager,
|
||||
CachedLoadbalancerCertificateManager,
|
||||
LoadbalancerCertificateManager,
|
||||
NatGatewayManager,
|
||||
DBInstanceManager,
|
||||
DBInstanceBackupManager,
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -77,7 +76,7 @@ type SLoadbalancerCertificate struct {
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) GetCachedCerts() ([]SCachedLoadbalancerCertificate, error) {
|
||||
ret := []SCachedLoadbalancerCertificate{}
|
||||
q := CachedLoadbalancerCertificateManager.Query().Equals("certificate_id", lbcert.Id)
|
||||
q := CachedLoadbalancerCertificateManager.Query().Equals("certificate_id", lbcert.Id).IsFalse("pending_deleted")
|
||||
err := db.FetchModelObjects(CachedLoadbalancerCertificateManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -131,6 +130,10 @@ func (lbcert *SLoadbalancerCertificate) GetExtraDetails(
|
||||
return api.LoadbalancerCertificateDetails{}, nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) IsComplete() bool {
|
||||
return lbcert.PrivateKey != "" && lbcert.Certificate != ""
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerCertificateManager) FetchCustomizeColumns(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
@@ -146,6 +149,7 @@ func (manager *SLoadbalancerCertificateManager) FetchCustomizeColumns(
|
||||
for i := range rows {
|
||||
rows[i] = api.LoadbalancerCertificateDetails{
|
||||
SharableVirtualResourceDetails: virtRows[i],
|
||||
IsComplete: objs[i].(*SLoadbalancerCertificate).IsComplete(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
)
|
||||
|
||||
var LB_CERTS_TO_BE_PURGE = map[string][]string{}
|
||||
|
||||
type IPurgeableManager interface {
|
||||
Keyword() string
|
||||
purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error
|
||||
@@ -195,12 +197,23 @@ func (manager *SCachedLoadbalancerCertificateManager) purgeAll(ctx context.Conte
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lbcertIds := []string{}
|
||||
if certs, ok := LB_CERTS_TO_BE_PURGE[providerId]; ok {
|
||||
lbcertIds = certs
|
||||
}
|
||||
|
||||
for i := range lbcs {
|
||||
err := lbcs[i].purge(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(lbcs[i].CertificateId) > 0 && !utils.IsInStringArray(lbcs[i].CertificateId, lbcertIds) {
|
||||
lbcertIds = append(lbcertIds, lbcs[i].CertificateId)
|
||||
}
|
||||
}
|
||||
LB_CERTS_TO_BE_PURGE[providerId] = lbcertIds
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -216,6 +229,50 @@ func (lbcert *SCachedLoadbalancerCertificate) purge(ctx context.Context, userCre
|
||||
return lbcert.DoPendingDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerCertificateManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
|
||||
if certs, ok := LB_CERTS_TO_BE_PURGE[providerId]; ok {
|
||||
lbcs := make([]SLoadbalancerCertificate, 0)
|
||||
err := db.FetchModelObjects(manager, manager.Query().In("id", certs), &lbcs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range lbcs {
|
||||
err := lbcs[i].purge(ctx, userCred)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
delete(LB_CERTS_TO_BE_PURGE, providerId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) purge(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, lbcert)
|
||||
defer lockman.ReleaseObject(ctx, lbcert)
|
||||
|
||||
if !lbcert.PendingDeleted {
|
||||
// 内容完整的证书不需要删除
|
||||
if lbcert.IsComplete() {
|
||||
return nil
|
||||
}
|
||||
|
||||
caches, err := lbcert.GetCachedCerts()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetCachedCerts")
|
||||
}
|
||||
|
||||
if len(caches) > 0 {
|
||||
log.Debugf("the lb cert %s (%s) is in use.can not purge.", lbcert.Name, lbcert.Id)
|
||||
return nil
|
||||
}
|
||||
return lbcert.DoPendingDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
|
||||
lbacls := make([]SCachedLoadbalancerAcl, 0)
|
||||
err := fetchByManagerId(manager, providerId, &lbacls)
|
||||
|
||||
Reference in New Issue
Block a user