proxy_endpoints.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 cloudproxy
  15. import (
  16. "io/ioutil"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type ProxyEndpointCreateOptions struct {
  21. NAME string
  22. User string
  23. Host string
  24. Port int `json:",omitzero"`
  25. PrivateKey string
  26. IntranetIpAddr string `required:"true"`
  27. }
  28. func (opts *ProxyEndpointCreateOptions) Params() (jsonutils.JSONObject, error) {
  29. params, err := options.StructToParams(opts)
  30. if err != nil {
  31. return nil, err
  32. }
  33. if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' {
  34. data, err := ioutil.ReadFile(opts.PrivateKey[1:])
  35. if err != nil {
  36. return nil, err
  37. }
  38. params.Set("private_key", jsonutils.NewString(string(data)))
  39. }
  40. return params, nil
  41. }
  42. type ProxyEndpointCreateFromServerOptions struct {
  43. Name string
  44. ServerId string `required:"true"`
  45. }
  46. func (opts *ProxyEndpointCreateFromServerOptions) Params() (jsonutils.JSONObject, error) {
  47. return options.StructToParams(opts)
  48. }
  49. type ProxyEndpointShowOptions struct {
  50. options.BaseShowOptions
  51. }
  52. type ProxyEndpointUpdateOptions struct {
  53. ID string `json:"-"`
  54. Name string
  55. User string
  56. Host string
  57. Port int `json:",omitzero"`
  58. PrivateKey string
  59. }
  60. func (opts *ProxyEndpointUpdateOptions) GetId() string {
  61. return opts.ID
  62. }
  63. func (opts *ProxyEndpointUpdateOptions) Params() (jsonutils.JSONObject, error) {
  64. params, err := options.StructToParams(opts)
  65. if err != nil {
  66. return nil, err
  67. }
  68. if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' {
  69. data, err := ioutil.ReadFile(opts.PrivateKey[1:])
  70. if err != nil {
  71. return nil, err
  72. }
  73. params.Set("private_key", jsonutils.NewString(string(data)))
  74. }
  75. return params, nil
  76. }
  77. type ProxyEndpointDeleteOptions struct {
  78. options.BaseShowOptions
  79. }
  80. type ProxyEndpointListOptions struct {
  81. options.BaseListOptions
  82. //User string
  83. Host string
  84. Port int `json:",omitzero"`
  85. VpcId string
  86. NetworkId string
  87. }
  88. func (opts *ProxyEndpointListOptions) Params() (jsonutils.JSONObject, error) {
  89. return options.ListStructToParams(opts)
  90. }