baremetalstorages.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 BaremetalStorageListOptions struct {
  24. options.BaseListOptions
  25. Host string `help:"ID or Name of Host"`
  26. }
  27. R(&BaremetalStorageListOptions{}, "baremetal-storage-list", "List baremetal storage pairs", func(s *mcclient.ClientSession, args *BaremetalStorageListOptions) error {
  28. var params *jsonutils.JSONDict
  29. {
  30. var err error
  31. params, err = args.BaseListOptions.Params()
  32. if err != nil {
  33. return err
  34. }
  35. }
  36. var result *printutils.ListResult
  37. var err error
  38. if len(args.Host) > 0 {
  39. result, err = modules.Baremetalstorages.ListDescendent(s, args.Host, params)
  40. } else {
  41. result, err = modules.Baremetalstorages.List(s, params)
  42. }
  43. if err != nil {
  44. return err
  45. }
  46. printList(result, modules.Baremetalstorages.GetColumns(s))
  47. return nil
  48. })
  49. type BaremetalStorageDetailOptions struct {
  50. HOST string `help:"ID or Name of Host"`
  51. STORAGE string `help:"ID or Name of Storage"`
  52. }
  53. R(&BaremetalStorageDetailOptions{}, "baremetal-storage-show", "Show baremetal storage details", func(s *mcclient.ClientSession, args *BaremetalStorageDetailOptions) error {
  54. result, err := modules.Baremetalstorages.Get(s, args.HOST, args.STORAGE, nil)
  55. if err != nil {
  56. return err
  57. }
  58. printObject(result)
  59. return nil
  60. })
  61. }