github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/bgp/peers/results.go (about)

     1  package peers
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  const jroot = "bgp_peer"
     9  
    10  type commonResult struct {
    11  	gophercloud.Result
    12  }
    13  
    14  // Extract is a function that accepts a result and extracts a bgp peer resource.
    15  func (r commonResult) Extract() (*BGPPeer, error) {
    16  	var s BGPPeer
    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  // BGP peer
    26  type BGPPeer struct {
    27  	// AuthType of the BGP Speaker
    28  	AuthType string `json:"auth_type"`
    29  
    30  	// UUID for the bgp peer
    31  	ID string `json:"id"`
    32  
    33  	// Human-readable name for the bgp peer. Might not be unique.
    34  	Name string `json:"name"`
    35  
    36  	// TenantID is the project owner of the bgp peer.
    37  	TenantID string `json:"tenant_id"`
    38  
    39  	// The IP addr of the BGP Peer
    40  	PeerIP string `json:"peer_ip"`
    41  
    42  	// ProjectID is the project owner of the bgp peer.
    43  	ProjectID string `json:"project_id"`
    44  
    45  	// Remote Autonomous System
    46  	RemoteAS int `json:"remote_as"`
    47  }
    48  
    49  // BGPPeerPage is the page returned by a pager when traversing over a
    50  // collection of bgp peers.
    51  type BGPPeerPage struct {
    52  	pagination.SinglePageBase
    53  }
    54  
    55  // IsEmpty checks whether a BGPPage struct is empty.
    56  func (r BGPPeerPage) IsEmpty() (bool, error) {
    57  	if r.StatusCode == 204 {
    58  		return true, nil
    59  	}
    60  
    61  	is, err := ExtractBGPPeers(r)
    62  	return len(is) == 0, err
    63  }
    64  
    65  // ExtractBGPPeers accepts a Page struct, specifically a BGPPeerPage struct,
    66  // and extracts the elements into a slice of BGPPeer structs. In other words,
    67  // a generic collection is mapped into a relevant slice.
    68  func ExtractBGPPeers(r pagination.Page) ([]BGPPeer, error) {
    69  	var s []BGPPeer
    70  	err := ExtractBGPPeersInto(r, &s)
    71  	return s, err
    72  }
    73  
    74  func ExtractBGPPeersInto(r pagination.Page, v interface{}) error {
    75  	return r.(BGPPeerPage).Result.ExtractIntoSlicePtr(v, "bgp_peers")
    76  }
    77  
    78  // GetResult represents the result of a get operation. Call its Extract
    79  // method to interpret it as a BGPPeer.
    80  type GetResult struct {
    81  	commonResult
    82  }
    83  
    84  // CreateResult represents the result of a create operation. Call its Extract
    85  // method to intepret it as a BGPPeer.
    86  type CreateResult struct {
    87  	commonResult
    88  }
    89  
    90  // DeleteResult represents the result of a delete operation. Call its
    91  // ExtractErr method to determine if the request succeeded or failed.
    92  type DeleteResult struct {
    93  	gophercloud.ErrResult
    94  }
    95  
    96  // UpdateResult represents the result of an update operation. Call its Extract
    97  // method to interpret it as a BGPPeer.
    98  type UpdateResult struct {
    99  	commonResult
   100  }