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