baremetalnetworks.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 HostNetworkListOptions struct {
  24. options.BaseListOptions
  25. Host string `help:"ID or Name of Host"`
  26. Network string `help:"ID or name of network"`
  27. }
  28. R(&HostNetworkListOptions{}, "host-network-list", "List baremetal network pairs", func(s *mcclient.ClientSession, args *HostNetworkListOptions) 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. if len(args.Network) > 0 {
  38. params.Add(jsonutils.NewString(args.Network), "network_id")
  39. }
  40. var result *printutils.ListResult
  41. var err error
  42. if len(args.Host) > 0 {
  43. result, err = modules.Baremetalnetworks.ListDescendent(s, args.Host, params)
  44. } else {
  45. result, err = modules.Baremetalnetworks.List(s, params)
  46. }
  47. if err != nil {
  48. return err
  49. }
  50. printList(result, modules.Baremetalnetworks.GetColumns(s))
  51. return nil
  52. })
  53. type HostNetworkDetailOptions struct {
  54. HOST string `help:"ID or Name of Host"`
  55. NETWORK string `help:"ID or Name of Wire"`
  56. }
  57. R(&HostNetworkDetailOptions{}, "host-network-show", "Show baremetal network details", func(s *mcclient.ClientSession, args *HostNetworkDetailOptions) error {
  58. result, err := modules.Baremetalnetworks.Get(s, args.HOST, args.NETWORK, nil)
  59. if err != nil {
  60. return err
  61. }
  62. printObject(result)
  63. return nil
  64. })
  65. }