github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v2/peerings/results.go (about) 1 package peerings 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 type VpcInfo struct { 9 VpcId string `json:"vpc_id" required:"true"` 10 TenantId string `json:"tenant_id,omitempty"` 11 } 12 13 // Peering represents a Neutron VPC peering connection. 14 // Manage and perform other operations on VPC peering connections, 15 // including querying VPC peering connections as well as 16 // creating, querying, deleting, and updating a VPC peering connection. 17 type Peering struct { 18 // ID is the unique identifier for the vpc_peering_connection. 19 ID string `json:"id"` 20 21 // Name is the human readable name for the vpc_peering_connection. It does not have to be 22 // unique. 23 Name string `json:"name"` 24 25 // Status indicates whether or not a vpc_peering_connections is currently operational. 26 Status string `json:"status"` 27 28 // Description is the supplementary information about the VPC peering connection. 29 Description string `json:"description"` 30 31 // RequestVpcInfo indicates information about the local VPC 32 RequestVpcInfo VpcInfo `json:"request_vpc_info"` 33 34 // AcceptVpcInfo indicates information about the peer VPC 35 AcceptVpcInfo VpcInfo `json:"accept_vpc_info"` 36 } 37 38 // PeeringConnectionPage is the page returned by a pager when traversing over a 39 // collection of vpc_peering_connections. 40 type PeeringConnectionPage struct { 41 pagination.LinkedPageBase 42 } 43 44 // NextPageURL is invoked when a paginated collection of vpc_peering_connections has reached 45 // the end of a page and the pager seeks to traverse over a new one. In order 46 // to do this, it needs to construct the next page's URL. 47 func (r PeeringConnectionPage) NextPageURL() (string, error) { 48 var s struct { 49 Links []golangsdk.Link `json:"peerings_links"` 50 } 51 err := r.ExtractInto(&s) 52 if err != nil { 53 return "", err 54 } 55 return golangsdk.ExtractNextURL(s.Links) 56 } 57 58 // IsEmpty checks whether a PeeringConnectionPage struct is empty. 59 func (r PeeringConnectionPage) IsEmpty() (bool, error) { 60 is, err := ExtractPeerings(r) 61 return len(is) == 0, err 62 } 63 64 // ExtractPeerings accepts a Page struct, specifically a PeeringConnectionPage struct, 65 // and extracts the elements into a slice of Peering structs. In other words, 66 // a generic collection is mapped into a relevant slice. 67 func ExtractPeerings(r pagination.Page) ([]Peering, error) { 68 var s struct { 69 Peerings []Peering `json:"peerings"` 70 } 71 err := (r.(PeeringConnectionPage)).ExtractInto(&s) 72 return s.Peerings, err 73 } 74 75 type commonResult struct { 76 golangsdk.Result 77 } 78 79 // Extract is a function that accepts a result and extracts a Peering. 80 func (r commonResult) Extract() (*Peering, error) { 81 var s struct { 82 Peering *Peering `json:"peering"` 83 } 84 err := r.ExtractInto(&s) 85 return s.Peering, err 86 } 87 88 // ExtractResult is a function that accepts a result and extracts a Peering. 89 func (r commonResult) ExtractResult() (Peering, error) { 90 var s struct { 91 // ID is the unique identifier for the vpc. 92 ID string `json:"id"` 93 // Name is the human readable name for the vpc. It does not have to be 94 // unique. 95 Name string `json:"name"` 96 97 // Status indicates whether or not a vpc is currently operational. 98 Status string `json:"status"` 99 100 // Description is the supplementary information about the VPC peering connection. 101 Description string `json:"description"` 102 103 // RequestVpcInfo indicates information about the local VPC 104 RequestVpcInfo VpcInfo `json:"request_vpc_info"` 105 106 // AcceptVpcInfo indicates information about the peer VPC 107 AcceptVpcInfo VpcInfo `json:"accept_vpc_info"` 108 } 109 err1 := r.ExtractInto(&s) 110 return s, err1 111 } 112 113 // GetResult represents the result of a get operation. Call its Extract 114 // method to interpret it as a Vpc Peering Connection. 115 type GetResult struct { 116 commonResult 117 } 118 119 // AcceptResult represents the result of a get operation. Call its Extract 120 // method to interpret it as a Vpc Peering Connection. 121 type AcceptResult struct { 122 commonResult 123 } 124 125 // RejectResult represents the result of a get operation. Call its Extract 126 // method to interpret it as a Vpc Peering Connection. 127 type RejectResult struct { 128 commonResult 129 } 130 131 // CreateResult represents the result of a create operation. Call its Extract 132 // method to interpret it as a vpc peering connection. 133 type CreateResult struct { 134 commonResult 135 } 136 137 // UpdateResult represents the result of an update operation. Call its Extract 138 // method to interpret it as a vpc peering connection. 139 type UpdateResult struct { 140 commonResult 141 } 142 143 // DeleteResult represents the result of a delete operation. Call its ExtractErr 144 // method to determine if the request succeeded or failed. 145 type DeleteResult struct { 146 golangsdk.ErrResult 147 }