routers.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.RouterCreateOptions{}, "router-create", "Create router", func(s *mcclient.ClientSession, opts *options.RouterCreateOptions) error {
  23. params, err := opts.Params()
  24. if err != nil {
  25. return err
  26. }
  27. router, err := modules.Routers.Create(s, params)
  28. if err != nil {
  29. return err
  30. }
  31. printObject(router)
  32. return nil
  33. })
  34. R(&options.RouterGetOptions{}, "router-show", "Show router", func(s *mcclient.ClientSession, opts *options.RouterGetOptions) error {
  35. router, err := modules.Routers.Get(s, opts.ID, nil)
  36. if err != nil {
  37. return err
  38. }
  39. printObject(router)
  40. return nil
  41. })
  42. R(&options.RouterListOptions{}, "router-list", "List routers", func(s *mcclient.ClientSession, opts *options.RouterListOptions) error {
  43. params, err := base_options.ListStructToParams(opts)
  44. if err != nil {
  45. return err
  46. }
  47. result, err := modules.Routers.List(s, params)
  48. if err != nil {
  49. return err
  50. }
  51. printList(result, modules.Routers.GetColumns(s))
  52. return nil
  53. })
  54. R(&options.RouterUpdateOptions{}, "router-update", "Update router", func(s *mcclient.ClientSession, opts *options.RouterUpdateOptions) error {
  55. params, err := base_options.StructToParams(opts)
  56. router, err := modules.Routers.Update(s, opts.ID, params)
  57. if err != nil {
  58. return err
  59. }
  60. printObject(router)
  61. return nil
  62. })
  63. R(&options.RouterDeleteOptions{}, "router-delete", "Delete router", func(s *mcclient.ClientSession, opts *options.RouterDeleteOptions) error {
  64. router, err := modules.Routers.Delete(s, opts.ID, nil)
  65. if err != nil {
  66. return err
  67. }
  68. printObject(router)
  69. return nil
  70. })
  71. R(&options.RouterActionJoinMeshNetworkOptions{}, "router-join-meshnetwork", "Router join meshnetwork", func(s *mcclient.ClientSession, opts *options.RouterActionJoinMeshNetworkOptions) error {
  72. params, err := base_options.StructToParams(opts)
  73. if err != nil {
  74. return err
  75. }
  76. router, err := modules.Routers.PerformAction(s, opts.ID, "join-mesh-network", params)
  77. if err != nil {
  78. return err
  79. }
  80. printObject(router)
  81. return nil
  82. })
  83. R(&options.RouterActionLeaveMeshNetworkOptions{}, "router-leave-meshnetwork", "Router leave meshnetwork", func(s *mcclient.ClientSession, opts *options.RouterActionLeaveMeshNetworkOptions) error {
  84. params, err := base_options.StructToParams(opts)
  85. if err != nil {
  86. return err
  87. }
  88. router, err := modules.Routers.PerformAction(s, opts.ID, "leave-mesh-network", params)
  89. if err != nil {
  90. return err
  91. }
  92. printObject(router)
  93. return nil
  94. })
  95. R(&options.RouterActionRegisterIfnameOptions{}, "router-register-ifname", "Router register new ifname", func(s *mcclient.ClientSession, opts *options.RouterActionRegisterIfnameOptions) error {
  96. params, err := base_options.StructToParams(opts)
  97. if err != nil {
  98. return err
  99. }
  100. router, err := modules.Routers.PerformAction(s, opts.ID, "register-ifname", params)
  101. if err != nil {
  102. return err
  103. }
  104. printObject(router)
  105. return nil
  106. })
  107. R(&options.RouterActionUnregisterIfnameOptions{}, "router-unregister-ifname", "Router unregister ifname", func(s *mcclient.ClientSession, opts *options.RouterActionUnregisterIfnameOptions) error {
  108. params, err := base_options.StructToParams(opts)
  109. if err != nil {
  110. return err
  111. }
  112. router, err := modules.Routers.PerformAction(s, opts.ID, "unregister-ifname", params)
  113. if err != nil {
  114. return err
  115. }
  116. printObject(router)
  117. return nil
  118. })
  119. R(&options.RouterActionRealizeOptions{}, "router-realize", "Router realize", func(s *mcclient.ClientSession, opts *options.RouterActionRealizeOptions) error {
  120. params, err := base_options.StructToParams(opts)
  121. if err != nil {
  122. return err
  123. }
  124. router, err := modules.Routers.PerformAction(s, opts.ID, "realize", params)
  125. if err != nil {
  126. return err
  127. }
  128. printObject(router)
  129. return nil
  130. })
  131. }