github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/vpnaas/services/results.go (about) 1 package services 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/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 golangsdk.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 []golangsdk.Link `json:"vpnservices_links"` 65 } 66 err := r.ExtractInto(&s) 67 if err != nil { 68 return "", err 69 } 70 return golangsdk.ExtractNextURL(s.Links) 71 } 72 73 // IsEmpty checks whether a ServicePage struct is empty. 74 func (r ServicePage) IsEmpty() (bool, error) { 75 is, err := ExtractServices(r) 76 return len(is) == 0, err 77 } 78 79 // ExtractServices accepts a Page struct, specifically a Service struct, 80 // and extracts the elements into a slice of Service structs. In other words, 81 // a generic collection is mapped into a relevant slice. 82 func ExtractServices(r pagination.Page) ([]Service, error) { 83 var s struct { 84 Services []Service `json:"vpnservices"` 85 } 86 err := (r.(ServicePage)).ExtractInto(&s) 87 return s.Services, err 88 } 89 90 // GetResult represents the result of a get operation. Call its Extract 91 // method to interpret it as a Service. 92 type GetResult struct { 93 commonResult 94 } 95 96 // Extract is a function that accepts a result and extracts a VPN service. 97 func (r commonResult) Extract() (*Service, error) { 98 var s struct { 99 Service *Service `json:"vpnservice"` 100 } 101 err := r.ExtractInto(&s) 102 return s.Service, err 103 } 104 105 // CreateResult represents the result of a create operation. Call its Extract 106 // method to interpret it as a Service. 107 type CreateResult struct { 108 commonResult 109 } 110 111 // DeleteResult represents the result of a delete operation. Call its 112 // ExtractErr method to determine if the operation succeeded or failed. 113 type DeleteResult struct { 114 golangsdk.ErrResult 115 } 116 117 // UpdateResult represents the result of an update operation. Call its Extract 118 // method to interpret it as a service. 119 type UpdateResult struct { 120 commonResult 121 }