fix(common): compatible metadata mod find (#21381)

This commit is contained in:
屈轩
2024-10-11 16:39:49 +08:00
committed by GitHub
parent 0a021351fc
commit 6720135a84
2 changed files with 11 additions and 13 deletions
+10 -12
View File
@@ -16,7 +16,6 @@ package compute
import (
"fmt"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/util/printutils"
@@ -78,22 +77,21 @@ func (this *MetadataManager) getModule(session *mcclient.ClientSession, params j
}
if len(resources) >= 1 {
resource := resources[0]
keyString := resource + "s"
if strings.HasSuffix(resource, "y") && resource != NatGateways.GetKeyword() {
keyString = resource[:len(resource)-1] + "ies"
}
find := false
keyStrings := []string{resource, resource + "s", resource + "ies"}
mods, _ := modulebase.GetRegisterdModules()
if utils.IsInStringArray(keyString, mods) {
mod, err := modulebase.GetModule(session, keyString)
if err != nil {
return nil, err
for _, keyString := range keyStrings {
if utils.IsInStringArray(keyString, mods) {
mod, err := modulebase.GetModule(session, keyString)
if err == nil {
service = mod.ServiceType()
find = true
break
}
}
service = mod.ServiceType()
find = true
}
if !find {
return nil, fmt.Errorf("No such module %s", keyString)
return nil, fmt.Errorf("No such module %s", resource)
}
}
}
+1 -1
View File
@@ -55,7 +55,7 @@ func (opts *SkuSyncOptions) Params() (jsonutils.JSONObject, error) {
}
type CloudregionSkuSyncOptions struct {
RESOURCE string `help:"Resource of skus" choices:"serversku|elasticcachesku|dbinstance_sku"`
RESOURCE string `help:"Resource of skus" choices:"serversku|elasticcachesku|dbinstance_sku|nat_sku"`
SkuSyncOptions
}