-
Notifications
You must be signed in to change notification settings - Fork 80
/
ocvp_esxihost_client.go
376 lines (342 loc) · 13.9 KB
/
ocvp_esxihost_client.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// Copyright (c) 2016, 2018, 2021, Oracle and/or its affiliates. All rights reserved.
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
// Code generated. DO NOT EDIT.
// Oracle Cloud VMware Solution API
//
// Use this API to manage your Oracle Cloud VMware Solution (https://docs.cloud.oracle.com/iaas/Content/VMware/Concepts/ocvsoverview.htm).
//
package ocvp
import (
"context"
"fmt"
"github.com/oracle/oci-go-sdk/v43/common"
"github.com/oracle/oci-go-sdk/v43/common/auth"
"net/http"
)
//EsxiHostClient a client for EsxiHost
type EsxiHostClient struct {
common.BaseClient
config *common.ConfigurationProvider
}
// NewEsxiHostClientWithConfigurationProvider Creates a new default EsxiHost client with the given configuration provider.
// the configuration provider will be used for the default signer as well as reading the region
func NewEsxiHostClientWithConfigurationProvider(configProvider common.ConfigurationProvider) (client EsxiHostClient, err error) {
provider, err := auth.GetGenericConfigurationProvider(configProvider)
if err != nil {
return client, err
}
baseClient, e := common.NewClientWithConfig(provider)
if e != nil {
return client, e
}
return newEsxiHostClientFromBaseClient(baseClient, provider)
}
// NewEsxiHostClientWithOboToken Creates a new default EsxiHost client with the given configuration provider.
// The obotoken will be added to default headers and signed; the configuration provider will be used for the signer
// as well as reading the region
func NewEsxiHostClientWithOboToken(configProvider common.ConfigurationProvider, oboToken string) (client EsxiHostClient, err error) {
baseClient, err := common.NewClientWithOboToken(configProvider, oboToken)
if err != nil {
return client, err
}
return newEsxiHostClientFromBaseClient(baseClient, configProvider)
}
func newEsxiHostClientFromBaseClient(baseClient common.BaseClient, configProvider common.ConfigurationProvider) (client EsxiHostClient, err error) {
client = EsxiHostClient{BaseClient: baseClient}
client.BasePath = "20200501"
err = client.setConfigurationProvider(configProvider)
return
}
// SetRegion overrides the region of this client.
func (client *EsxiHostClient) SetRegion(region string) {
client.Host = common.StringToRegion(region).EndpointForTemplate("ocvp", "https://ocvps.{region}.oci.{secondLevelDomain}")
}
// SetConfigurationProvider sets the configuration provider including the region, returns an error if is not valid
func (client *EsxiHostClient) setConfigurationProvider(configProvider common.ConfigurationProvider) error {
if ok, err := common.IsConfigurationProviderValid(configProvider); !ok {
return err
}
// Error has been checked already
region, _ := configProvider.Region()
client.SetRegion(region)
client.config = &configProvider
return nil
}
// ConfigurationProvider the ConfigurationProvider used in this client, or null if none set
func (client *EsxiHostClient) ConfigurationProvider() *common.ConfigurationProvider {
return client.config
}
// CreateEsxiHost Adds another ESXi host to an existing SDDC. The attributes of the specified
// `Sddc` determine the VMware software and other configuration settings used
// by the ESXi host.
// Use the WorkRequest operations to track the
// creation of the ESXi host.
//
// See also
//
// Click https://docs.cloud.oracle.com/en-us/iaas/tools/go-sdk-examples/latest/ocvp/CreateEsxiHost.go.html to see an example of how to use CreateEsxiHost API.
func (client EsxiHostClient) CreateEsxiHost(ctx context.Context, request CreateEsxiHostRequest) (response CreateEsxiHostResponse, err error) {
var ociResponse common.OCIResponse
policy := common.NoRetryPolicy()
if client.RetryPolicy() != nil {
policy = *client.RetryPolicy()
}
if request.RetryPolicy() != nil {
policy = *request.RetryPolicy()
}
if !(request.OpcRetryToken != nil && *request.OpcRetryToken != "") {
request.OpcRetryToken = common.String(common.RetryToken())
}
ociResponse, err = common.Retry(ctx, request, client.createEsxiHost, policy)
if err != nil {
if ociResponse != nil {
if httpResponse := ociResponse.HTTPResponse(); httpResponse != nil {
opcRequestId := httpResponse.Header.Get("opc-request-id")
response = CreateEsxiHostResponse{RawResponse: httpResponse, OpcRequestId: &opcRequestId}
} else {
response = CreateEsxiHostResponse{}
}
}
return
}
if convertedResponse, ok := ociResponse.(CreateEsxiHostResponse); ok {
response = convertedResponse
} else {
err = fmt.Errorf("failed to convert OCIResponse into CreateEsxiHostResponse")
}
return
}
// createEsxiHost implements the OCIOperation interface (enables retrying operations)
func (client EsxiHostClient) createEsxiHost(ctx context.Context, request common.OCIRequest, binaryReqBody *common.OCIReadSeekCloser) (common.OCIResponse, error) {
httpRequest, err := request.HTTPRequest(http.MethodPost, "/esxiHosts", binaryReqBody)
if err != nil {
return nil, err
}
var response CreateEsxiHostResponse
var httpResponse *http.Response
httpResponse, err = client.Call(ctx, &httpRequest)
defer common.CloseBodyIfValid(httpResponse)
response.RawResponse = httpResponse
if err != nil {
return response, err
}
err = common.UnmarshalResponse(httpResponse, &response)
return response, err
}
// DeleteEsxiHost Deletes the specified ESXi host. Before deleting the host, back up or
// migrate any VMware workloads running on it.
// When you delete an ESXi host, Oracle does not remove the node
// configuration within the VMware environment itself. That is
// your responsibility.
// **Note:** If you delete EXSi hosts from the SDDC to total less than 3,
// you are still billed for the 3 minimum recommended EXSi hosts. Also,
// you cannot add more VMware workloads to the SDDC until it again has at
// least 3 ESXi hosts.
// Use the WorkRequest operations to track the
// deletion of the ESXi host.
//
// See also
//
// Click https://docs.cloud.oracle.com/en-us/iaas/tools/go-sdk-examples/latest/ocvp/DeleteEsxiHost.go.html to see an example of how to use DeleteEsxiHost API.
func (client EsxiHostClient) DeleteEsxiHost(ctx context.Context, request DeleteEsxiHostRequest) (response DeleteEsxiHostResponse, err error) {
var ociResponse common.OCIResponse
policy := common.NoRetryPolicy()
if client.RetryPolicy() != nil {
policy = *client.RetryPolicy()
}
if request.RetryPolicy() != nil {
policy = *request.RetryPolicy()
}
ociResponse, err = common.Retry(ctx, request, client.deleteEsxiHost, policy)
if err != nil {
if ociResponse != nil {
if httpResponse := ociResponse.HTTPResponse(); httpResponse != nil {
opcRequestId := httpResponse.Header.Get("opc-request-id")
response = DeleteEsxiHostResponse{RawResponse: httpResponse, OpcRequestId: &opcRequestId}
} else {
response = DeleteEsxiHostResponse{}
}
}
return
}
if convertedResponse, ok := ociResponse.(DeleteEsxiHostResponse); ok {
response = convertedResponse
} else {
err = fmt.Errorf("failed to convert OCIResponse into DeleteEsxiHostResponse")
}
return
}
// deleteEsxiHost implements the OCIOperation interface (enables retrying operations)
func (client EsxiHostClient) deleteEsxiHost(ctx context.Context, request common.OCIRequest, binaryReqBody *common.OCIReadSeekCloser) (common.OCIResponse, error) {
httpRequest, err := request.HTTPRequest(http.MethodDelete, "/esxiHosts/{esxiHostId}", binaryReqBody)
if err != nil {
return nil, err
}
var response DeleteEsxiHostResponse
var httpResponse *http.Response
httpResponse, err = client.Call(ctx, &httpRequest)
defer common.CloseBodyIfValid(httpResponse)
response.RawResponse = httpResponse
if err != nil {
return response, err
}
err = common.UnmarshalResponse(httpResponse, &response)
return response, err
}
// GetEsxiHost Gets the specified ESXi host's information.
//
// See also
//
// Click https://docs.cloud.oracle.com/en-us/iaas/tools/go-sdk-examples/latest/ocvp/GetEsxiHost.go.html to see an example of how to use GetEsxiHost API.
func (client EsxiHostClient) GetEsxiHost(ctx context.Context, request GetEsxiHostRequest) (response GetEsxiHostResponse, err error) {
var ociResponse common.OCIResponse
policy := common.NoRetryPolicy()
if client.RetryPolicy() != nil {
policy = *client.RetryPolicy()
}
if request.RetryPolicy() != nil {
policy = *request.RetryPolicy()
}
ociResponse, err = common.Retry(ctx, request, client.getEsxiHost, policy)
if err != nil {
if ociResponse != nil {
if httpResponse := ociResponse.HTTPResponse(); httpResponse != nil {
opcRequestId := httpResponse.Header.Get("opc-request-id")
response = GetEsxiHostResponse{RawResponse: httpResponse, OpcRequestId: &opcRequestId}
} else {
response = GetEsxiHostResponse{}
}
}
return
}
if convertedResponse, ok := ociResponse.(GetEsxiHostResponse); ok {
response = convertedResponse
} else {
err = fmt.Errorf("failed to convert OCIResponse into GetEsxiHostResponse")
}
return
}
// getEsxiHost implements the OCIOperation interface (enables retrying operations)
func (client EsxiHostClient) getEsxiHost(ctx context.Context, request common.OCIRequest, binaryReqBody *common.OCIReadSeekCloser) (common.OCIResponse, error) {
httpRequest, err := request.HTTPRequest(http.MethodGet, "/esxiHosts/{esxiHostId}", binaryReqBody)
if err != nil {
return nil, err
}
var response GetEsxiHostResponse
var httpResponse *http.Response
httpResponse, err = client.Call(ctx, &httpRequest)
defer common.CloseBodyIfValid(httpResponse)
response.RawResponse = httpResponse
if err != nil {
return response, err
}
err = common.UnmarshalResponse(httpResponse, &response)
return response, err
}
// ListEsxiHosts Lists the ESXi hosts in the specified SDDC. The list can be filtered
// by Compute instance OCID or ESXi display name.
// Remember that in terms of implementation, an ESXi host is a Compute instance that
// is configured with the chosen bundle of VMware software. Each `EsxiHost`
// object has its own OCID (`id`), and a separate attribute for the OCID of
// the Compute instance (`computeInstanceId`). When filtering the list of
// ESXi hosts, you can specify the OCID of the Compute instance, not the
// ESXi host OCID.
//
// See also
//
// Click https://docs.cloud.oracle.com/en-us/iaas/tools/go-sdk-examples/latest/ocvp/ListEsxiHosts.go.html to see an example of how to use ListEsxiHosts API.
func (client EsxiHostClient) ListEsxiHosts(ctx context.Context, request ListEsxiHostsRequest) (response ListEsxiHostsResponse, err error) {
var ociResponse common.OCIResponse
policy := common.NoRetryPolicy()
if client.RetryPolicy() != nil {
policy = *client.RetryPolicy()
}
if request.RetryPolicy() != nil {
policy = *request.RetryPolicy()
}
ociResponse, err = common.Retry(ctx, request, client.listEsxiHosts, policy)
if err != nil {
if ociResponse != nil {
if httpResponse := ociResponse.HTTPResponse(); httpResponse != nil {
opcRequestId := httpResponse.Header.Get("opc-request-id")
response = ListEsxiHostsResponse{RawResponse: httpResponse, OpcRequestId: &opcRequestId}
} else {
response = ListEsxiHostsResponse{}
}
}
return
}
if convertedResponse, ok := ociResponse.(ListEsxiHostsResponse); ok {
response = convertedResponse
} else {
err = fmt.Errorf("failed to convert OCIResponse into ListEsxiHostsResponse")
}
return
}
// listEsxiHosts implements the OCIOperation interface (enables retrying operations)
func (client EsxiHostClient) listEsxiHosts(ctx context.Context, request common.OCIRequest, binaryReqBody *common.OCIReadSeekCloser) (common.OCIResponse, error) {
httpRequest, err := request.HTTPRequest(http.MethodGet, "/esxiHosts", binaryReqBody)
if err != nil {
return nil, err
}
var response ListEsxiHostsResponse
var httpResponse *http.Response
httpResponse, err = client.Call(ctx, &httpRequest)
defer common.CloseBodyIfValid(httpResponse)
response.RawResponse = httpResponse
if err != nil {
return response, err
}
err = common.UnmarshalResponse(httpResponse, &response)
return response, err
}
// UpdateEsxiHost Updates the specified ESXi host.
//
// See also
//
// Click https://docs.cloud.oracle.com/en-us/iaas/tools/go-sdk-examples/latest/ocvp/UpdateEsxiHost.go.html to see an example of how to use UpdateEsxiHost API.
func (client EsxiHostClient) UpdateEsxiHost(ctx context.Context, request UpdateEsxiHostRequest) (response UpdateEsxiHostResponse, err error) {
var ociResponse common.OCIResponse
policy := common.NoRetryPolicy()
if client.RetryPolicy() != nil {
policy = *client.RetryPolicy()
}
if request.RetryPolicy() != nil {
policy = *request.RetryPolicy()
}
ociResponse, err = common.Retry(ctx, request, client.updateEsxiHost, policy)
if err != nil {
if ociResponse != nil {
if httpResponse := ociResponse.HTTPResponse(); httpResponse != nil {
opcRequestId := httpResponse.Header.Get("opc-request-id")
response = UpdateEsxiHostResponse{RawResponse: httpResponse, OpcRequestId: &opcRequestId}
} else {
response = UpdateEsxiHostResponse{}
}
}
return
}
if convertedResponse, ok := ociResponse.(UpdateEsxiHostResponse); ok {
response = convertedResponse
} else {
err = fmt.Errorf("failed to convert OCIResponse into UpdateEsxiHostResponse")
}
return
}
// updateEsxiHost implements the OCIOperation interface (enables retrying operations)
func (client EsxiHostClient) updateEsxiHost(ctx context.Context, request common.OCIRequest, binaryReqBody *common.OCIReadSeekCloser) (common.OCIResponse, error) {
httpRequest, err := request.HTTPRequest(http.MethodPut, "/esxiHosts/{esxiHostId}", binaryReqBody)
if err != nil {
return nil, err
}
var response UpdateEsxiHostResponse
var httpResponse *http.Response
httpResponse, err = client.Call(ctx, &httpRequest)
defer common.CloseBodyIfValid(httpResponse)
response.RawResponse = httpResponse
if err != nil {
return response, err
}
err = common.UnmarshalResponse(httpResponse, &response)
return response, err
}