mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: 支持访问其他服务的标签列表
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user