Skip to content

Commit

Permalink
fix: 支持访问其他服务的标签列表
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed May 11, 2020
1 parent 1403fae commit f01bed8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
50 changes: 46 additions & 4 deletions pkg/mcclient/modules/mod_metadatas.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,57 @@

package modules

import "yunion.io/x/onecloud/pkg/mcclient/modulebase"
import (
"yunion.io/x/jsonutils"

"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)

type MetadataManager struct {
modulebase.ResourceManager
}

var (
Metadatas modulebase.ResourceManager
Metadatas MetadataManager
)

func init() {
Metadatas = NewComputeManager("metadata", "metadatas",
Metadatas = MetadataManager{NewComputeManager("metadata", "metadatas",
[]string{"id", "key", "value"},
[]string{})
[]string{})}
registerCompute(&Metadatas)
}

func (this *MetadataManager) getModule(session *mcclient.ClientSession, params jsonutils.JSONObject) (*modulebase.ResourceManager, error) {
service, _ := params.GetString("service")
if len(service) > 0 {
_, err := session.GetServiceURL(service, "")
if err != nil {
return nil, httperrors.NewNotFoundError("service %s not found error: %v", service, err)
}
} else {
service = "compute"
}
return &modulebase.ResourceManager{
BaseManager: *modulebase.NewBaseManager(service, "", "", []string{}, []string{}),
Keyword: "metadata", KeywordPlural: "metadatas",
}, nil
}

func (this *MetadataManager) List(session *mcclient.ClientSession, params jsonutils.JSONObject) (*modulebase.ListResult, error) {
mod, err := this.getModule(session, params)
if err != nil {
return nil, err
}
return mod.List(session, params)
}

func (this *MetadataManager) Get(session *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
mod, err := this.getModule(session, params)
if err != nil {
return nil, err
}
return mod.Get(session, id, params)
}
1 change: 1 addition & 0 deletions pkg/mcclient/options/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package options

type MetadataListOptions struct {
Resources []string `help:"list of resource e.g server、disk、eip、snapshot, empty will show all metadata"`
Service string `help:"service type" default:"compute"`

SysMeta *bool `help:"Show sys metadata only"`
CloudMeta *bool `help:"Show cloud metadata olny"`
Expand Down

0 comments on commit f01bed8

Please sign in to comment.