meshnetworks.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 cloudnet
  15. import (
  16. "yunion.io/x/onecloud/pkg/mcclient"
  17. modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudnet"
  18. base_options "yunion.io/x/onecloud/pkg/mcclient/options"
  19. options "yunion.io/x/onecloud/pkg/mcclient/options/cloudnet"
  20. )
  21. func init() {
  22. R(&options.MeshNetworkCreateOptions{}, "meshnetwork-create", "Create mesh network", func(s *mcclient.ClientSession, opts *options.MeshNetworkCreateOptions) error {
  23. params, err := base_options.StructToParams(opts)
  24. if err != nil {
  25. return err
  26. }
  27. mn, err := modules.MeshNetworks.Create(s, params)
  28. if err != nil {
  29. return err
  30. }
  31. printObject(mn)
  32. return nil
  33. })
  34. R(&options.MeshNetworkGetOptions{}, "meshnetwork-show", "Show mesh network", func(s *mcclient.ClientSession, opts *options.MeshNetworkGetOptions) error {
  35. mn, err := modules.MeshNetworks.Get(s, opts.ID, nil)
  36. if err != nil {
  37. return err
  38. }
  39. printObject(mn)
  40. return nil
  41. })
  42. R(&options.MeshNetworkListOptions{}, "meshnetwork-list", "List mesh networks", func(s *mcclient.ClientSession, opts *options.MeshNetworkListOptions) error {
  43. params, err := base_options.ListStructToParams(opts)
  44. if err != nil {
  45. return err
  46. }
  47. result, err := modules.MeshNetworks.List(s, params)
  48. if err != nil {
  49. return err
  50. }
  51. printList(result, modules.MeshNetworks.GetColumns(s))
  52. return nil
  53. })
  54. R(&options.MeshNetworkUpdateOptions{}, "meshnetwork-update", "Update mesh network", func(s *mcclient.ClientSession, opts *options.MeshNetworkUpdateOptions) error {
  55. params, err := base_options.StructToParams(opts)
  56. mn, err := modules.MeshNetworks.Update(s, opts.ID, params)
  57. if err != nil {
  58. return err
  59. }
  60. printObject(mn)
  61. return nil
  62. })
  63. R(&options.MeshNetworkDeleteOptions{}, "meshnetwork-delete", "Delete mesh network", func(s *mcclient.ClientSession, opts *options.MeshNetworkDeleteOptions) error {
  64. mn, err := modules.MeshNetworks.Delete(s, opts.ID, nil)
  65. if err != nil {
  66. return err
  67. }
  68. printObject(mn)
  69. return nil
  70. })
  71. R(&options.MeshNetworkActionRealizeOptions{}, "meshnetwork-realize", "Realize mesh network", func(s *mcclient.ClientSession, opts *options.MeshNetworkActionRealizeOptions) error {
  72. mn, err := modules.MeshNetworks.PerformAction(s, opts.ID, "realize", nil)
  73. if err != nil {
  74. return err
  75. }
  76. printObject(mn)
  77. return nil
  78. })
  79. }