routers.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. "io/ioutil"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type RouterCreateOptions struct {
  21. NAME string
  22. User string
  23. Host string
  24. Port int
  25. PrivateKey string
  26. RealizeWgIfaces string `choices:"on|off" default:"on" help:"apply wg ifaces config on realization"`
  27. RealizeRoutes string `choices:"on|off" default:"on" help:"apply routes config on realization"`
  28. RealizeRules string `choices:"on|off" default:"on" help:"apply firewall rules on realization"`
  29. }
  30. func (opts *RouterCreateOptions) Params() (jsonutils.JSONObject, error) {
  31. params, err := options.StructToParams(opts)
  32. if err != nil {
  33. return nil, err
  34. }
  35. if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' {
  36. data, err := ioutil.ReadFile(opts.PrivateKey[1:])
  37. if err != nil {
  38. return nil, err
  39. }
  40. params.Set("private_key", jsonutils.NewString(string(data)))
  41. }
  42. return params, nil
  43. }
  44. type RouterGetOptions struct {
  45. ID string `json:"-"`
  46. }
  47. type RouterUpdateOptions struct {
  48. ID string `json:"-"`
  49. Name string
  50. User string
  51. Host string
  52. Port int `json:",omitzero"`
  53. PrivateKey string
  54. RealizeWgIfaces string `json:",omitzero" choices:"on|off" help:"apply wg ifaces config on realization"`
  55. RealizeRoutes string `json:",omitzero" choices:"on|off" help:"apply routes config on realization"`
  56. RealizeRules string `json:",omitzero" choices:"on|off" help:"apply firewall rules on realization"`
  57. }
  58. func (opts *RouterUpdateOptions) Params() (jsonutils.JSONObject, error) {
  59. params, err := options.StructToParams(opts)
  60. if err != nil {
  61. return nil, err
  62. }
  63. if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' {
  64. data, err := ioutil.ReadFile(opts.PrivateKey[1:])
  65. if err != nil {
  66. return nil, err
  67. }
  68. params.Set("private_key", jsonutils.NewString(string(data)))
  69. }
  70. return params, nil
  71. }
  72. type RouterDeleteOptions struct {
  73. ID string `json:"-"`
  74. }
  75. type RouterListOptions struct {
  76. options.BaseListOptions
  77. }
  78. type RouterActionJoinMeshNetworkOptions struct {
  79. ID string `json:"-"`
  80. MeshNetwork string
  81. AdvertiseSubnets string `help:"cidr concatenated by comma"`
  82. }
  83. type RouterActionLeaveMeshNetworkOptions struct {
  84. ID string `json:"-"`
  85. MeshNetwork string
  86. }
  87. type RouterActionRegisterIfnameOptions struct {
  88. ID string `json:"-"`
  89. Ifname string
  90. }
  91. type RouterActionUnregisterIfnameOptions struct {
  92. ID string `json:"-"`
  93. Ifname string
  94. }
  95. type RouterActionRealizeOptions struct {
  96. ID string `json:"-"`
  97. }