File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (163 lines) | stat: -rw-r--r-- 5,233 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package siteconnections

import (
	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/pagination"
)

type DPD struct {
	// Action is the dead peer detection (DPD) action.
	Action string `json:"action"`

	// Timeout is the dead peer detection (DPD) timeout in seconds.
	Timeout int `json:"timeout"`

	// Interval is the dead peer detection (DPD) interval in seconds.
	Interval int `json:"interval"`
}

// Connection is an IPSec site connection
type Connection struct {
	// IKEPolicyID is the ID of the IKE policy.
	IKEPolicyID string `json:"ikepolicy_id"`

	// VPNServiceID is the ID of the VPN service.
	VPNServiceID string `json:"vpnservice_id"`

	// LocalEPGroupID is the ID for the endpoint group that contains private subnets for the local side of the connection.
	LocalEPGroupID string `json:"local_ep_group_id"`

	// IPSecPolicyID is the ID of the IPSec policy
	IPSecPolicyID string `json:"ipsecpolicy_id"`

	// PeerID is the peer router identity for authentication.
	PeerID string `json:"peer_id"`

	// TenantID is the ID of the project.
	TenantID string `json:"tenant_id"`

	// ProjectID is the ID of the project.
	ProjectID string `json:"project_id"`

	// PeerEPGroupID is the ID for the endpoint group that contains private CIDRs in the form < net_address > / < prefix >
	// for the peer side of the connection.
	PeerEPGroupID string `json:"peer_ep_group_id"`

	// LocalID is 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.
	LocalID string `json:"local_id"`

	// Name is the human readable name of the connection.
	Name string `json:"name"`

	// Description is the human readable description of the connection.
	Description string `json:"description"`

	// PeerAddress is the peer gateway public IPv4 or IPv6 address or FQDN.
	PeerAddress string `json:"peer_address"`

	// RouteMode is the route mode.
	RouteMode string `json:"route_mode"`

	// PSK is the pre-shared key.
	PSK string `json:"psk"`

	// Initiator indicates whether this VPN can only respond to connections or both respond to and initiate connections.
	Initiator string `json:"initiator"`

	// PeerCIDRs is a unique list of valid peer private CIDRs in the form < net_address > / < prefix > .
	PeerCIDRs []string `json:"peer_cidrs"`

	// AdminStateUp is the administrative state of the connection.
	AdminStateUp bool `json:"admin_state_up"`

	// DPD is the dead peer detection (DPD) protocol controls.
	DPD DPD `json:"dpd"`

	// AuthMode is the authentication mode.
	AuthMode string `json:"auth_mode"`

	// MTU is the maximum transmission unit (MTU) value to address fragmentation.
	MTU int `json:"mtu"`

	// Status indicates whether the IPsec connection is currently operational.
	// Values are ACTIVE, DOWN, BUILD, ERROR, PENDING_CREATE, PENDING_UPDATE, or PENDING_DELETE.
	Status string `json:"status"`

	// ID is the id of the connection
	ID string `json:"id"`
}

type commonResult struct {
	gophercloud.Result
}

// ConnectionPage is the page returned by a pager when traversing over a
// collection of IPSec site connections.
type ConnectionPage struct {
	pagination.LinkedPageBase
}

// NextPageURL is invoked when a paginated collection of IPSec site connections has
// reached the end of a page and the pager seeks to traverse over a new one.
// In order to do this, it needs to construct the next page's URL.
func (r ConnectionPage) NextPageURL() (string, error) {
	var s struct {
		Links []gophercloud.Link `json:"ipsec_site_connections_links"`
	}
	err := r.ExtractInto(&s)
	if err != nil {
		return "", err
	}
	return gophercloud.ExtractNextURL(s.Links)
}

// IsEmpty checks whether a ConnectionPage struct is empty.
func (r ConnectionPage) IsEmpty() (bool, error) {
	is, err := ExtractConnections(r)
	return len(is) == 0, err
}

// ExtractConnections accepts a Page struct, specifically a Connection struct,
// and extracts the elements into a slice of Connection structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractConnections(r pagination.Page) ([]Connection, error) {
	var s struct {
		Connections []Connection `json:"ipsec_site_connections"`
	}
	err := (r.(ConnectionPage)).ExtractInto(&s)
	return s.Connections, err
}

// Extract is a function that accepts a result and extracts an IPSec site connection.
func (r commonResult) Extract() (*Connection, error) {
	var s struct {
		Connection *Connection `json:"ipsec_site_connection"`
	}
	err := r.ExtractInto(&s)
	return s.Connection, err
}

// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Connection.
type CreateResult struct {
	commonResult
}

// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the operation succeeded or failed.
type DeleteResult struct {
	gophercloud.ErrResult
}

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Connection.
type GetResult struct {
	commonResult
}

// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a connection
type UpdateResult struct {
	commonResult
}