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

     1  package siteconnections
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // CreateOptsBuilder allows extensions to add additional parameters to the
     9  // Create request.
    10  type CreateOptsBuilder interface {
    11  	ToConnectionCreateMap() (map[string]interface{}, error)
    12  }
    13  type Action string
    14  type Initiator string
    15  
    16  const (
    17  	ActionHold             Action    = "hold"
    18  	ActionClear            Action    = "clear"
    19  	ActionRestart          Action    = "restart"
    20  	ActionDisabled         Action    = "disabled"
    21  	ActionRestartByPeer    Action    = "restart-by-peer"
    22  	InitiatorBiDirectional Initiator = "bi-directional"
    23  	InitiatorResponseOnly  Initiator = "response-only"
    24  )
    25  
    26  // DPDCreateOpts contains all the values needed to create a valid configuration for Dead Peer detection protocols
    27  type DPDCreateOpts struct {
    28  	// The dead peer detection (DPD) action.
    29  	// A valid value is clear, hold, restart, disabled, or restart-by-peer.
    30  	// Default value is hold.
    31  	Action Action `json:"action,omitempty"`
    32  
    33  	// The dead peer detection (DPD) timeout in seconds.
    34  	// A valid value is a positive integer that is greater than the DPD interval value.
    35  	// Default is 120.
    36  	Timeout int `json:"timeout,omitempty"`
    37  
    38  	// The dead peer detection (DPD) interval, in seconds.
    39  	// A valid value is a positive integer.
    40  	// Default is 30.
    41  	Interval int `json:"interval,omitempty"`
    42  }
    43  
    44  // CreateOpts contains all the values needed to create a new IPSec site connection
    45  type CreateOpts struct {
    46  	// The ID of the IKE policy
    47  	IKEPolicyID string `json:"ikepolicy_id"`
    48  
    49  	// The ID of the VPN Service
    50  	VPNServiceID string `json:"vpnservice_id"`
    51  
    52  	// The ID for the endpoint group that contains private subnets for the local side of the connection.
    53  	// You must specify this parameter with the peer_ep_group_id parameter unless
    54  	// in backward- compatible mode where peer_cidrs is provided with a subnet_id for the VPN service.
    55  	LocalEPGroupID string `json:"local_ep_group_id,omitempty"`
    56  
    57  	// The ID of the IPsec policy.
    58  	IPSecPolicyID string `json:"ipsecpolicy_id"`
    59  
    60  	// The peer router identity for authentication.
    61  	// A valid value is an IPv4 address, IPv6 address, e-mail address, key ID, or FQDN.
    62  	// Typically, this value matches the peer_address value.
    63  	PeerID string `json:"peer_id"`
    64  
    65  	// The ID of the project
    66  	TenantID string `json:"tenant_id,omitempty"`
    67  
    68  	// The ID for the endpoint group that contains private CIDRs in the form < net_address > / < prefix >
    69  	// for the peer side of the connection.
    70  	// You must specify this parameter with the local_ep_group_id parameter unless in backward-compatible mode
    71  	// where peer_cidrs is provided with a subnet_id for the VPN service.
    72  	PeerEPGroupID string `json:"peer_ep_group_id,omitempty"`
    73  
    74  	// An ID to be used instead of the external IP address for a virtual router used in traffic between instances on different networks in east-west traffic.
    75  	// Most often, local ID would be domain name, email address, etc.
    76  	// If this is not configured then the external IP address will be used as the ID.
    77  	LocalID string `json:"local_id,omitempty"`
    78  
    79  	// The human readable name of the connection.
    80  	// Does not have to be unique.
    81  	// Default is an empty string
    82  	Name string `json:"name,omitempty"`
    83  
    84  	// The human readable description of the connection.
    85  	// Does not have to be unique.
    86  	// Default is an empty string
    87  	Description string `json:"description,omitempty"`
    88  
    89  	// The peer gateway public IPv4 or IPv6 address or FQDN.
    90  	PeerAddress string `json:"peer_address"`
    91  
    92  	// The pre-shared key.
    93  	// A valid value is any string.
    94  	PSK string `json:"psk"`
    95  
    96  	// Indicates whether this VPN can only respond to connections or both respond to and initiate connections.
    97  	// A valid value is response-only or bi-directional. Default is bi-directional.
    98  	Initiator Initiator `json:"initiator,omitempty"`
    99  
   100  	// Unique list of valid peer private CIDRs in the form < net_address > / < prefix > .
   101  	PeerCIDRs []string `json:"peer_cidrs,omitempty"`
   102  
   103  	// The administrative state of the resource, which is up (true) or down (false).
   104  	// Default is false
   105  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   106  
   107  	// A dictionary with dead peer detection (DPD) protocol controls.
   108  	DPD *DPDCreateOpts `json:"dpd,omitempty"`
   109  
   110  	// The maximum transmission unit (MTU) value to address fragmentation.
   111  	// Minimum value is 68 for IPv4, and 1280 for IPv6.
   112  	MTU int `json:"mtu,omitempty"`
   113  }
   114  
   115  // ToConnectionCreateMap casts a CreateOpts struct to a map.
   116  func (opts CreateOpts) ToConnectionCreateMap() (map[string]interface{}, error) {
   117  	return golangsdk.BuildRequestBody(opts, "ipsec_site_connection")
   118  }
   119  
   120  // Create accepts a CreateOpts struct and uses the values to create a new
   121  // IPSec site connection.
   122  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   123  	b, err := opts.ToConnectionCreateMap()
   124  	if err != nil {
   125  		r.Err = err
   126  		return
   127  	}
   128  	_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
   129  
   130  	return
   131  }
   132  
   133  // Delete will permanently delete a particular IPSec site connection based on its
   134  // unique ID.
   135  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   136  	_, r.Err = c.Delete(resourceURL(c, id), nil)
   137  	return
   138  }
   139  
   140  // Get retrieves a particular IPSec site connection based on its unique ID.
   141  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
   142  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
   143  	return
   144  }
   145  
   146  // ListOptsBuilder allows extensions to add additional parameters to the
   147  // List request.
   148  type ListOptsBuilder interface {
   149  	ToConnectionListQuery() (string, error)
   150  }
   151  
   152  // ListOpts allows the filtering and sorting of paginated collections through
   153  // the API. Filtering is achieved by passing in struct field values that map to
   154  // the IPSec site connection attributes you want to see returned.
   155  type ListOpts struct {
   156  	IKEPolicyID    string    `q:"ikepolicy_id"`
   157  	VPNServiceID   string    `q:"vpnservice_id"`
   158  	LocalEPGroupID string    `q:"local_ep_group_id"`
   159  	IPSecPolicyID  string    `q:"ipsecpolicy_id"`
   160  	PeerID         string    `q:"peer_id"`
   161  	TenantID       string    `q:"tenant_id"`
   162  	ProjectID      string    `q:"project_id"`
   163  	PeerEPGroupID  string    `q:"peer_ep_group_id"`
   164  	LocalID        string    `q:"local_id"`
   165  	Name           string    `q:"name"`
   166  	Description    string    `q:"description"`
   167  	PeerAddress    string    `q:"peer_address"`
   168  	PSK            string    `q:"psk"`
   169  	Initiator      Initiator `q:"initiator"`
   170  	AdminStateUp   *bool     `q:"admin_state_up"`
   171  	MTU            int       `q:"mtu"`
   172  }
   173  
   174  // ToConnectionListQuery formats a ListOpts into a query string.
   175  func (opts ListOpts) ToConnectionListQuery() (string, error) {
   176  	q, err := golangsdk.BuildQueryString(opts)
   177  	return q.String(), err
   178  }
   179  
   180  // List returns a Pager which allows you to iterate over a collection of
   181  // IPSec site connections. It accepts a ListOpts struct, which allows you to filter
   182  // and sort the returned collection for greater efficiency.
   183  func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   184  	url := rootURL(c)
   185  	if opts != nil {
   186  		query, err := opts.ToConnectionListQuery()
   187  		if err != nil {
   188  			return pagination.Pager{Err: err}
   189  		}
   190  		url += query
   191  	}
   192  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   193  		return ConnectionPage{pagination.LinkedPageBase{PageResult: r}}
   194  	})
   195  }
   196  
   197  // UpdateOptsBuilder allows extensions to add additional parameters to the
   198  // Update request.
   199  type UpdateOptsBuilder interface {
   200  	ToConnectionUpdateMap() (map[string]interface{}, error)
   201  }
   202  
   203  // UpdateOpts contains the values used when updating the DPD of an IPSec site connection
   204  type DPDUpdateOpts struct {
   205  	Action   Action `json:"action,omitempty"`
   206  	Timeout  int    `json:"timeout,omitempty"`
   207  	Interval int    `json:"interval,omitempty"`
   208  }
   209  
   210  // UpdateOpts contains the values used when updating an IPSec site connection
   211  type UpdateOpts struct {
   212  	Description    *string        `json:"description,omitempty"`
   213  	Name           *string        `json:"name,omitempty"`
   214  	LocalID        string         `json:"local_id,omitempty"`
   215  	PeerAddress    string         `json:"peer_address,omitempty"`
   216  	PeerID         string         `json:"peer_id,omitempty"`
   217  	PeerCIDRs      []string       `json:"peer_cidrs,omitempty"`
   218  	LocalEPGroupID string         `json:"local_ep_group_id,omitempty"`
   219  	PeerEPGroupID  string         `json:"peer_ep_group_id,omitempty"`
   220  	MTU            int            `json:"mtu,omitempty"`
   221  	Initiator      Initiator      `json:"initiator,omitempty"`
   222  	PSK            string         `json:"psk,omitempty"`
   223  	DPD            *DPDUpdateOpts `json:"dpd,omitempty"`
   224  	AdminStateUp   *bool          `json:"admin_state_up,omitempty"`
   225  }
   226  
   227  // ToConnectionUpdateMap casts an UpdateOpts struct to a map.
   228  func (opts UpdateOpts) ToConnectionUpdateMap() (map[string]interface{}, error) {
   229  	return golangsdk.BuildRequestBody(opts, "ipsec_site_connection")
   230  }
   231  
   232  // Update allows IPSec site connections to be updated.
   233  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   234  	b, err := opts.ToConnectionUpdateMap()
   235  	if err != nil {
   236  		r.Err = err
   237  		return
   238  	}
   239  	_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{
   240  		OkCodes: []int{200},
   241  	})
   242  	return
   243  }