eips.go 4.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 compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient/options"
  18. )
  19. type ElasticipListOptions struct {
  20. Region string `help:"List eips in cloudregion"`
  21. Usable *bool `help:"List all zones that is usable"`
  22. UsableEipForAssociateType string `help:"With associate id filter which eip can associate" choices:"server|natgateway|loadbalancer"`
  23. UsableEipForAssociateId string `help:"With associate type filter which eip can associate"`
  24. OrderByIp string
  25. AssociateId []string
  26. AssociateType []string
  27. AssociateName []string
  28. IsAssociated *bool
  29. IpAddr []string
  30. options.BaseListOptions
  31. }
  32. func (opts *ElasticipListOptions) Params() (jsonutils.JSONObject, error) {
  33. return options.ListStructToParams(opts)
  34. }
  35. type EipCreateOptions struct {
  36. options.BaseCreateOptions
  37. Manager *string `help:"cloud provider"`
  38. Region *string `help:"cloud region in which EIP is allocated"`
  39. Bandwidth *int `help:"Bandwidth in Mbps"`
  40. IpAddr *string `help:"IP address of the EIP" json:"ip_addr"`
  41. Network *string `help:"Network of the EIP"`
  42. BgpType *string `help:"BgpType of the EIP" positional:"false" choices:"BGP|BGP_PRO"`
  43. ChargeType *string `help:"bandwidth charge type" choices:"traffic|bandwidth"`
  44. }
  45. func (opts *EipCreateOptions) Params() (jsonutils.JSONObject, error) {
  46. return jsonutils.Marshal(opts), nil
  47. }
  48. type EipUpdateOptions struct {
  49. options.BaseUpdateOptions
  50. AutoDellocate *string `help:"enable or disable automatically dellocate when dissociate from instance" choices:"true|false"`
  51. IpAddr string
  52. AssociateId string
  53. AssociateType string
  54. }
  55. func (opts *EipUpdateOptions) Params() (jsonutils.JSONObject, error) {
  56. return jsonutils.Marshal(opts), nil
  57. }
  58. type EipAssociateOptions struct {
  59. options.BaseIdOptions
  60. INSTANCE_ID string `help:"ID of instance the eip associated with"`
  61. InstanceType string `default:"server" help:"Instance type that the eip associated with, default is server" choices:"server|natgateway|loadbalancer"`
  62. }
  63. func (opts *EipAssociateOptions) Params() (jsonutils.JSONObject, error) {
  64. return jsonutils.Marshal(map[string]string{"instance_id": opts.INSTANCE_ID, "instance_type": opts.InstanceType}), nil
  65. }
  66. type EipDissociateOptions struct {
  67. options.BaseIdOptions
  68. AutoDelete bool `help:"automatically delete the dissociate EIP" json:"auto_delete,omitfalse"`
  69. }
  70. func (opts *EipDissociateOptions) Params() (jsonutils.JSONObject, error) {
  71. return jsonutils.Marshal(map[string]bool{"auto_delete": opts.AutoDelete}), nil
  72. }
  73. type EipChangeBandwidthOptions struct {
  74. options.BaseIdOptions
  75. BANDWIDTH int `help:"new bandwidth of EIP"`
  76. }
  77. func (opts *EipChangeBandwidthOptions) Params() (jsonutils.JSONObject, error) {
  78. return jsonutils.Marshal(map[string]int{"bandwidth": opts.BANDWIDTH}), nil
  79. }
  80. type EipChangeOwnerOptions struct {
  81. options.BaseIdOptions
  82. PROJECT string `help:"Project ID or change"`
  83. //RawId bool `help:"User raw ID, instead of name"`
  84. }
  85. func (opts *EipChangeOwnerOptions) Params() (jsonutils.JSONObject, error) {
  86. return jsonutils.Marshal(map[string]string{"tenant": opts.PROJECT}), nil
  87. /*
  88. params := jsonutils.NewDict()
  89. if opts.RawId {
  90. projid, err := modules.Projects.GetId(s, opts.PROJECT, nil)
  91. if err != nil {
  92. return err
  93. }
  94. params.Add(jsonutils.NewString(projid), "tenant")
  95. params.Add(jsonutils.JSONTrue, "raw_id")
  96. } else {
  97. params.Add(jsonutils.NewString(opts.PROJECT), "tenant")
  98. }
  99. */
  100. }