fix: 支持访问其他服务的标签列表

This commit is contained in:
Qu Xuan
2020-05-11 21:39:32 +08:00
parent 1403fae69b
commit f01bed833d
2 changed files with 47 additions and 4 deletions
+46 -4
View File
@@ -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
View File
@@ -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"`