-
Notifications
You must be signed in to change notification settings - Fork 8
/
ip_address_reservations.go
190 lines (154 loc) · 5.91 KB
/
ip_address_reservations.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package compute
import (
"fmt"
"path/filepath"
)
// IPAddressReservationsClient is a client to manage ip address reservation resources
type IPAddressReservationsClient struct {
*ResourceClient
}
const (
IPAddressReservationDescription = "IP Address Reservation"
IPAddressReservationContainerPath = "/network/v1/ipreservation/"
IPAddressReservationResourcePath = "/network/v1/ipreservation"
IPAddressReservationQualifier = "/oracle/public"
)
// IPAddressReservations returns an IPAddressReservationsClient to manage IP address reservation
// resources
func (c *ComputeClient) IPAddressReservations() *IPAddressReservationsClient {
return &IPAddressReservationsClient{
ResourceClient: &ResourceClient{
ComputeClient: c,
ResourceDescription: IPAddressReservationDescription,
ContainerPath: IPAddressReservationContainerPath,
ResourceRootPath: IPAddressReservationResourcePath,
},
}
}
// IPAddressReservation describes an IP Address reservation
type IPAddressReservation struct {
// Description of the IP Address Reservation
Description string `json:"description"`
// Reserved NAT IPv4 address from the IP Address Pool
IPAddress string `json:"ipAddress"`
// Name of the IP Address pool to reserve the NAT IP from
IPAddressPool string `json:"ipAddressPool"`
// Name of the reservation
Name string `json:"name"`
// Tags associated with the object
Tags []string `json:"tags"`
// Uniform Resource Identified for the reservation
Uri string `json:"uri"`
}
const (
PublicIPAddressPool = "public-ippool"
PrivateIPAddressPool = "cloud-ippool"
)
// CreateIPAddressReservationInput defines input parameters to create an ip address reservation
type CreateIPAddressReservationInput struct {
// Description of the IP Address Reservation
// Optional
Description string `json:"description"`
// IP Address pool from which to reserve an IP Address.
// Can be one of the following:
//
// 'public-ippool' - When you attach an IP Address from this pool to an instance, you enable
// access between the public Internet and the instance
// 'cloud-ippool' - When you attach an IP Address from this pool to an instance, the instance
// can communicate privately with other Oracle Cloud Services
// Optional
IPAddressPool string `json:"ipAddressPool"`
// The name of the reservation to create
// Required
Name string `json:"name"`
// Tags to associate with the IP Reservation
// Optional
Tags []string `json:"tags"`
}
// Takes an input struct, creates an IP Address reservation, and returns the info struct and any errors
func (c *IPAddressReservationsClient) CreateIPAddressReservation(input *CreateIPAddressReservationInput) (*IPAddressReservation, error) {
var ipAddrRes IPAddressReservation
// Qualify supplied name
input.Name = c.getQualifiedName(input.Name)
// Qualify supplied address pool if not nil
if input.IPAddressPool != "" {
input.IPAddressPool = c.qualifyIPAddressPool(input.IPAddressPool)
}
if err := c.createResource(input, &ipAddrRes); err != nil {
return nil, err
}
return c.success(&ipAddrRes)
}
// Parameters to retrieve information on an ip address reservation
type GetIPAddressReservationInput struct {
// Name of the IP Reservation
// Required
Name string `json:"name"`
}
// Returns an IP Address Reservation and any errors
func (c *IPAddressReservationsClient) GetIPAddressReservation(input *GetIPAddressReservationInput) (*IPAddressReservation, error) {
var ipAddrRes IPAddressReservation
input.Name = c.getQualifiedName(input.Name)
if err := c.getResource(input.Name, &ipAddrRes); err != nil {
return nil, err
}
return c.success(&ipAddrRes)
}
// Parameters to update an IP Address reservation
type UpdateIPAddressReservationInput struct {
// Description of the IP Address Reservation
// Optional
Description string `json:"description"`
// IP Address pool from which to reserve an IP Address.
// Can be one of the following:
//
// 'public-ippool' - When you attach an IP Address from this pool to an instance, you enable
// access between the public Internet and the instance
// 'cloud-ippool' - When you attach an IP Address from this pool to an instance, the instance
// can communicate privately with other Oracle Cloud Services
// Optional
IPAddressPool string `json:"ipAddressPool"`
// The name of the reservation to create
// Required
Name string `json:"name"`
// Tags to associate with the IP Reservation
// Optional
Tags []string `json:"tags"`
}
func (c *IPAddressReservationsClient) UpdateIPAddressReservation(input *UpdateIPAddressReservationInput) (*IPAddressReservation, error) {
var ipAddrRes IPAddressReservation
// Qualify supplied name
input.Name = c.getQualifiedName(input.Name)
// Qualify supplied address pool if not nil
if input.IPAddressPool != "" {
input.IPAddressPool = c.qualifyIPAddressPool(input.IPAddressPool)
}
if err := c.updateResource(input.Name, input, &ipAddrRes); err != nil {
return nil, err
}
return c.success(&ipAddrRes)
}
// Parameters to delete an IP Address Reservation
type DeleteIPAddressReservationInput struct {
// The name of the reservation to delete
Name string `json:"name"`
}
func (c *IPAddressReservationsClient) DeleteIPAddressReservation(input *DeleteIPAddressReservationInput) error {
input.Name = c.getQualifiedName(input.Name)
return c.deleteResource(input.Name)
}
func (c *IPAddressReservationsClient) success(result *IPAddressReservation) (*IPAddressReservation, error) {
c.unqualify(&result.Name)
if result.IPAddressPool != "" {
result.IPAddressPool = c.unqualifyIPAddressPool(result.IPAddressPool)
}
return result, nil
}
func (c *IPAddressReservationsClient) qualifyIPAddressPool(input string) string {
// Add '/oracle/public/'
return fmt.Sprintf("%s/%s", IPAddressReservationQualifier, input)
}
func (c *IPAddressReservationsClient) unqualifyIPAddressPool(input string) string {
// Remove '/oracle/public/'
return filepath.Base(input)
}