github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/eips/requests.go (about) 1 package eips 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/common/structs" 6 "github.com/huaweicloud/golangsdk/pagination" 7 ) 8 9 //ApplyOptsBuilder is an interface by which can build the request body of public ip 10 //application 11 type ApplyOptsBuilder interface { 12 ToPublicIpApplyMap() (map[string]interface{}, error) 13 } 14 15 //ApplyOpts is a struct which is used to create public ip 16 type ApplyOpts struct { 17 IP PublicIpOpts `json:"publicip" required:"true"` 18 Bandwidth BandwidthOpts `json:"bandwidth" required:"true"` 19 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 20 21 //ExtendParam is only valid by v2.0 client 22 ExtendParam *structs.ChargeInfo `json:"extendParam,omitempty"` 23 } 24 25 type PublicIpOpts struct { 26 Type string `json:"type" required:"true"` 27 Address string `json:"ip_address,omitempty"` 28 } 29 30 type BandwidthOpts struct { 31 Name string `json:"name,omitempty"` 32 Size int `json:"size,omitempty"` 33 Id string `json:"id,omitempty"` 34 ShareType string `json:"share_type" required:"true"` 35 ChargeMode string `json:"charge_mode,omitempty"` 36 } 37 38 func (opts ApplyOpts) ToPublicIpApplyMap() (map[string]interface{}, error) { 39 return golangsdk.BuildRequestBody(opts, "") 40 } 41 42 //Apply is a method by which can access to apply the public ip 43 func Apply(client *golangsdk.ServiceClient, opts ApplyOptsBuilder) (r ApplyResult) { 44 b, err := opts.ToPublicIpApplyMap() 45 if err != nil { 46 r.Err = err 47 return 48 } 49 _, r.Err = client.Post(rootURL(client), b, &r.Body, &golangsdk.RequestOpts{ 50 OkCodes: []int{200}, 51 }) 52 return 53 } 54 55 //Get is a method by which can get the detailed information of public ip 56 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 57 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 58 return 59 } 60 61 //Delete is a method by which can be able to delete a private ip 62 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 63 _, r.Err = client.Delete(resourceURL(client, id), nil) 64 return 65 } 66 67 //UpdateOptsBuilder is an interface by which can be able to build the request 68 //body 69 type UpdateOptsBuilder interface { 70 ToPublicIpUpdateMap() (map[string]interface{}, error) 71 } 72 73 //UpdateOpts is a struct which represents the request body of update method 74 type UpdateOpts struct { 75 PortID string `json:"port_id,omitempty"` 76 } 77 78 func (opts UpdateOpts) ToPublicIpUpdateMap() (map[string]interface{}, error) { 79 return golangsdk.BuildRequestBody(opts, "publicip") 80 } 81 82 //Update is a method which can be able to update the port of public ip 83 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 84 b, err := opts.ToPublicIpUpdateMap() 85 if err != nil { 86 r.Err = err 87 return 88 } 89 _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ 90 OkCodes: []int{200}, 91 }) 92 return 93 } 94 95 type ListOpts struct { 96 // Specifies the resource ID of pagination query. If the parameter 97 // is left blank, only resources on the first page are queried. 98 Marker string `q:"marker"` 99 100 // Specifies the number of records returned on each page. The 101 // value ranges from 0 to intmax. 102 Limit int `q:"limit"` 103 104 // Value range: 4, 6, respectively, to create ipv4 and ipv6, when not created ipv4 by default 105 IPVersion int `q:"ip_version"` 106 107 // Associated port id 108 PortId string `q:"port_id"` 109 110 // Public IP address 111 PublicIp string `q:"public_ip_address"` 112 113 // enterprise_project_id 114 // You can use this field to filter the elastic public IP under an enterprise project. 115 EnterpriseProjectId string `q:"enterprise_project_id"` 116 } 117 118 type ListOptsBuilder interface { 119 ToListPublicIPQuery() (string, error) 120 } 121 122 func (opts ListOpts) ToListPublicIPQuery() (string, error) { 123 q, err := golangsdk.BuildQueryString(opts) 124 return q.String(), err 125 } 126 127 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 128 url := listURL(client) 129 if opts != nil { 130 query, err := opts.ToListPublicIPQuery() 131 if err != nil { 132 return pagination.Pager{Err: err} 133 } 134 url += query 135 } 136 137 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 138 return PublicIPPage{pagination.LinkedPageBase{PageResult: r}} 139 }) 140 }