github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/vpnaas/siteconnections/results.go (about)

     1  package siteconnections
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/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  	golangsdk.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 []golangsdk.Link `json:"ipsec_site_connections_links"`
   107  	}
   108  	err := r.ExtractInto(&s)
   109  	if err != nil {
   110  		return "", err
   111  	}
   112  	return golangsdk.ExtractNextURL(s.Links)
   113  }
   114  
   115  // IsEmpty checks whether a ConnectionPage struct is empty.
   116  func (r ConnectionPage) IsEmpty() (bool, error) {
   117  	is, err := ExtractConnections(r)
   118  	return len(is) == 0, err
   119  }
   120  
   121  // ExtractConnections accepts a Page struct, specifically a Connection struct,
   122  // and extracts the elements into a slice of Connection structs. In other words,
   123  // a generic collection is mapped into a relevant slice.
   124  func ExtractConnections(r pagination.Page) ([]Connection, error) {
   125  	var s struct {
   126  		Connections []Connection `json:"ipsec_site_connections"`
   127  	}
   128  	err := (r.(ConnectionPage)).ExtractInto(&s)
   129  	return s.Connections, err
   130  }
   131  
   132  // Extract is a function that accepts a result and extracts an IPSec site connection.
   133  func (r commonResult) Extract() (*Connection, error) {
   134  	var s struct {
   135  		Connection *Connection `json:"ipsec_site_connection"`
   136  	}
   137  	err := r.ExtractInto(&s)
   138  	return s.Connection, err
   139  }
   140  
   141  // CreateResult represents the result of a create operation. Call its Extract
   142  // method to interpret it as a Connection.
   143  type CreateResult struct {
   144  	commonResult
   145  }
   146  
   147  // DeleteResult represents the result of a delete operation. Call its
   148  // ExtractErr method to determine if the operation succeeded or failed.
   149  type DeleteResult struct {
   150  	golangsdk.ErrResult
   151  }
   152  
   153  // GetResult represents the result of a get operation. Call its Extract
   154  // method to interpret it as a Connection.
   155  type GetResult struct {
   156  	commonResult
   157  }
   158  
   159  // UpdateResult represents the result of an update operation. Call its Extract
   160  // method to interpret it as a connection
   161  type UpdateResult struct {
   162  	commonResult
   163  }