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

     1  package siteconnections
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  type DPD struct {
     9  	// Action is the dead peer detection (DPD) action.
    10  	Action string `json:"action"`
    11  
    12  	// Timeout is the dead peer detection (DPD) timeout in seconds.
    13  	Timeout int `json:"timeout"`
    14  
    15  	// Interval is the dead peer detection (DPD) interval in seconds.
    16  	Interval int `json:"interval"`
    17  }
    18  
    19  // Connection is an IPSec site connection
    20  type Connection struct {
    21  	// IKEPolicyID is the ID of the IKE policy.
    22  	IKEPolicyID string `json:"ikepolicy_id"`
    23  
    24  	// VPNServiceID is the ID of the VPN service.
    25  	VPNServiceID string `json:"vpnservice_id"`
    26  
    27  	// LocalEPGroupID is the ID for the endpoint group that contains private subnets for the local side of the connection.
    28  	LocalEPGroupID string `json:"local_ep_group_id"`
    29  
    30  	// IPSecPolicyID is the ID of the IPSec policy
    31  	IPSecPolicyID string `json:"ipsecpolicy_id"`
    32  
    33  	// PeerID is the peer router identity for authentication.
    34  	PeerID string `json:"peer_id"`
    35  
    36  	// TenantID is the ID of the project.
    37  	TenantID string `json:"tenant_id"`
    38  
    39  	// ProjectID is the ID of the project.
    40  	ProjectID string `json:"project_id"`
    41  
    42  	// PeerEPGroupID is the ID for the endpoint group that contains private CIDRs in the form < net_address > / < prefix >
    43  	// for the peer side of the connection.
    44  	PeerEPGroupID string `json:"peer_ep_group_id"`
    45  
    46  	// LocalID is an ID to be used instead of the external IP address for a virtual router used in traffic
    47  	// between instances on different networks in east-west traffic.
    48  	LocalID string `json:"local_id"`
    49  
    50  	// Name is the human readable name of the connection.
    51  	Name string `json:"name"`
    52  
    53  	// Description is the human readable description of the connection.
    54  	Description string `json:"description"`
    55  
    56  	// PeerAddress is the peer gateway public IPv4 or IPv6 address or FQDN.
    57  	PeerAddress string `json:"peer_address"`
    58  
    59  	// RouteMode is the route mode.
    60  	RouteMode string `json:"route_mode"`
    61  
    62  	// PSK is the pre-shared key.
    63  	PSK string `json:"psk"`
    64  
    65  	// Initiator indicates whether this VPN can only respond to connections or both respond to and initiate connections.
    66  	Initiator string `json:"initiator"`
    67  
    68  	// PeerCIDRs is a unique list of valid peer private CIDRs in the form < net_address > / < prefix > .
    69  	PeerCIDRs []string `json:"peer_cidrs"`
    70  
    71  	// AdminStateUp is the administrative state of the connection.
    72  	AdminStateUp bool `json:"admin_state_up"`
    73  
    74  	// DPD is the dead peer detection (DPD) protocol controls.
    75  	DPD DPD `json:"dpd"`
    76  
    77  	// AuthMode is the authentication mode.
    78  	AuthMode string `json:"auth_mode"`
    79  
    80  	// MTU is the maximum transmission unit (MTU) value to address fragmentation.
    81  	MTU int `json:"mtu"`
    82  
    83  	// Status indicates whether the IPsec connection is currently operational.
    84  	// Values are ACTIVE, DOWN, BUILD, ERROR, PENDING_CREATE, PENDING_UPDATE, or PENDING_DELETE.
    85  	Status string `json:"status"`
    86  
    87  	// ID is the id of the connection
    88  	ID string `json:"id"`
    89  }
    90  
    91  type commonResult struct {
    92  	gophercloud.Result
    93  }
    94  
    95  // ConnectionPage is the page returned by a pager when traversing over a
    96  // collection of IPSec site connections.
    97  type ConnectionPage struct {
    98  	pagination.LinkedPageBase
    99  }
   100  
   101  // NextPageURL is invoked when a paginated collection of IPSec site connections has
   102  // reached the end of a page and the pager seeks to traverse over a new one.
   103  // In order to do this, it needs to construct the next page's URL.
   104  func (r ConnectionPage) NextPageURL() (string, error) {
   105  	var s struct {
   106  		Links []gophercloud.Link `json:"ipsec_site_connections_links"`
   107  	}
   108  	err := r.ExtractInto(&s)
   109  	if err != nil {
   110  		return "", err
   111  	}
   112  	return gophercloud.ExtractNextURL(s.Links)
   113  }
   114  
   115  // IsEmpty checks whether a ConnectionPage struct is empty.
   116  func (r ConnectionPage) IsEmpty() (bool, error) {
   117  	if r.StatusCode == 204 {
   118  		return true, nil
   119  	}
   120  
   121  	is, err := ExtractConnections(r)
   122  	return len(is) == 0, err
   123  }
   124  
   125  // ExtractConnections accepts a Page struct, specifically a Connection struct,
   126  // and extracts the elements into a slice of Connection structs. In other words,
   127  // a generic collection is mapped into a relevant slice.
   128  func ExtractConnections(r pagination.Page) ([]Connection, error) {
   129  	var s struct {
   130  		Connections []Connection `json:"ipsec_site_connections"`
   131  	}
   132  	err := (r.(ConnectionPage)).ExtractInto(&s)
   133  	return s.Connections, err
   134  }
   135  
   136  // Extract is a function that accepts a result and extracts an IPSec site connection.
   137  func (r commonResult) Extract() (*Connection, error) {
   138  	var s struct {
   139  		Connection *Connection `json:"ipsec_site_connection"`
   140  	}
   141  	err := r.ExtractInto(&s)
   142  	return s.Connection, err
   143  }
   144  
   145  // CreateResult represents the result of a create operation. Call its Extract
   146  // method to interpret it as a Connection.
   147  type CreateResult struct {
   148  	commonResult
   149  }
   150  
   151  // DeleteResult represents the result of a delete operation. Call its
   152  // ExtractErr method to determine if the operation succeeded or failed.
   153  type DeleteResult struct {
   154  	gophercloud.ErrResult
   155  }
   156  
   157  // GetResult represents the result of a get operation. Call its Extract
   158  // method to interpret it as a Connection.
   159  type GetResult struct {
   160  	commonResult
   161  }
   162  
   163  // UpdateResult represents the result of an update operation. Call its Extract
   164  // method to interpret it as a connection
   165  type UpdateResult struct {
   166  	commonResult
   167  }