isolated_device_models.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/cmd/climc/shell"
  19. "yunion.io/x/onecloud/pkg/mcclient"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  21. baseoptions "yunion.io/x/onecloud/pkg/mcclient/options"
  22. options "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  23. )
  24. func init() {
  25. cmd := shell.NewResourceCmd(&modules.IsolatedDeviceModels)
  26. cmd.List(new(options.IsolatedDeviceModelListOptions))
  27. cmd.Create(new(options.IsolatedDeviceModelCreateOptions))
  28. cmd.Update(new(options.IsolatedDeviceModelUpdateOptions))
  29. cmd.Delete(new(options.IsolatedDeviceIdsOptions))
  30. cmd.Perform("set-hardware-info", new(options.IsolatedDeviceModelSetHardwareInfoOptions))
  31. cmd.Get("hardware-info", new(options.IsolatedDeviceIdsOptions))
  32. type HostIsolatedDeviceModelListOptions struct {
  33. baseoptions.BaseListOptions
  34. Host string `help:"ID or Name of Host"`
  35. IsolatedDeviceModel string `help:"ID or Name of Isolated device model"`
  36. }
  37. R(&HostIsolatedDeviceModelListOptions{}, "host-isolated-device-model-list",
  38. "List host Isolated device model pairs", func(s *mcclient.ClientSession, args *HostIsolatedDeviceModelListOptions) error {
  39. var params *jsonutils.JSONDict
  40. {
  41. var err error
  42. params, err = args.BaseListOptions.Params()
  43. if err != nil {
  44. return err
  45. }
  46. }
  47. var result *printutils.ListResult
  48. var err error
  49. if len(args.Host) > 0 {
  50. result, err = modules.HostIsolatedDeviceModels.ListDescendent(s, args.Host, params)
  51. } else if len(args.IsolatedDeviceModel) > 0 {
  52. result, err = modules.HostIsolatedDeviceModels.ListDescendent2(s, args.IsolatedDeviceModel, params)
  53. } else {
  54. result, err = modules.HostIsolatedDeviceModels.List(s, params)
  55. }
  56. if err != nil {
  57. return err
  58. }
  59. printList(result, modules.HostIsolatedDeviceModels.GetColumns(s))
  60. return nil
  61. })
  62. type HostIsolatedDeviceModelDetailOptions struct {
  63. HOST string `help:"ID or Name of Host"`
  64. IsolatedDeviceModel string `help:"ID or Name of Isolated device model"`
  65. }
  66. R(&HostIsolatedDeviceModelDetailOptions{}, "host-isolated-device-model-show", "Show host isolated-device-model details", func(s *mcclient.ClientSession, args *HostIsolatedDeviceModelDetailOptions) error {
  67. result, err := modules.HostIsolatedDeviceModels.Get(s, args.HOST, args.IsolatedDeviceModel, nil)
  68. if err != nil {
  69. return err
  70. }
  71. printObject(result)
  72. return nil
  73. })
  74. R(&HostIsolatedDeviceModelDetailOptions{}, "host-isolated-device-model-detach", "Detach a isolated-device-model from a host", func(s *mcclient.ClientSession, args *HostIsolatedDeviceModelDetailOptions) error {
  75. result, err := modules.HostIsolatedDeviceModels.Detach(s, args.HOST, args.IsolatedDeviceModel, nil)
  76. if err != nil {
  77. return err
  78. }
  79. printObject(result)
  80. return nil
  81. })
  82. R(&HostIsolatedDeviceModelDetailOptions{}, "host-isolated-device-model-attach", "Attach a isolated-device-model to a host", func(s *mcclient.ClientSession, args *HostIsolatedDeviceModelDetailOptions) error {
  83. params := jsonutils.NewDict()
  84. result, err := modules.HostIsolatedDeviceModels.Attach(s, args.HOST, args.IsolatedDeviceModel, params)
  85. if err != nil {
  86. return err
  87. }
  88. printObject(result)
  89. return nil
  90. })
  91. }