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. |
| 40 | func ExtractFloatingIPs(page pagination.Page) ([]FloatingIP, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame^] | 41 | r := page.(FloatingIPPage) |
| 42 | var s struct { |
| 43 | FloatingIPs []FloatingIP `json:"floating_ips"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 44 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame^] | 45 | err := r.ExtractInto(&s) |
| 46 | return s.FloatingIPs, err |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame^] | 49 | // FloatingIPResult is the raw result from a FloatingIP request. |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 50 | type FloatingIPResult struct { |
| 51 | gophercloud.Result |
| 52 | } |
| 53 | |
| 54 | // Extract is a method that attempts to interpret any FloatingIP resource |
| 55 | // response as a FloatingIP struct. |
| 56 | func (r FloatingIPResult) Extract() (*FloatingIP, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame^] | 57 | var s struct { |
| 58 | FloatingIP *FloatingIP `json:"floating_ip"` |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 59 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame^] | 60 | err := r.ExtractInto(&s) |
| 61 | return s.FloatingIP, err |
Joe Topjian | dee3222 | 2015-02-09 23:56:26 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | // CreateResult is the response from a Create operation. Call its Extract method to interpret it |
| 65 | // as a FloatingIP. |
| 66 | type CreateResult struct { |
| 67 | FloatingIPResult |
| 68 | } |
| 69 | |
| 70 | // GetResult is the response from a Get operation. Call its Extract method to interpret it |
| 71 | // as a FloatingIP. |
| 72 | type GetResult struct { |
| 73 | FloatingIPResult |
| 74 | } |
| 75 | |
| 76 | // DeleteResult is the response from a Delete operation. Call its Extract method to determine if |
| 77 | // the call succeeded or failed. |
| 78 | type DeleteResult struct { |
| 79 | gophercloud.ErrResult |
| 80 | } |
| 81 | |
| 82 | // AssociateResult is the response from a Delete operation. Call its Extract method to determine if |
| 83 | // the call succeeded or failed. |
| 84 | type AssociateResult struct { |
| 85 | gophercloud.ErrResult |
| 86 | } |
| 87 | |
| 88 | // DisassociateResult is the response from a Delete operation. Call its Extract method to determine if |
| 89 | // the call succeeded or failed. |
| 90 | type DisassociateResult struct { |
| 91 | gophercloud.ErrResult |
| 92 | } |