github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/networking/v2/extensions/networkipavailabilities/requests.go (about) 1 package networkipavailabilities 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 8 ) 9 10 // ListOptsBuilder allows extensions to add additional parameters to the 11 // List request. 12 type ListOptsBuilder interface { 13 ToNetworkIPAvailabilityListQuery() (string, error) 14 } 15 16 // ListOpts allows the filtering and sorting of paginated collections through 17 // the Neutron API. 18 type ListOpts struct { 19 // NetworkName allows to filter on the identifier of a network. 20 NetworkID string `q:"network_id"` 21 22 // NetworkName allows to filter on the name of a network. 23 NetworkName string `q:"network_name"` 24 25 // IPVersion allows to filter on the version of the IP protocol. 26 // You can use the well-known IP versions with the gophercloud.IPVersion type. 27 IPVersion string `q:"ip_version"` 28 29 // ProjectID allows to filter on the Identity project field. 30 ProjectID string `q:"project_id"` 31 32 // TenantID allows to filter on the Identity project field. 33 TenantID string `q:"tenant_id"` 34 } 35 36 // ToNetworkIPAvailabilityListQuery formats a ListOpts into a query string. 37 func (opts ListOpts) ToNetworkIPAvailabilityListQuery() (string, error) { 38 q, err := gophercloud.BuildQueryString(opts) 39 return q.String(), err 40 } 41 42 // List returns a Pager which allows you to iterate over a collection of 43 // networkipavailabilities. It accepts a ListOpts struct, which allows you to 44 // filter the returned collection for greater efficiency. 45 func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 46 url := listURL(c) 47 if opts != nil { 48 query, err := opts.ToNetworkIPAvailabilityListQuery() 49 if err != nil { 50 return pagination.Pager{Err: err} 51 } 52 url += query 53 } 54 return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 55 return NetworkIPAvailabilityPage{pagination.SinglePageBase(r)} 56 }) 57 } 58 59 // Get retrieves a specific NetworkIPAvailability based on its ID. 60 func Get(ctx context.Context, c *gophercloud.ServiceClient, id string) (r GetResult) { 61 resp, err := c.Get(ctx, getURL(c, id), &r.Body, nil) 62 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 63 return 64 }