github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/layer3/addressscopes/results.go (about) 1 package addressscopes 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 type commonResult struct { 9 gophercloud.Result 10 } 11 12 // Extract is a function that accepts a result and extracts an address-scope resource. 13 func (r commonResult) Extract() (*AddressScope, error) { 14 var s struct { 15 AddressScope *AddressScope `json:"address_scope"` 16 } 17 err := r.ExtractInto(&s) 18 return s.AddressScope, err 19 } 20 21 // GetResult represents the result of a get operation. Call its Extract 22 // method to interpret it as a SubnetPool. 23 type GetResult struct { 24 commonResult 25 } 26 27 // CreateResult represents the result of a create operation. Call its Extract 28 // method to interpret it as a SubnetPool. 29 type CreateResult struct { 30 commonResult 31 } 32 33 // UpdateResult represents the result of an update operation. Call its Extract 34 // method to interpret it as an AddressScope. 35 type UpdateResult struct { 36 commonResult 37 } 38 39 // DeleteResult represents the result of a delete operation. Call its 40 // ExtractErr method to determine if the request succeeded or failed. 41 type DeleteResult struct { 42 gophercloud.ErrResult 43 } 44 45 // AddressScope represents a Neutron address-scope. 46 type AddressScope struct { 47 // ID is the id of the address-scope. 48 ID string `json:"id"` 49 50 // Name is the human-readable name of the address-scope. 51 Name string `json:"name"` 52 53 // TenantID is the id of the Identity project. 54 TenantID string `json:"tenant_id"` 55 56 // ProjectID is the id of the Identity project. 57 ProjectID string `json:"project_id"` 58 59 // IPVersion is the IP protocol version. 60 IPVersion int `json:"ip_version"` 61 62 // Shared indicates whether this address-scope is shared across all projects. 63 Shared bool `json:"shared"` 64 } 65 66 // AddressScopePage stores a single page of AddressScopes from a List() API call. 67 type AddressScopePage struct { 68 pagination.LinkedPageBase 69 } 70 71 // NextPageURL is invoked when a paginated collection of address-scope has 72 // reached the end of a page and the pager seeks to traverse over a new one. 73 // In order to do this, it needs to construct the next page's URL. 74 func (r AddressScopePage) NextPageURL() (string, error) { 75 var s struct { 76 Links []gophercloud.Link `json:"address_scopes_links"` 77 } 78 err := r.ExtractInto(&s) 79 if err != nil { 80 return "", err 81 } 82 return gophercloud.ExtractNextURL(s.Links) 83 } 84 85 // IsEmpty determines whether or not a AddressScopePage is empty. 86 func (r AddressScopePage) IsEmpty() (bool, error) { 87 if r.StatusCode == 204 { 88 return true, nil 89 } 90 91 addressScopes, err := ExtractAddressScopes(r) 92 return len(addressScopes) == 0, err 93 } 94 95 // ExtractAddressScopes interprets the results of a single page from a List() 96 // API call, producing a slice of AddressScopes structs. 97 func ExtractAddressScopes(r pagination.Page) ([]AddressScope, error) { 98 var s struct { 99 AddressScopes []AddressScope `json:"address_scopes"` 100 } 101 err := (r.(AddressScopePage)).ExtractInto(&s) 102 return s.AddressScopes, err 103 }