storagecachedimages.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/jsonutils"
  17. "yunion.io/x/pkg/util/printutils"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. )
  22. func init() {
  23. type StorageCachedImageListOptions struct {
  24. options.BaseListOptions
  25. Storagecache string `help:"ID or Name of Storage"`
  26. Image string `help:"ID or Name of image"`
  27. }
  28. R(&StorageCachedImageListOptions{}, "storage-cached-image-list", "List storage cached image pairs", func(s *mcclient.ClientSession, args *StorageCachedImageListOptions) error {
  29. var params *jsonutils.JSONDict
  30. {
  31. var err error
  32. params, err = args.BaseListOptions.Params()
  33. if err != nil {
  34. return err
  35. }
  36. }
  37. var result *printutils.ListResult
  38. var err error
  39. if len(args.Storagecache) > 0 {
  40. result, err = modules.Storagecachedimages.ListDescendent(s, args.Storagecache, params)
  41. } else if len(args.Image) > 0 {
  42. result, err = modules.Storagecachedimages.ListDescendent2(s, args.Image, params)
  43. } else {
  44. result, err = modules.Storagecachedimages.List(s, params)
  45. }
  46. if err != nil {
  47. return err
  48. }
  49. printList(result, modules.Storagecachedimages.GetColumns(s))
  50. return nil
  51. })
  52. type StorageCachedImageUpdateOptions struct {
  53. STORAGECACHE string `help:"ID or Name of Storage cache"`
  54. IMAGE string `help:"ID or name of image"`
  55. Status string `help:"Status"`
  56. }
  57. R(&StorageCachedImageUpdateOptions{}, "storage-cached-image-update", "Update storage cached image", func(s *mcclient.ClientSession, args *StorageCachedImageUpdateOptions) error {
  58. params := jsonutils.NewDict()
  59. if len(args.Status) > 0 {
  60. params.Add(jsonutils.NewString(args.Status), "status")
  61. }
  62. if params.Size() == 0 {
  63. return InvalidUpdateError()
  64. }
  65. result, err := modules.Storagecachedimages.Update(s, args.STORAGECACHE, args.IMAGE, nil, params)
  66. if err != nil {
  67. return err
  68. }
  69. printObject(result)
  70. return nil
  71. })
  72. type StorageCachedImageShowOptions struct {
  73. STORAGECACHE string `help:"ID or Name of Storage cache"`
  74. IMAGE string `help:"ID or name of image"`
  75. }
  76. R(&StorageCachedImageShowOptions{}, "storage-cached-image-show", "Show storage cached image", func(s *mcclient.ClientSession, args *StorageCachedImageShowOptions) error {
  77. result, err := modules.Storagecachedimages.Get(s, args.STORAGECACHE, args.IMAGE, nil)
  78. if err != nil {
  79. return err
  80. }
  81. printObject(result)
  82. return nil
  83. })
  84. }