github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/vpnaas/services/results.go (about) 1 package services 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // Service is a VPN Service 9 type Service struct { 10 // TenantID is the ID of the project. 11 TenantID string `json:"tenant_id"` 12 13 // ProjectID is the ID of the project. 14 ProjectID string `json:"project_id"` 15 16 // SubnetID is the ID of the subnet. 17 SubnetID string `json:"subnet_id"` 18 19 // RouterID is the ID of the router. 20 RouterID string `json:"router_id"` 21 22 // Description is a human-readable description for the resource. 23 // Default is an empty string 24 Description string `json:"description"` 25 26 // AdminStateUp is the administrative state of the resource, which is up (true) or down (false). 27 AdminStateUp bool `json:"admin_state_up"` 28 29 // Name is the human readable name of the service. 30 Name string `json:"name"` 31 32 // Status indicates whether IPsec VPN service is currently operational. 33 // Values are ACTIVE, DOWN, BUILD, ERROR, PENDING_CREATE, PENDING_UPDATE, or PENDING_DELETE. 34 Status string `json:"status"` 35 36 // ID is the unique ID of the VPN service. 37 ID string `json:"id"` 38 39 // ExternalV6IP is the read-only external (public) IPv6 address that is used for the VPN service. 40 ExternalV6IP string `json:"external_v6_ip"` 41 42 // ExternalV4IP is the read-only external (public) IPv4 address that is used for the VPN service. 43 ExternalV4IP string `json:"external_v4_ip"` 44 45 // FlavorID is the ID of the flavor. 46 FlavorID string `json:"flavor_id"` 47 } 48 49 type commonResult struct { 50 gophercloud.Result 51 } 52 53 // ServicePage is the page returned by a pager when traversing over a 54 // collection of VPN services. 55 type ServicePage struct { 56 pagination.LinkedPageBase 57 } 58 59 // NextPageURL is invoked when a paginated collection of VPN services has 60 // reached the end of a page and the pager seeks to traverse over a new one. 61 // In order to do this, it needs to construct the next page's URL. 62 func (r ServicePage) NextPageURL() (string, error) { 63 var s struct { 64 Links []gophercloud.Link `json:"vpnservices_links"` 65 } 66 err := r.ExtractInto(&s) 67 if err != nil { 68 return "", err 69 } 70 return gophercloud.ExtractNextURL(s.Links) 71 } 72 73 // IsEmpty checks whether a ServicePage struct is empty. 74 func (r ServicePage) IsEmpty() (bool, error) { 75 if r.StatusCode == 204 { 76 return true, nil 77 } 78 79 is, err := ExtractServices(r) 80 return len(is) == 0, err 81 } 82 83 // ExtractServices accepts a Page struct, specifically a Service struct, 84 // and extracts the elements into a slice of Service structs. In other words, 85 // a generic collection is mapped into a relevant slice. 86 func ExtractServices(r pagination.Page) ([]Service, error) { 87 var s struct { 88 Services []Service `json:"vpnservices"` 89 } 90 err := (r.(ServicePage)).ExtractInto(&s) 91 return s.Services, err 92 } 93 94 // GetResult represents the result of a get operation. Call its Extract 95 // method to interpret it as a Service. 96 type GetResult struct { 97 commonResult 98 } 99 100 // Extract is a function that accepts a result and extracts a VPN service. 101 func (r commonResult) Extract() (*Service, error) { 102 var s struct { 103 Service *Service `json:"vpnservice"` 104 } 105 err := r.ExtractInto(&s) 106 return s.Service, err 107 } 108 109 // CreateResult represents the result of a create operation. Call its Extract 110 // method to interpret it as a Service. 111 type CreateResult struct { 112 commonResult 113 } 114 115 // DeleteResult represents the result of a delete operation. Call its 116 // ExtractErr method to determine if the operation succeeded or failed. 117 type DeleteResult struct { 118 gophercloud.ErrResult 119 } 120 121 // UpdateResult represents the result of an update operation. Call its Extract 122 // method to interpret it as a service. 123 type UpdateResult struct { 124 commonResult 125 }