github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vpc/v1/publicips/requests.go (about) 1 package publicips 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 type PublicIPRequest struct { 9 // Specifies the type of the elastic IP address. The value can the 10 // 5_telcom, 5_union, 5_bgp, or 5_sbgp. China Northeast: 5_telcom and 5_union China 11 // South: 5_sbgp China East: 5_sbgp China North: 5_bgp and 5_sbgp The value must be a 12 // type supported by the system. The value can be 5_telcom, 5_union, or 5_bgp. 13 Type string `json:"type" required:"true"` 14 15 // Specifies the elastic IP address to be obtained. The value must 16 // be a valid IP address in the available IP address segment. 17 IpAddress string `json:"ip_address,omitempty"` 18 19 //Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default 20 IPVersion int `json:"ip_version,omitempty"` 21 } 22 23 type BandWidth struct { 24 // Specifies the bandwidth name. The value is a string of 1 to 64 25 // characters that can contain letters, digits, underscores (_), and hyphens (-). This 26 // parameter is mandatory when share_type is set to PER and is optional when share_type 27 // is set to WHOLE with an ID specified. 28 Name string `json:"name,omitempty"` 29 30 // Specifies the bandwidth size. The value ranges from 1 Mbit/s to 31 // 300 Mbit/s. This parameter is mandatory when share_type is set to PER and is optional 32 // when share_type is set to WHOLE with an ID specified. 33 Size int `json:"size,omitempty"` 34 35 // Specifies the ID of the bandwidth. You can specify an earlier 36 // shared bandwidth when applying for an elastic IP address for the bandwidth whose type 37 // is set to WHOLE. The bandwidth whose type is set to WHOLE exclusively uses its own 38 // ID. The value can be the ID of the bandwidth whose type is set to WHOLE. 39 ID string `json:"id,omitempty"` 40 41 // Specifies whether the bandwidth is shared or exclusive. The 42 // value can be PER or WHOLE. 43 ShareType string `json:"share_type" required:"true"` 44 45 // Specifies the charging mode (by traffic or by bandwidth). The 46 // value can be bandwidth or traffic. If the value is an empty character string or no 47 // value is specified, default value bandwidth is used. 48 ChargeMode string `json:"charge_mode,omitempty"` 49 } 50 51 type CreateOpts struct { 52 // Specifies the elastic IP address objects. 53 Publicip PublicIPRequest `json:"publicip" required:"true"` 54 55 // Specifies the bandwidth objects. 56 Bandwidth BandWidth `json:"bandwidth" required:"true"` 57 // Enterprise project ID. The maximum length is 36 bytes, with the U-ID format of the hyphen "-", or the string "0". 58 //When creating an elastic public IP address, bind the enterprise project ID to the elastic public network IP. 59 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 60 } 61 62 type CreateOptsBuilder interface { 63 ToCreatePublicIPMap() (map[string]interface{}, error) 64 } 65 66 func (opts CreateOpts) ToCreatePublicIPMap() (map[string]interface{}, error) { 67 b, err := golangsdk.BuildRequestBody(opts, "") 68 if err != nil { 69 return nil, err 70 } 71 return b, nil 72 } 73 74 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 75 b, err := opts.ToCreatePublicIPMap() 76 if err != nil { 77 r.Err = err 78 return 79 } 80 81 _, r.Err = client.Post(CreateURL(client), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 82 return 83 } 84 85 func Delete(client *golangsdk.ServiceClient, publicipId string) (r DeleteResult) { 86 url := DeleteURL(client, publicipId) 87 _, r.Err = client.Delete(url, nil) 88 return 89 } 90 91 func Get(client *golangsdk.ServiceClient, publicipId string) (r GetResult) { 92 url := GetURL(client, publicipId) 93 _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{}) 94 return 95 } 96 97 type ListOpts struct { 98 // Specifies the resource ID of pagination query. If the parameter 99 // is left blank, only resources on the first page are queried. 100 Marker string `q:"marker"` 101 102 // Specifies the number of records returned on each page. The 103 // value ranges from 0 to intmax. 104 Limit int `q:"limit"` 105 106 // Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default 107 IPVersion int `q:"ip_version"` 108 109 // Associated port id 110 PortId string `q:"port_id"` 111 112 // Public IP address 113 PublicIp string `q:"public_ip_address"` 114 115 // enterprise_project_id 116 // You can use this field to filter the elastic public IP under an enterprise project. 117 EnterpriseProjectId string `q:"enterprise_project_id"` 118 } 119 120 type ListOptsBuilder interface { 121 ToListPublicIPQuery() (string, error) 122 } 123 124 func (opts ListOpts) ToListPublicIPQuery() (string, error) { 125 q, err := golangsdk.BuildQueryString(opts) 126 return q.String(), err 127 } 128 129 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 130 url := ListURL(client) 131 if opts != nil { 132 query, err := opts.ToListPublicIPQuery() 133 if err != nil { 134 return pagination.Pager{Err: err} 135 } 136 url += query 137 } 138 139 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 140 return PublicIPPage{pagination.LinkedPageBase{PageResult: r}} 141 }) 142 } 143 144 type UpdateOpts struct { 145 // Specifies the port ID. 146 PortId string `json:"port_id,omitempty"` 147 148 //Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default 149 IPVersion int `json:"ip_version,omitempty"` 150 } 151 152 type UpdateOptsBuilder interface { 153 ToUpdatePublicIPMap() (map[string]interface{}, error) 154 } 155 156 func (opts UpdateOpts) ToUpdatePublicIPMap() (map[string]interface{}, error) { 157 b, err := golangsdk.BuildRequestBody(opts, "publicip") 158 if err != nil { 159 return nil, err 160 } 161 return b, nil 162 } 163 164 func Update(client *golangsdk.ServiceClient, publicipId string, opts UpdateOptsBuilder) (r UpdateResult) { 165 b, err := opts.ToUpdatePublicIPMap() 166 if err != nil { 167 r.Err = err 168 return 169 } 170 171 _, r.Err = client.Put(UpdateURL(client, publicipId), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 172 return 173 }