github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/bgp/speakers/results.go (about) 1 package speakers 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 const jroot = "bgp_speaker" 9 10 type commonResult struct { 11 gophercloud.Result 12 } 13 14 // Extract is a function that accepts a result and extracts a bgp speaker resource. 15 func (r commonResult) Extract() (*BGPSpeaker, error) { 16 var s BGPSpeaker 17 err := r.ExtractInto(&s) 18 return &s, err 19 } 20 21 func (r commonResult) ExtractInto(v interface{}) error { 22 return r.Result.ExtractIntoStructPtr(v, jroot) 23 } 24 25 // BGPSpeaker BGP Speaker 26 type BGPSpeaker struct { 27 // UUID for the bgp speaker 28 ID string `json:"id"` 29 30 // Human-readable name for the bgp speaker. Might not be unique. 31 Name string `json:"name"` 32 33 // TenantID is the project owner of the bgp speaker. 34 TenantID string `json:"tenant_id"` 35 36 // ProjectID is the project owner of the bgp speaker. 37 ProjectID string `json:"project_id"` 38 39 // If the speaker would advertise floating ip host routes 40 AdvertiseFloatingIPHostRoutes bool `json:"advertise_floating_ip_host_routes"` 41 42 // If the speaker would advertise tenant networks 43 AdvertiseTenantNetworks bool `json:"advertise_tenant_networks"` 44 45 // IP version 46 IPVersion int `json:"ip_version"` 47 48 // Local Autonomous System 49 LocalAS int `json:"local_as"` 50 51 // The uuid of the Networks configured with this speaker 52 Networks []string `json:"networks"` 53 54 // The uuid of the BGP Peer Configured with this speaker 55 Peers []string `json:"peers"` 56 } 57 58 // BGPSpeakerPage is the page returned by a pager when traversing over a 59 // collection of bgp speakers. 60 type BGPSpeakerPage struct { 61 pagination.SinglePageBase 62 } 63 64 // IsEmpty checks whether a BGPSpeakerPage struct is empty. 65 func (r BGPSpeakerPage) IsEmpty() (bool, error) { 66 if r.StatusCode == 204 { 67 return true, nil 68 } 69 70 is, err := ExtractBGPSpeakers(r) 71 return len(is) == 0, err 72 } 73 74 // ExtractBGPSpeakers accepts a Page struct, specifically a BGPSpeakerPage struct, 75 // and extracts the elements into a slice of BGPSpeaker structs. In other words, 76 // a generic collection is mapped into a relevant slice. 77 func ExtractBGPSpeakers(r pagination.Page) ([]BGPSpeaker, error) { 78 var s []BGPSpeaker 79 err := ExtractBGPSpeakersInto(r, &s) 80 return s, err 81 } 82 83 // ExtractBGPSpeakersInto accepts a Page struct and an interface{}. The former contains 84 // a list of BGPSpeaker and the later should be used to store the result that would be 85 // extracted from the former. 86 func ExtractBGPSpeakersInto(r pagination.Page, v interface{}) error { 87 return r.(BGPSpeakerPage).Result.ExtractIntoSlicePtr(v, "bgp_speakers") 88 } 89 90 // GetResult represents the result of a get operation. Call its Extract 91 // method to interpret it as a BGPSpeaker. 92 type GetResult struct { 93 commonResult 94 } 95 96 // CreateResult represents the result of a create operation. Call its Extract 97 // method to interpret it as a BGPSpeaker. 98 type CreateResult struct { 99 commonResult 100 } 101 102 // DeleteResult represents the result of a delete operation. Call its 103 // ExtractErr method to determine if the request succeeded or failed. 104 type DeleteResult struct { 105 gophercloud.ErrResult 106 } 107 108 // UpdateResult represents the result of an update operation. Call its Extract 109 // method to interpret it as a BGPSpeaker. 110 type UpdateResult struct { 111 commonResult 112 } 113 114 // AddBGPPeerResult represent the response of the PUT /v2.0/bgp-speakers/{bgp-speaker-id}/add-bgp-peer 115 type AddBGPPeerResult struct { 116 gophercloud.Result 117 } 118 119 // Extract is a function that accepts a result and extracts a AddBGPPeerResult resource 120 func (r AddBGPPeerResult) Extract() (*AddBGPPeerOpts, error) { 121 var s AddBGPPeerOpts 122 err := r.ExtractInto(&s) 123 return &s, err 124 } 125 126 func (r AddBGPPeerResult) ExtractInto(v interface{}) error { 127 return r.Result.ExtractIntoStructPtr(v, "") 128 } 129 130 // RemoveBGPPeerResult represent the response of the PUT /v2.0/bgp-speakers/{bgp-speaker-id}/remove-bgp-peer 131 // There is no body content for the response of a successful DELETE request. 132 type RemoveBGPPeerResult struct { 133 gophercloud.ErrResult 134 } 135 136 // AdvertisedRoute represents an advertised route 137 type AdvertisedRoute struct { 138 // NextHop IP address 139 NextHop string `json:"next_hop"` 140 141 // Destination Network 142 Destination string `json:"destination"` 143 } 144 145 // AdvertisedRoutePage is the page returned by a pager when you call 146 type AdvertisedRoutePage struct { 147 pagination.SinglePageBase 148 } 149 150 // IsEmpty checks whether a AdvertisedRoutePage struct is empty. 151 func (r AdvertisedRoutePage) IsEmpty() (bool, error) { 152 if r.StatusCode == 204 { 153 return true, nil 154 } 155 156 is, err := ExtractAdvertisedRoutes(r) 157 return len(is) == 0, err 158 } 159 160 // ExtractAdvertisedRoutes accepts a Page struct, a.k.a. AdvertisedRoutePage struct, 161 // and extracts the elements into a slice of AdvertisedRoute structs. 162 func ExtractAdvertisedRoutes(r pagination.Page) ([]AdvertisedRoute, error) { 163 var s []AdvertisedRoute 164 err := ExtractAdvertisedRoutesInto(r, &s) 165 return s, err 166 } 167 168 // ExtractAdvertisedRoutesInto extract the advertised routes from the first param into the 2nd 169 func ExtractAdvertisedRoutesInto(r pagination.Page, v interface{}) error { 170 return r.(AdvertisedRoutePage).Result.ExtractIntoSlicePtr(v, "advertised_routes") 171 } 172 173 // AddGatewayNetworkResult represents the data that would be PUT to 174 // /v2.0/bgp-speakers/{bgp-speaker-id}/add_gateway_network 175 type AddGatewayNetworkResult struct { 176 gophercloud.Result 177 } 178 179 func (r AddGatewayNetworkResult) Extract() (*AddGatewayNetworkOpts, error) { 180 var s AddGatewayNetworkOpts 181 err := r.ExtractInto(&s) 182 return &s, err 183 } 184 185 // RemoveGatewayNetworkResult represents the data that would be PUT to 186 // /v2.0/bgp-speakers/{bgp-speaker-id}/remove_gateway_network 187 type RemoveGatewayNetworkResult struct { 188 gophercloud.ErrResult 189 }