github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/layer3/floatingips/results.go (about) 1 package floatingips 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // FloatingIP represents a floating IP resource. A floating IP is an external 9 // IP address that is mapped to an internal port and, optionally, a specific 10 // IP address on a private network. In other words, it enables access to an 11 // instance on a private network from an external network. For this reason, 12 // floating IPs can only be defined on networks where the `router:external' 13 // attribute (provided by the external network extension) is set to True. 14 type FloatingIP struct { 15 // ID is the unique identifier for the floating IP instance. 16 ID string `json:"id"` 17 18 // FloatingNetworkID is the UUID of the external network where the floating 19 // IP is to be created. 20 FloatingNetworkID string `json:"floating_network_id"` 21 22 // FloatingIP is the address of the floating IP on the external network. 23 FloatingIP string `json:"floating_ip_address"` 24 25 // PortID is the UUID of the port on an internal network that is associated 26 // with the floating IP. 27 PortID string `json:"port_id"` 28 29 // FixedIP is the specific IP address of the internal port which should be 30 // associated with the floating IP. 31 FixedIP string `json:"fixed_ip_address"` 32 33 // TenantID is the project owner of the floating IP. Only admin users can 34 // specify a project identifier other than its own. 35 TenantID string `json:"tenant_id"` 36 37 // ProjectID is the project owner of the floating IP. 38 ProjectID string `json:"project_id"` 39 40 // Status is the condition of the API resource. 41 Status string `json:"status"` 42 43 // RouterID is the ID of the router used for this floating IP. 44 RouterID string `json:"router_id"` 45 } 46 47 type commonResult struct { 48 golangsdk.Result 49 } 50 51 // Extract will extract a FloatingIP resource from a result. 52 func (r commonResult) Extract() (*FloatingIP, error) { 53 var s struct { 54 FloatingIP *FloatingIP `json:"floatingip"` 55 } 56 err := r.ExtractInto(&s) 57 return s.FloatingIP, err 58 } 59 60 // CreateResult represents the result of a create operation. Call its Extract 61 // method to interpret it as a FloatingIP. 62 type CreateResult struct { 63 commonResult 64 } 65 66 // GetResult represents the result of a get operation. Call its Extract 67 // method to interpret it as a FloatingIP. 68 type GetResult struct { 69 commonResult 70 } 71 72 // UpdateResult represents the result of an update operation. Call its Extract 73 // method to interpret it as a FloatingIP. 74 type UpdateResult struct { 75 commonResult 76 } 77 78 // DeleteResult represents the result of an update operation. Call its 79 // ExtractErr method to determine if the request succeeded or failed. 80 type DeleteResult struct { 81 golangsdk.ErrResult 82 } 83 84 // FloatingIPPage is the page returned by a pager when traversing over a 85 // collection of floating IPs. 86 type FloatingIPPage struct { 87 pagination.LinkedPageBase 88 } 89 90 // NextPageURL is invoked when a paginated collection of floating IPs has 91 // reached the end of a page and the pager seeks to traverse over a new one. 92 // In order to do this, it needs to construct the next page's URL. 93 func (r FloatingIPPage) NextPageURL() (string, error) { 94 var s struct { 95 Links []golangsdk.Link `json:"floatingips_links"` 96 } 97 err := r.ExtractInto(&s) 98 if err != nil { 99 return "", err 100 } 101 return golangsdk.ExtractNextURL(s.Links) 102 } 103 104 // IsEmpty checks whether a FloatingIPPage struct is empty. 105 func (r FloatingIPPage) IsEmpty() (bool, error) { 106 is, err := ExtractFloatingIPs(r) 107 return len(is) == 0, err 108 } 109 110 // ExtractFloatingIPs accepts a Page struct, specifically a FloatingIPPage 111 // struct, and extracts the elements into a slice of FloatingIP structs. In 112 // other words, a generic collection is mapped into a relevant slice. 113 func ExtractFloatingIPs(r pagination.Page) ([]FloatingIP, error) { 114 var s struct { 115 FloatingIPs []FloatingIP `json:"floatingips"` 116 } 117 err := (r.(FloatingIPPage)).ExtractInto(&s) 118 return s.FloatingIPs, err 119 }