blob: 753f3afa758a1df01fb1f36cdbf0c48651a764ed [file] [log] [blame]
Jon Perritt12395212016-02-24 10:41:17 -06001package floatingips
Joe Topjiandee32222015-02-09 23:56:26 +00002
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Joe Topjiandee32222015-02-09 23:56:26 +00006)
7
8// A FloatingIP is an IP that can be associated with an instance
9type FloatingIP struct {
10 // ID is a unique ID of the Floating IP
Jon Perritt12395212016-02-24 10:41:17 -060011 ID string `json:"id"`
Joe Topjiandee32222015-02-09 23:56:26 +000012
13 // FixedIP is the IP of the instance related to the Floating IP
Jon Perritt12395212016-02-24 10:41:17 -060014 FixedIP string `json:"fixed_ip,omitempty"`
Joe Topjiandee32222015-02-09 23:56:26 +000015
16 // InstanceID is the ID of the instance that is using the Floating IP
Jon Perritt12395212016-02-24 10:41:17 -060017 InstanceID string `json:"instance_id"`
Joe Topjiandee32222015-02-09 23:56:26 +000018
19 // IP is the actual Floating IP
Jon Perritt12395212016-02-24 10:41:17 -060020 IP string `json:"ip"`
Joe Topjiandee32222015-02-09 23:56:26 +000021
22 // Pool is the pool of floating IPs that this floating IP belongs to
Jon Perritt12395212016-02-24 10:41:17 -060023 Pool string `json:"pool"`
Joe Topjiandee32222015-02-09 23:56:26 +000024}
25
Jon Perritt12395212016-02-24 10:41:17 -060026// FloatingIPPage stores a single, only page of FloatingIPs
Joe Topjiandee32222015-02-09 23:56:26 +000027// results from a List call.
Jon Perritt12395212016-02-24 10:41:17 -060028type FloatingIPPage struct {
Joe Topjiandee32222015-02-09 23:56:26 +000029 pagination.SinglePageBase
30}
31
32// IsEmpty determines whether or not a FloatingIPsPage is empty.
Jon Perritt12395212016-02-24 10:41:17 -060033func (page FloatingIPPage) IsEmpty() (bool, error) {
Joe Topjiandee32222015-02-09 23:56:26 +000034 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 Perritt31b66462016-02-25 22:25:30 -060040func ExtractFloatingIPs(r pagination.Page) ([]FloatingIP, error) {
Jon Perritt12395212016-02-24 10:41:17 -060041 var s struct {
42 FloatingIPs []FloatingIP `json:"floating_ips"`
Joe Topjiandee32222015-02-09 23:56:26 +000043 }
Jon Perritt31b66462016-02-25 22:25:30 -060044 err := (r.(FloatingIPPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060045 return s.FloatingIPs, err
Joe Topjiandee32222015-02-09 23:56:26 +000046}
47
Jon Perritt12395212016-02-24 10:41:17 -060048// FloatingIPResult is the raw result from a FloatingIP request.
Joe Topjiandee32222015-02-09 23:56:26 +000049type 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.
55func (r FloatingIPResult) Extract() (*FloatingIP, error) {
Jon Perritt12395212016-02-24 10:41:17 -060056 var s struct {
57 FloatingIP *FloatingIP `json:"floating_ip"`
Joe Topjiandee32222015-02-09 23:56:26 +000058 }
Jon Perritt12395212016-02-24 10:41:17 -060059 err := r.ExtractInto(&s)
60 return s.FloatingIP, err
Joe Topjiandee32222015-02-09 23:56:26 +000061}
62
63// CreateResult is the response from a Create operation. Call its Extract method to interpret it
64// as a FloatingIP.
65type 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.
71type 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.
77type 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.
83type 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.
89type DisassociateResult struct {
90 gophercloud.ErrResult
91}