forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metal_gateway.go
136 lines (111 loc) · 4.88 KB
/
metal_gateway.go
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
package packngo
import (
"path"
)
type MetalGatewayState string
const (
metalGatewayBasePath = "/metal-gateways"
MetalGatewayActive MetalGatewayState = "active"
MetalGatewayReady MetalGatewayState = "ready"
MetalGatewayDeleting MetalGatewayState = "deleting"
)
type MetalGatewayService interface {
List(projectID string, opts *ListOptions) ([]MetalGateway, *Response, error)
Create(projectID string, input *MetalGatewayCreateRequest) (*MetalGateway, *Response, error)
Get(metalGatewayID string, opts *GetOptions) (*MetalGateway, *Response, error)
Delete(metalGatewayID string) (*Response, error)
}
type MetalGateway struct {
ID string `json:"id"`
State MetalGatewayState `json:"state"`
Project *Project `json:"project,omitempty"`
VirtualNetwork *VirtualNetwork `json:"virtual_network,omitempty"`
IPReservation *IPAddressReservation `json:"ip_reservation,omitempty"`
Href string `json:"href"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
VRF *VRF `json:"vrf,omitempty"`
}
// MetalGatewayLite struct representation of a Metal Gateway
type MetalGatewayLite struct {
ID string `json:"id,omitempty"`
// The current state of the Metal Gateway. 'Ready' indicates the gateway record has been configured, but is currently not active on the network. 'Active' indicates the gateway has been configured on the network. 'Deleting' is a temporary state used to indicate that the gateway is in the process of being un-configured from the network, after which the gateway record will be deleted.
State string `json:"state,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
// The gateway address with subnet CIDR value for this Metal Gateway. For example, a Metal Gateway using an IP reservation with block 10.1.2.0/27 would have a gateway address of 10.1.2.1/27.
GatewayAddress string `json:"gateway_address,omitempty"`
// The VLAN id of the Virtual Network record associated to this Metal Gateway. Example: 1001.
VLAN int `json:"vlan,omitempty"`
Href string `json:"href,omitempty"`
}
type MetalGatewayServiceOp struct {
client *Client
}
func (s *MetalGatewayServiceOp) List(projectID string, opts *ListOptions) (metalGateways []MetalGateway, resp *Response, err error) {
if validateErr := ValidateUUID(projectID); validateErr != nil {
return nil, nil, validateErr
}
type metalGatewaysRoot struct {
MetalGateways []MetalGateway `json:"metal_gateways"`
Meta meta `json:"meta"`
}
endpointPath := path.Join(projectBasePath, projectID, metalGatewayBasePath)
apiPathQuery := opts.WithQuery(endpointPath)
for {
subset := new(metalGatewaysRoot)
resp, err = s.client.DoRequest("GET", apiPathQuery, nil, subset)
if err != nil {
return nil, resp, err
}
metalGateways = append(metalGateways, subset.MetalGateways...)
if apiPathQuery = nextPage(subset.Meta, opts); apiPathQuery != "" {
continue
}
return
}
}
type MetalGatewayCreateRequest struct {
// VirtualNetworkID virtual network UUID.
VirtualNetworkID string `json:"virtual_network_id"`
// IPReservationID (optional) IP Reservation UUID (Public or VRF). Required for VRF.
IPReservationID string `json:"ip_reservation_id,omitempty"`
// PrivateIPv4SubnetSize (optional) Power of 2 between 8 and 128 (8, 16, 32, 64, 128). Invalid for VRF.
PrivateIPv4SubnetSize int `json:"private_ipv4_subnet_size,omitempty"`
}
func (s *MetalGatewayServiceOp) Get(metalGatewayID string, opts *GetOptions) (*MetalGateway, *Response, error) {
if validateErr := ValidateUUID(metalGatewayID); validateErr != nil {
return nil, nil, validateErr
}
endpointPath := path.Join(metalGatewayBasePath, metalGatewayID)
apiPathQuery := opts.WithQuery(endpointPath)
metalGateway := new(MetalGateway)
resp, err := s.client.DoRequest("GET", apiPathQuery, nil, metalGateway)
if err != nil {
return nil, resp, err
}
return metalGateway, resp, err
}
func (s *MetalGatewayServiceOp) Create(projectID string, input *MetalGatewayCreateRequest) (*MetalGateway, *Response, error) {
if validateErr := ValidateUUID(projectID); validateErr != nil {
return nil, nil, validateErr
}
apiPath := path.Join(projectBasePath, projectID, metalGatewayBasePath)
output := new(MetalGateway)
resp, err := s.client.DoRequest("POST", apiPath, input, output)
if err != nil {
return nil, nil, err
}
return output, resp, nil
}
func (s *MetalGatewayServiceOp) Delete(metalGatewayID string) (*Response, error) {
if validateErr := ValidateUUID(metalGatewayID); validateErr != nil {
return nil, validateErr
}
apiPath := path.Join(metalGatewayBasePath, metalGatewayID)
resp, err := s.client.DoRequest("DELETE", apiPath, nil, nil)
if err != nil {
return nil, err
}
return resp, nil
}