loadbalancerclusters.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/onecloud/pkg/mcclient"
  17. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  18. options "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  19. )
  20. func init() {
  21. R(&options.LoadbalancerClusterCreateOptions{}, "lbcluster-create", "Create lbcluster", func(s *mcclient.ClientSession, opts *options.LoadbalancerClusterCreateOptions) error {
  22. params, err := opts.Params()
  23. if err != nil {
  24. return err
  25. }
  26. lbcluster, err := modules.LoadbalancerClusters.Create(s, params)
  27. if err != nil {
  28. return err
  29. }
  30. printObject(lbcluster)
  31. return nil
  32. })
  33. R(&options.LoadbalancerClusterUpdateOptions{}, "lbcluster-update", "Update lbcluster", func(s *mcclient.ClientSession, opts *options.LoadbalancerClusterUpdateOptions) error {
  34. params, err := opts.Params()
  35. if err != nil {
  36. return err
  37. }
  38. lbcluster, err := modules.LoadbalancerClusters.Update(s, opts.ID, params)
  39. if err != nil {
  40. return err
  41. }
  42. printObject(lbcluster)
  43. return nil
  44. })
  45. R(&options.LoadbalancerClusterGetOptions{}, "lbcluster-show", "Show lbcluster", func(s *mcclient.ClientSession, opts *options.LoadbalancerClusterGetOptions) error {
  46. lbcluster, err := modules.LoadbalancerClusters.Get(s, opts.ID, nil)
  47. if err != nil {
  48. return err
  49. }
  50. printObject(lbcluster)
  51. return nil
  52. })
  53. R(&options.LoadbalancerClusterListOptions{}, "lbcluster-list", "List lbclusters", func(s *mcclient.ClientSession, opts *options.LoadbalancerClusterListOptions) error {
  54. params, err := opts.Params()
  55. if err != nil {
  56. return err
  57. }
  58. result, err := modules.LoadbalancerClusters.List(s, params)
  59. if err != nil {
  60. return err
  61. }
  62. printList(result, modules.LoadbalancerClusters.GetColumns(s))
  63. return nil
  64. })
  65. R(&options.LoadbalancerClusterDeleteOptions{}, "lbcluster-delete", "Delete lbcluster", func(s *mcclient.ClientSession, opts *options.LoadbalancerClusterDeleteOptions) error {
  66. lbagent, err := modules.LoadbalancerClusters.Delete(s, opts.ID, nil)
  67. if err != nil {
  68. return err
  69. }
  70. printObject(lbagent)
  71. return nil
  72. })
  73. }