metadata.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/pkg/util/printutils"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. )
  22. func init() {
  23. R(&options.MetadataListOptions{}, "metadata-list", "List metadatas", func(s *mcclient.ClientSession, opts *options.MetadataListOptions) error {
  24. params, err := options.ListStructToParams(opts)
  25. if err != nil {
  26. return err
  27. }
  28. result, err := modules.ComputeMetadatas.List(s, params)
  29. if err != nil {
  30. return err
  31. }
  32. printList(result, []string{})
  33. return nil
  34. })
  35. R(&options.TagListOptions{}, "service-metadata-list", "List service metadata", func(s *mcclient.ClientSession, opts *options.TagListOptions) error {
  36. var mod modulebase.IResourceManager
  37. switch opts.Service {
  38. case "compute":
  39. mod = &modules.ComputeMetadatas
  40. case "identity":
  41. mod = &modules.IdentityMetadatas
  42. case "image":
  43. mod = &modules.ImageMetadatas
  44. default:
  45. mod = &modules.ComputeMetadatas
  46. }
  47. params, err := options.ListStructToParams(opts)
  48. if err != nil {
  49. return err
  50. }
  51. result, err := mod.Get(s, "tag-value-pairs", params)
  52. if err != nil {
  53. return err
  54. }
  55. listResult := printutils.ListResult{}
  56. err = result.Unmarshal(&listResult)
  57. if err != nil {
  58. return err
  59. }
  60. printList(&listResult, []string{})
  61. return nil
  62. })
  63. }