fix(region): hcs obs

This commit is contained in:
ioito
2022-11-01 17:01:52 +08:00
parent 9418bdf6be
commit 26bfd8ee58
8 changed files with 89 additions and 20 deletions
+2 -2
View File
@@ -83,12 +83,12 @@ 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.20221031032051-188c6b884581
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221101083441-16667c2d550f
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
yunion.io/x/log v1.0.0
yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7
yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e
yunion.io/x/pkg v1.0.1-0.20221031045951-0b770b490c45
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.2-0.20220923040147-ddd3e96868af
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6
+4 -3
View File
@@ -1162,8 +1162,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.20221031032051-188c6b884581 h1:ZP0ZjypSiE8C2OHtryqOjJouxsMufsGv+ZjltRSRCbg=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221031032051-188c6b884581/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221101083441-16667c2d550f h1:2+R3KK+2CHf+JA2ODt6b/XmxH148EyeBtMrfHJg4ZJ8=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221101083441-16667c2d550f/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
@@ -1179,8 +1179,9 @@ yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7/go.mod h1:0vLkNEhlmA64HViPB
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e h1:enPKN/yaKmRjw3PWEdA7HDd6VDqewvczIJbSRpO7R8E=
yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e/go.mod h1:nYOMflWG1wQC6301rGVglQva9bYbJxHThEJUxRAgMFc=
yunion.io/x/pkg v1.0.1-0.20221031045951-0b770b490c45 h1:IHnBCHsL/6SquvVq84YP+aVewZ490SOazCbUjOg2Lr0=
yunion.io/x/pkg v1.0.1-0.20221031045951-0b770b490c45/go.mod h1:nYOMflWG1wQC6301rGVglQva9bYbJxHThEJUxRAgMFc=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.0.1/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
+1 -1
View File
@@ -3349,7 +3349,7 @@ func (self *SGuest) SyncVMNics(ctx context.Context, userCred mcclient.TokenCrede
ExtFunc: "GetMAC",
ExtSet: vnics,
}
err = compare.CompareSetsFunc(set, &removed, &commondb, &commonext, &added)
err = compare.CompareSetsFunc(set, &removed, &commondb, &commonext, &added, nil)
if err != nil {
result.Error(errors.Wrapf(err, "compare.CompareSets"))
return result
+1 -1
View File
@@ -190,7 +190,7 @@ func (self *SCloudregion) GetNatSkus() ([]SNatSku, error) {
func (self *SCloudregion) GetElasticcacheSkus() ([]SElasticcacheSku, error) {
skus := []SElasticcacheSku{}
q := ElasticcacheSkuManager.Query().Equals("cloudregion_id", self.Id)
err := db.FetchModelObjects(NatSkuManager, q, &skus)
err := db.FetchModelObjects(ElasticcacheSkuManager, q, &skus)
if err != nil {
return nil, errors.Wrapf(err, "db.FetchModelObjects")
}
+30
View File
@@ -1232,6 +1232,36 @@ func (self *SCloudregion) purgeSkus(ctx context.Context, userCred mcclient.Token
return err
}
}
natSkus, err := self.GetNatSkus()
if err != nil {
return errors.Wrapf(err, "GetNatSkus")
}
for i := range natSkus {
err = natSkus[i].Delete(ctx, userCred)
if err != nil {
return errors.Wrapf(err, "delete nat sku %s", natSkus[i].Id)
}
}
rdsSkus, err := self.GetDBInstanceSkus()
if err != nil {
return errors.Wrapf(err, "GetDBInstanceSkus")
}
for i := range rdsSkus {
err = rdsSkus[i].Delete(ctx, userCred)
if err != nil {
return errors.Wrapf(err, "delete rds sku %s", rdsSkus[i].Id)
}
}
cacheSkus, err := self.GetElasticcacheSkus()
if err != nil {
return errors.Wrapf(err, "GetElasticcacheSkus")
}
for i := range cacheSkus {
err = cacheSkus[i].Delete(ctx, userCred)
if err != nil {
return errors.Wrapf(err, "delete cache sku %s", cacheSkus[i].Id)
}
}
return nil
}
+2 -2
View File
@@ -1428,7 +1428,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.20221031032051-188c6b884581
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221101083441-16667c2d550f
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
@@ -1524,7 +1524,7 @@ yunion.io/x/log/hooks
yunion.io/x/ovsdb/cli_util
yunion.io/x/ovsdb/schema/ovn_nb
yunion.io/x/ovsdb/types
# yunion.io/x/pkg v1.0.1-0.20220819080140-55b265a8658e
# yunion.io/x/pkg v1.0.1-0.20221031045951-0b770b490c45
## explicit; go 1.18
yunion.io/x/pkg/errors
yunion.io/x/pkg/gotypes
+4 -1
View File
@@ -313,6 +313,9 @@ func (self *SHcsClient) fetchRegions() error {
}
for i := range self.regions {
self.defaultRegion = self.regions[i].Id
if self.projectName == self.regions[i].Id {
self.isMainProject = true
}
}
return nil
}
@@ -724,7 +727,7 @@ func (self *SHcsClient) GetCapabilities() []string {
}
func (self *SHcsClient) getOBSEndpoint(regionId string) string {
return fmt.Sprintf("obs.%s.%s", regionId, self.authUrl)
return fmt.Sprintf("obsv3.%s.%s", regionId, self.authUrl)
}
func (self *SHcsClient) getOBSClient(regionId string) (*obs.ObsClient, error) {
+45 -10
View File
@@ -20,6 +20,7 @@ import (
"sort"
"strings"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
)
@@ -76,7 +77,7 @@ type SCompareSet struct {
ExtSet interface{}
}
func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{}, commonExt interface{}, added interface{}) error {
func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{}, commonExt interface{}, added interface{}, duplicated interface{}) error {
dbSetArray, err := valueSet2Array(cs.DBSet, cs.DBFunc)
if err != nil {
return err
@@ -85,22 +86,53 @@ func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{},
if err != nil {
return err
}
sort.Sort(valueSet(dbSetArray))
sort.Sort(valueSet(extSetArray))
dupCheck := map[string][]reflect.Value{}
sort.Sort(valueSet(dbSetArray))
dupCheck := map[string][]int{}
for i := range extSetArray {
_, ok := dupCheck[extSetArray[i].key]
if !ok {
dupCheck[extSetArray[i].key] = []reflect.Value{}
dupCheck[extSetArray[i].key] = []int{}
}
dupCheck[extSetArray[i].key] = append(dupCheck[extSetArray[i].key], extSetArray[i].value)
dupCheck[extSetArray[i].key] = append(dupCheck[extSetArray[i].key], i)
}
if len(dupCheck[extSetArray[i].key]) > 1 {
return errors.Wrapf(errors.ErrDuplicateId, "duplicated id: %s", extSetArray[i].key)
var dupValue reflect.Value
storeDup := false
if duplicated != nil {
storeDup = true
dupValue = reflect.Indirect(reflect.ValueOf(duplicated))
}
errs := make([]error, 0)
newExtSetArray := make([]valueElement, 0)
for k, idx := range dupCheck {
if len(idx) > 1 {
if !storeDup {
log.Warningf("CompareSets Duplicate ID: %s (%d)", k, len(idx))
errs = append(errs, errors.Wrapf(errors.ErrDuplicateId, "duplicated id: %s (%d)", k, len(idx)))
} else {
// store in dupValue
dupArrays := reflect.MakeSlice(reflect.SliceOf(extSetArray[idx[0]].value.Type()), len(idx), len(idx))
for i := 0; i < len(idx); i++ {
dupArrays.Index(i).Set(extSetArray[idx[i]].value)
}
dupValue.SetMapIndex(reflect.ValueOf(k), dupArrays)
}
} else {
newExtSetArray = append(newExtSetArray, extSetArray[idx[0]])
}
}
if len(errs) > 0 {
return errors.NewAggregate(errs)
}
extSetArray = newExtSetArray
sort.Sort(valueSet(extSetArray))
removedValue := reflect.Indirect(reflect.ValueOf(removed))
commonDBValue := reflect.Indirect(reflect.ValueOf(commonDB))
commonExtValue := reflect.Indirect(reflect.ValueOf(commonExt))
@@ -142,14 +174,17 @@ func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{},
}
}
return nil
}
func CompareSets(dbSet interface{}, extSet interface{}, removed interface{}, commonDB interface{}, commonExt interface{}, added interface{}) error {
return CompareSets2(dbSet, extSet, removed, commonDB, commonExt, added, nil)
}
func CompareSets2(dbSet interface{}, extSet interface{}, removed interface{}, commonDB interface{}, commonExt interface{}, added interface{}, duplicated interface{}) error {
return CompareSetsFunc(SCompareSet{
DBFunc: "GetExternalId",
DBSet: dbSet,
ExtFunc: "GetGlobalId",
ExtSet: extSet,
}, removed, commonDB, commonExt, added)
}, removed, commonDB, commonExt, added, duplicated)
}