Skip to content

Commit

Permalink
fix: 优化标签列表version问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jun 15, 2020
1 parent e49c11e commit d296a18
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
35 changes: 30 additions & 5 deletions pkg/mcclient/modules/mod_metadatas.go
Expand Up @@ -15,9 +15,11 @@
package modules

import (
"fmt"
"strings"

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/utils"

"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
Expand All @@ -40,7 +42,7 @@ func init() {
}

func (this *MetadataManager) getModule(session *mcclient.ClientSession, params jsonutils.JSONObject) (modulebase.Manager, error) {
service := "compute_v2"
service, version := "compute", ""
if params.Contains("service") {
service, _ = params.GetString("service")
} else {
Expand All @@ -63,14 +65,37 @@ func (this *MetadataManager) getModule(session *mcclient.ClientSession, params j
if strings.HasSuffix(resource, "y") {
keyString = resource[:len(resource)-1] + "ies"
}
mod, err := modulebase.GetModule(session, keyString)
if err != nil {
return nil, err
find := false
mods, _ := modulebase.GetRegisterdModules()
for _versin, mds := range mods {
if utils.IsInStringArray(keyString, mds) {
version = _versin
session.SetApiVersion(version)
mod, err := modulebase.GetModule(session, keyString)
if err != nil {
return nil, err
}
service = mod.ServiceType()
find = true
break
}
}
if !find {
return nil, fmt.Errorf("No such module %s", keyString)
}
service = mod.ServiceType()
}
}

switch service {
case "identity":
version = "v3"
case "compute":
version = "v2"
default:
version = "v1"
}

session.SetApiVersion(version)
_, err := session.GetServiceURL(service, "")
if err != nil {
return nil, httperrors.NewNotFoundError("service %s not found error: %v", service, err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/mcclient/session.go
Expand Up @@ -352,6 +352,10 @@ func (this *ClientSession) WaitTaskNotify() {
}
}

func (this *ClientSession) SetApiVersion(version string) {
this.defaultApiVersion = version
}

func (this *ClientSession) GetApiVersion() string {
apiVersion := this.getApiVersion("")
if len(apiVersion) == 0 {
Expand Down

0 comments on commit d296a18

Please sign in to comment.