blob: f8e56207994336ce6f6b7d0671337c3ae71d72f5 [file] [log] [blame]
Jamie Hannaford548d3402014-09-18 15:50:08 +02001package ports
2
3import (
4 "strconv"
5
6 "github.com/rackspace/gophercloud"
7 "github.com/rackspace/gophercloud/openstack/utils"
8 "github.com/rackspace/gophercloud/pagination"
9)
10
11type ListOpts struct {
12 Status string
13 Name string
14 AdminStateUp *bool
15 NetworkID string
16 TenantID string
17 DeviceOwner string
18 MACAddress string
19 ID string
20 SecurityGroups string
21 DeviceID string
22 BindingHostID string
23 BindingVIFType string
24 BindingVNICType string
25 Limit int
26 Page string
27 PerPage string
28}
29
30func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
31 // Build query parameters
32 q := make(map[string]string)
33 if opts.Status != "" {
34 q["status"] = opts.Status
35 }
36 if opts.Name != "" {
37 q["name"] = opts.Name
38 }
39 if opts.AdminStateUp != nil {
40 q["admin_state_up"] = strconv.FormatBool(*opts.AdminStateUp)
41 }
42 if opts.NetworkID != "" {
43 q["network_id"] = opts.NetworkID
44 }
45 if opts.TenantID != "" {
46 q["tenant_id"] = opts.TenantID
47 }
48 if opts.DeviceOwner != "" {
49 q["device_owner"] = opts.DeviceOwner
50 }
51 if opts.MACAddress != "" {
52 q["mac_address"] = opts.MACAddress
53 }
54 if opts.ID != "" {
55 q["id"] = opts.ID
56 }
57 if opts.SecurityGroups != "" {
58 q["security_groups"] = opts.SecurityGroups
59 }
60 if opts.DeviceID != "" {
61 q["device_id"] = opts.DeviceID
62 }
63 if opts.BindingHostID != "" {
64 q["binding:host_id"] = opts.BindingHostID
65 }
66 if opts.BindingVIFType != "" {
67 q["binding:vif_type"] = opts.BindingVIFType
68 }
69 if opts.BindingVNICType != "" {
70 q["binding:vnic_type"] = opts.BindingVNICType
71 }
72 if opts.NetworkID != "" {
73 q["network_id"] = opts.NetworkID
74 }
75 if opts.Limit != 0 {
76 q["limit"] = strconv.Itoa(opts.Limit)
77 }
78 if opts.Page != "" {
79 q["page"] = opts.Page
80 }
81 if opts.PerPage != "" {
82 q["per_page"] = opts.PerPage
83 }
84
85 u := ListURL(c) + utils.BuildQuery(q)
86 return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
87 return PortPage{pagination.LinkedPageBase(r)}
88 })
89}