loadbalancernetworks.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 LoadbalancerNetworkListOptions struct {
  24. options.BaseListOptions
  25. Loadbalancer string `help:"ID or Name of Loadbalancer"`
  26. Network string `help:"ID or Name of network"`
  27. Ip string `help:"search the IP address"`
  28. }
  29. R(&LoadbalancerNetworkListOptions{}, "lbnetwork-list", "List loadbalancer network pairs", func(s *mcclient.ClientSession, args *LoadbalancerNetworkListOptions) error {
  30. var params *jsonutils.JSONDict
  31. {
  32. var err error
  33. params, err = args.BaseListOptions.Params()
  34. if err != nil {
  35. return err
  36. }
  37. }
  38. if len(args.Ip) > 0 {
  39. params.Add(jsonutils.NewString(args.Ip), "ip_addr")
  40. }
  41. var result *printutils.ListResult
  42. var err error
  43. if len(args.Loadbalancer) > 0 {
  44. result, err = modules.Loadbalancernetworks.ListDescendent(s, args.Loadbalancer, params)
  45. } else if len(args.Network) > 0 {
  46. result, err = modules.Loadbalancernetworks.ListDescendent2(s, args.Network, params)
  47. } else {
  48. result, err = modules.Loadbalancernetworks.List(s, params)
  49. }
  50. if err != nil {
  51. return err
  52. }
  53. printList(result, modules.Loadbalancernetworks.GetColumns(s))
  54. return nil
  55. })
  56. }