Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 1 | package floatingips |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | // A FloatingIP is an IP that can be associated with an instance |
| 9 | type FloatingIP struct { |
| 10 | // ID is a unique ID of the Floating IP |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | ID string `json:"id"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 12 | |
| 13 | // FixedIP is the IP of the instance related to the Floating IP |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 14 | FixedIP string `json:"fixed_ip,omitempty"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 15 | |
| 16 | // InstanceID is the ID of the instance that is using the Floating IP |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 17 | InstanceID string `json:"instance_id"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 18 | |
| 19 | // IP is the actual Floating IP |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 20 | IP string `json:"ip"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 21 | |
| 22 | // Pool is the pool of floating IPs that this floating IP belongs to |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 23 | Pool string `json:"pool"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 26 | // FloatingIPPage stores a single, only page of FloatingIPs |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 27 | // results from a List call. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 28 | type FloatingIPPage struct { |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 29 | pagination.SinglePageBase |
| 30 | } |
| 31 | |
| 32 | // IsEmpty determines whether or not a FloatingIPsPage is empty. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 33 | func (page FloatingIPPage) IsEmpty() (bool, error) { |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 34 | va, err := ExtractFloatingIPs(page) |
| 35 | return len(va) == 0, err |
| 36 | } |
| 37 | |
| 38 | // ExtractFloatingIPs interprets a page of results as a slice of |
| 39 | // FloatingIPs. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 40 | func ExtractFloatingIPs(r pagination.Page) ([]FloatingIP, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 41 | var s struct { |
| 42 | FloatingIPs []FloatingIP `json:"floating_ips"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 43 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 44 | err := (r.(FloatingIPPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 45 | return s.FloatingIPs, err |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 48 | // FloatingIPResult is the raw result from a FloatingIP request. |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 49 | type FloatingIPResult struct { |
| 50 | gophercloud.Result |
| 51 | } |
| 52 | |
| 53 | // Extract is a method that attempts to interpret any FloatingIP resource |
| 54 | // response as a FloatingIP struct. |
| 55 | func (r FloatingIPResult) Extract() (*FloatingIP, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 56 | var s struct { |
| 57 | FloatingIP *FloatingIP `json:"floating_ip"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 58 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 59 | err := r.ExtractInto(&s) |
| 60 | return s.FloatingIP, err |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | // CreateResult is the response from a Create operation. Call its Extract method to interpret it |
| 64 | // as a FloatingIP. |
| 65 | type CreateResult struct { |
| 66 | FloatingIPResult |
| 67 | } |
| 68 | |
| 69 | // GetResult is the response from a Get operation. Call its Extract method to interpret it |
| 70 | // as a FloatingIP. |
| 71 | type GetResult struct { |
| 72 | FloatingIPResult |
| 73 | } |
| 74 | |
| 75 | // DeleteResult is the response from a Delete operation. Call its Extract method to determine if |
| 76 | // the call succeeded or failed. |
| 77 | type DeleteResult struct { |
| 78 | gophercloud.ErrResult |
| 79 | } |
| 80 | |
| 81 | // AssociateResult is the response from a Delete operation. Call its Extract method to determine if |
| 82 | // the call succeeded or failed. |
| 83 | type AssociateResult struct { |
| 84 | gophercloud.ErrResult |
| 85 | } |
| 86 | |
| 87 | // DisassociateResult is the response from a Delete operation. Call its Extract method to determine if |
| 88 | // the call succeeded or failed. |
| 89 | type DisassociateResult struct { |
| 90 | gophercloud.ErrResult |
| 91 | } |