hostcachedimages.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 HostCachedImageListOptions struct {
  24. options.BaseListOptions
  25. Host string `help:"ID or Name of Host"`
  26. Image string `help:"ID or Name of image"`
  27. }
  28. R(&HostCachedImageListOptions{}, "host-cachedimage-list", "List host cached image pairs", func(s *mcclient.ClientSession, args *HostCachedImageListOptions) 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.Host) > 0 {
  40. result, err = modules.Hostcachedimages.ListDescendent(s, args.Host, params)
  41. } else {
  42. result, err = modules.Hostcachedimages.List(s, params)
  43. }
  44. if err != nil {
  45. return err
  46. }
  47. printList(result, modules.Hostcachedimages.GetColumns(s))
  48. return nil
  49. })
  50. type HostCachedImageUpdateOptions struct {
  51. HOST string `help:"ID or Name of Host"`
  52. IMAGE string `help:"ID or name of image"`
  53. Status string `help:"Status"`
  54. }
  55. R(&HostCachedImageUpdateOptions{}, "host-cachedimage-update", "Update host cached image", func(s *mcclient.ClientSession, args *HostCachedImageUpdateOptions) error {
  56. params := jsonutils.NewDict()
  57. if len(args.Status) > 0 {
  58. params.Add(jsonutils.NewString(args.Status), "status")
  59. }
  60. if params.Size() == 0 {
  61. return InvalidUpdateError()
  62. }
  63. result, err := modules.Hostcachedimages.Update(s, args.HOST, args.IMAGE, nil, params)
  64. if err != nil {
  65. return err
  66. }
  67. printObject(result)
  68. return nil
  69. })
  70. }