vpc.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. "fmt"
  17. "yunion.io/x/jsonutils"
  18. baseoptions "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type VpcListOptions struct {
  21. baseoptions.BaseListOptions
  22. Usable *bool `help:"Filter usable vpcs"`
  23. Region string `help:"ID or Name of region" json:"-"`
  24. Globalvpc string `help:"Filter by globalvpc"`
  25. DnsZoneId string `help:"Filter by DnsZone"`
  26. InterVpcNetworkId string `help:"Filter by InterVpcNetwork"`
  27. ExternalAccessMode string `help:"Filter by external access mode" choices:"distgw|eip|eip-distgw"`
  28. ZoneId string `help:"Filter by zone which has networks"`
  29. UsableForInterVpcNetworkId string `help:"Filter usable vpcs for inter vpc network"`
  30. OrderByWireCount string
  31. CidrBlock string `help:"IPv4 cidr block"`
  32. CidrBlock6 string `help:"IPv6 cidr block"`
  33. }
  34. func (opts *VpcListOptions) GetContextId() string {
  35. return opts.Region
  36. }
  37. func (opts *VpcListOptions) Params() (jsonutils.JSONObject, error) {
  38. return baseoptions.ListStructToParams(opts)
  39. }
  40. type VpcCreateOptions struct {
  41. REGION string `help:"ID or name of the region where the VPC is created" json:"cloudregion_id"`
  42. Id string `help:"ID of the new VPC"`
  43. NAME string `help:"Name of the VPC" json:"name"`
  44. CIDR string `help:"CIDR block"`
  45. CIDR6 string `help:"IPv6 CIDR block"`
  46. Default bool `help:"default VPC for the region" default:"false"`
  47. Desc string `help:"Description of the VPC"`
  48. Manager string `help:"ID or Name of Cloud provider" json:"manager_id"`
  49. ExternalAccessMode string `help:"Filter by external access mode" choices:"distgw|eip|eip-distgw" default:""`
  50. GlobalvpcId string `help:"Global vpc id, Only for Google Cloud"`
  51. }
  52. func (opts *VpcCreateOptions) Params() (jsonutils.JSONObject, error) {
  53. params := jsonutils.NewDict()
  54. params.Add(jsonutils.NewString(opts.REGION), "cloudregion_id")
  55. params.Add(jsonutils.NewString(opts.NAME), "name")
  56. params.Add(jsonutils.NewString(opts.CIDR), "cidr_block")
  57. if len(opts.CIDR6) > 0 {
  58. params.Add(jsonutils.NewString(opts.CIDR6), "cidr_block6")
  59. }
  60. if len(opts.Id) > 0 {
  61. params.Add(jsonutils.NewString(opts.Id), "id")
  62. }
  63. if len(opts.ExternalAccessMode) > 0 {
  64. params.Add(jsonutils.NewString(opts.ExternalAccessMode), "external_access_mode")
  65. }
  66. if len(opts.Desc) > 0 {
  67. params.Add(jsonutils.NewString(opts.Desc), "description")
  68. }
  69. if opts.Default {
  70. params.Add(jsonutils.JSONTrue, "is_default")
  71. }
  72. if len(opts.Manager) > 0 {
  73. params.Add(jsonutils.NewString(opts.Manager), "manager_id")
  74. }
  75. if len(opts.GlobalvpcId) > 0 {
  76. params.Add(jsonutils.NewString(opts.GlobalvpcId), "globalvpc_id")
  77. }
  78. return params, nil
  79. }
  80. type VpcIdOptions struct {
  81. ID string `help:"ID or name of the vpc"`
  82. }
  83. func (opts *VpcIdOptions) GetId() string {
  84. return opts.ID
  85. }
  86. func (opts *VpcIdOptions) Params() (jsonutils.JSONObject, error) {
  87. return nil, nil
  88. }
  89. type VpcUpdateOptions struct {
  90. baseoptions.BaseUpdateOptions
  91. ExternalAccessMode string `help:"Filter by external access mode" choices:"distgw|eip|eip-distgw|none"`
  92. Direct bool `help:"Can it be connected directly"`
  93. CidrBlock string `help:"IPv4 CIDR block"`
  94. CidrBlock6 string `help:"IPv6 CIDR block"`
  95. }
  96. func (opts *VpcUpdateOptions) Params() (jsonutils.JSONObject, error) {
  97. params := jsonutils.Marshal(opts).(*jsonutils.JSONDict)
  98. return params, nil
  99. }
  100. type VpcStatusOptions struct {
  101. VpcIdOptions
  102. STATUS string `help:"Set Vpc status" choices:"available|pending"`
  103. }
  104. func (opts *VpcStatusOptions) Params() (jsonutils.JSONObject, error) {
  105. return jsonutils.Marshal(map[string]string{"status": opts.STATUS}), nil
  106. }
  107. type VpcChangeOwnerOptions struct {
  108. VpcIdOptions
  109. ProjectDomain string `json:"project_domain" help:"target domain"`
  110. }
  111. func (opts *VpcChangeOwnerOptions) Params() (jsonutils.JSONObject, error) {
  112. if len(opts.ProjectDomain) == 0 {
  113. return nil, fmt.Errorf("empty project_domain")
  114. }
  115. return jsonutils.Marshal(map[string]string{"project_domain": opts.ProjectDomain}), nil
  116. }