blob: c77ed770d8ff216e467ad8fa42760c6a24aacc44 [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.
40func ExtractFloatingIPs(page pagination.Page) ([]FloatingIP, error) {
Jon Perritt12395212016-02-24 10:41:17 -060041 r := page.(FloatingIPPage)
42 var s struct {
43 FloatingIPs []FloatingIP `json:"floating_ips"`
Joe Topjiandee32222015-02-09 23:56:26 +000044 }
Jon Perritt12395212016-02-24 10:41:17 -060045 err := r.ExtractInto(&s)
46 return s.FloatingIPs, err
Joe Topjiandee32222015-02-09 23:56:26 +000047}
48
Jon Perritt12395212016-02-24 10:41:17 -060049// FloatingIPResult is the raw result from a FloatingIP request.
Joe Topjiandee32222015-02-09 23:56:26 +000050type 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.
56func (r FloatingIPResult) Extract() (*FloatingIP, error) {
Jon Perritt12395212016-02-24 10:41:17 -060057 var s struct {
58 FloatingIP *FloatingIP `json:"floating_ip"`
Joe Topjiandee32222015-02-09 23:56:26 +000059 }
Jon Perritt12395212016-02-24 10:41:17 -060060 err := r.ExtractInto(&s)
61 return s.FloatingIP, err
Joe Topjiandee32222015-02-09 23:56:26 +000062}
63
64// CreateResult is the response from a Create operation. Call its Extract method to interpret it
65// as a FloatingIP.
66type 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.
72type 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.
78type 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.
84type 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.
90type DisassociateResult struct {
91 gophercloud.ErrResult
92}