-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctiondeploymentfunctionversion.go
More file actions
398 lines (360 loc) · 17.3 KB
/
Copy pathfunctiondeploymentfunctionversion.go
File metadata and controls
398 lines (360 loc) · 17.3 KB
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package nvidiacloudfunctions
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/brevdev/nvcf-go/internal/apijson"
"github.com/brevdev/nvcf-go/internal/apiquery"
"github.com/brevdev/nvcf-go/internal/param"
"github.com/brevdev/nvcf-go/internal/requestconfig"
"github.com/brevdev/nvcf-go/option"
"github.com/brevdev/nvcf-go/shared"
)
// FunctionDeploymentFunctionVersionService contains methods and other services
// that help with interacting with the nvidia-cloud-functions API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewFunctionDeploymentFunctionVersionService] method instead.
type FunctionDeploymentFunctionVersionService struct {
Options []option.RequestOption
}
// NewFunctionDeploymentFunctionVersionService generates a new service that applies
// the given options to each request. These options are applied after the parent
// client's options (if there is one), and before any request-specific options.
func NewFunctionDeploymentFunctionVersionService(opts ...option.RequestOption) (r *FunctionDeploymentFunctionVersionService) {
r = &FunctionDeploymentFunctionVersionService{}
r.Options = opts
return
}
// Initiates deployment for the specified function version. Upon invocation of this
// endpoint, the function's status transitions to 'DEPLOYING'. If the specified
// function version is public, then Account Admin cannot perform this operation.
// Access to this endpoint mandates a bearer token with 'deploy_function' scope in
// the HTTP Authorization header.
func (r *FunctionDeploymentFunctionVersionService) New(ctx context.Context, functionID string, functionVersionID string, body FunctionDeploymentFunctionVersionNewParams, opts ...option.RequestOption) (res *DeploymentResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
if functionVersionID == "" {
err = errors.New("missing required functionVersionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/deployments/functions/%s/versions/%s", functionID, functionVersionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Allows Account Admins to retrieve the deployment details of the specified
// function version. Access to this endpoint mandates a bearer token with
// 'deploy_function' scope in the HTTP Authorization header.
func (r *FunctionDeploymentFunctionVersionService) Get(ctx context.Context, functionID string, functionVersionID string, opts ...option.RequestOption) (res *DeploymentResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
if functionVersionID == "" {
err = errors.New("missing required functionVersionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/deployments/functions/%s/versions/%s", functionID, functionVersionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Updates the deployment specs of the specified function version. It's important
// to note that GPU type and backend configurations cannot be modified through this
// endpoint. If the specified function is public, then Account Admin cannot perform
// this operation. Access to this endpoint mandates a bearer token with
// 'deploy_function' scope in the HTTP Authorization header.
func (r *FunctionDeploymentFunctionVersionService) Update(ctx context.Context, functionID string, functionVersionID string, body FunctionDeploymentFunctionVersionUpdateParams, opts ...option.RequestOption) (res *DeploymentResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
if functionVersionID == "" {
err = errors.New("missing required functionVersionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/deployments/functions/%s/versions/%s", functionID, functionVersionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
return
}
// Deletes the deployment associated with the specified function. Upon deletion,
// any active instances will be terminated, and the function's status will
// transition to 'INACTIVE'. To undeploy a function version gracefully, specify
// 'graceful=true' query parameter, allowing current tasks to complete before
// terminating the instances. If the specified function version is public, then
// Account Admin cannot perform this operation. Access to this endpoint mandates a
// bearer token with 'deploy_function' scope in the HTTP Authorization header.
func (r *FunctionDeploymentFunctionVersionService) Delete(ctx context.Context, functionID string, functionVersionID string, body FunctionDeploymentFunctionVersionDeleteParams, opts ...option.RequestOption) (res *shared.FunctionResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
if functionVersionID == "" {
err = errors.New("missing required functionVersionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/deployments/functions/%s/versions/%s", functionID, functionVersionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...)
return
}
// Function Deployment Response
type DeploymentResponse struct {
// Function deployment response
Deployment DeploymentResponseDeployment `json:"deployment,required"`
JSON deploymentResponseJSON `json:"-"`
}
// deploymentResponseJSON contains the JSON metadata for the struct
// [DeploymentResponse]
type deploymentResponseJSON struct {
Deployment apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DeploymentResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r deploymentResponseJSON) RawJSON() string {
return r.raw
}
// Function deployment response
type DeploymentResponseDeployment struct {
// Function deployment creation timestamp
CreatedAt time.Time `json:"createdAt,required" format:"date-time"`
// Function deployment details
DeploymentSpecifications []DeploymentResponseDeploymentDeploymentSpecification `json:"deploymentSpecifications,required"`
// Function id
FunctionID string `json:"functionId,required" format:"uuid"`
// Function name
FunctionName string `json:"functionName,required"`
// Function status
FunctionStatus DeploymentResponseDeploymentFunctionStatus `json:"functionStatus,required"`
// Function version id
FunctionVersionID string `json:"functionVersionId,required" format:"uuid"`
// NVIDIA Cloud Account Id
NcaID string `json:"ncaId,required"`
// Health info for a deployment specification is included only if there are any
// issues/errors.
HealthInfo []DeploymentResponseDeploymentHealthInfo `json:"healthInfo"`
// Deprecated Request Queue URL
RequestQueueURL string `json:"requestQueueUrl"`
JSON deploymentResponseDeploymentJSON `json:"-"`
}
// deploymentResponseDeploymentJSON contains the JSON metadata for the struct
// [DeploymentResponseDeployment]
type deploymentResponseDeploymentJSON struct {
CreatedAt apijson.Field
DeploymentSpecifications apijson.Field
FunctionID apijson.Field
FunctionName apijson.Field
FunctionStatus apijson.Field
FunctionVersionID apijson.Field
NcaID apijson.Field
HealthInfo apijson.Field
RequestQueueURL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DeploymentResponseDeployment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r deploymentResponseDeploymentJSON) RawJSON() string {
return r.raw
}
// Data Transfer Object(DTO) representing GPU specification.
type DeploymentResponseDeploymentDeploymentSpecification struct {
// GPU name from the cluster
GPU string `json:"gpu,required"`
// Instance type, based on GPU, assigned to a Worker
InstanceType string `json:"instanceType,required"`
// Maximum number of spot instances for the deployment
MaxInstances int64 `json:"maxInstances,required"`
// Minimum number of spot instances for the deployment
MinInstances int64 `json:"minInstances,required"`
// Specific attributes capabilities to deploy functions.
Attributes []string `json:"attributes"`
// List of availability-zones(or clusters) in the cluster group
AvailabilityZones []string `json:"availabilityZones"`
// Backend/CSP where the GPU powered instance will be launched
Backend string `json:"backend"`
// Specific clusters within spot instance or worker node powered by the selected
// instance-type to deploy function.
Clusters []string `json:"clusters"`
Configuration interface{} `json:"configuration"`
// Max request concurrency between 1 (default) and 1024.
MaxRequestConcurrency int64 `json:"maxRequestConcurrency"`
// Preferred order of deployment if there are several gpu specs.
PreferredOrder int64 `json:"preferredOrder"`
// List of regions allowed to deploy. The instance or worker node will be in one of
// the specified geographical regions.
Regions []string `json:"regions"`
JSON deploymentResponseDeploymentDeploymentSpecificationJSON `json:"-"`
}
// deploymentResponseDeploymentDeploymentSpecificationJSON contains the JSON
// metadata for the struct [DeploymentResponseDeploymentDeploymentSpecification]
type deploymentResponseDeploymentDeploymentSpecificationJSON struct {
GPU apijson.Field
InstanceType apijson.Field
MaxInstances apijson.Field
MinInstances apijson.Field
Attributes apijson.Field
AvailabilityZones apijson.Field
Backend apijson.Field
Clusters apijson.Field
Configuration apijson.Field
MaxRequestConcurrency apijson.Field
PreferredOrder apijson.Field
Regions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DeploymentResponseDeploymentDeploymentSpecification) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r deploymentResponseDeploymentDeploymentSpecificationJSON) RawJSON() string {
return r.raw
}
// Function status
type DeploymentResponseDeploymentFunctionStatus string
const (
DeploymentResponseDeploymentFunctionStatusActive DeploymentResponseDeploymentFunctionStatus = "ACTIVE"
DeploymentResponseDeploymentFunctionStatusDeploying DeploymentResponseDeploymentFunctionStatus = "DEPLOYING"
DeploymentResponseDeploymentFunctionStatusError DeploymentResponseDeploymentFunctionStatus = "ERROR"
DeploymentResponseDeploymentFunctionStatusInactive DeploymentResponseDeploymentFunctionStatus = "INACTIVE"
DeploymentResponseDeploymentFunctionStatusDeleted DeploymentResponseDeploymentFunctionStatus = "DELETED"
)
func (r DeploymentResponseDeploymentFunctionStatus) IsKnown() bool {
switch r {
case DeploymentResponseDeploymentFunctionStatusActive, DeploymentResponseDeploymentFunctionStatusDeploying, DeploymentResponseDeploymentFunctionStatusError, DeploymentResponseDeploymentFunctionStatusInactive, DeploymentResponseDeploymentFunctionStatusDeleted:
return true
}
return false
}
// Data Transfer Object(DTO) representing deployment error
type DeploymentResponseDeploymentHealthInfo struct {
// Backend/CSP where the GPU powered instance will be launched
Backend string `json:"backend,required"`
// Deployment error
Error string `json:"error,required"`
// GPU Type as per SDD
GPU string `json:"gpu,required"`
// Instance type
InstanceType string `json:"instanceType"`
// SIS Request ID
SisRequestID string `json:"sisRequestId" format:"uuid"`
JSON deploymentResponseDeploymentHealthInfoJSON `json:"-"`
}
// deploymentResponseDeploymentHealthInfoJSON contains the JSON metadata for the
// struct [DeploymentResponseDeploymentHealthInfo]
type deploymentResponseDeploymentHealthInfoJSON struct {
Backend apijson.Field
Error apijson.Field
GPU apijson.Field
InstanceType apijson.Field
SisRequestID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DeploymentResponseDeploymentHealthInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r deploymentResponseDeploymentHealthInfoJSON) RawJSON() string {
return r.raw
}
type FunctionDeploymentFunctionVersionNewParams struct {
// Deployment specs with Backend, GPU, instance-type, etc. details
DeploymentSpecifications param.Field[[]FunctionDeploymentFunctionVersionNewParamsDeploymentSpecification] `json:"deploymentSpecifications,required"`
}
func (r FunctionDeploymentFunctionVersionNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Data Transfer Object(DTO) representing GPU specification.
type FunctionDeploymentFunctionVersionNewParamsDeploymentSpecification struct {
// GPU name from the cluster
GPU param.Field[string] `json:"gpu,required"`
// Instance type, based on GPU, assigned to a Worker
InstanceType param.Field[string] `json:"instanceType,required"`
// Maximum number of spot instances for the deployment
MaxInstances param.Field[int64] `json:"maxInstances,required"`
// Minimum number of spot instances for the deployment
MinInstances param.Field[int64] `json:"minInstances,required"`
// Specific attributes capabilities to deploy functions.
Attributes param.Field[[]string] `json:"attributes"`
// List of availability-zones(or clusters) in the cluster group
AvailabilityZones param.Field[[]string] `json:"availabilityZones"`
// Backend/CSP where the GPU powered instance will be launched
Backend param.Field[string] `json:"backend"`
// Specific clusters within spot instance or worker node powered by the selected
// instance-type to deploy function.
Clusters param.Field[[]string] `json:"clusters"`
Configuration param.Field[interface{}] `json:"configuration"`
// Max request concurrency between 1 (default) and 1024.
MaxRequestConcurrency param.Field[int64] `json:"maxRequestConcurrency"`
// Preferred order of deployment if there are several gpu specs.
PreferredOrder param.Field[int64] `json:"preferredOrder"`
// List of regions allowed to deploy. The instance or worker node will be in one of
// the specified geographical regions.
Regions param.Field[[]string] `json:"regions"`
}
func (r FunctionDeploymentFunctionVersionNewParamsDeploymentSpecification) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type FunctionDeploymentFunctionVersionUpdateParams struct {
// Deployment specs with Backend, GPU, instance-type, etc. details
DeploymentSpecifications param.Field[[]FunctionDeploymentFunctionVersionUpdateParamsDeploymentSpecification] `json:"deploymentSpecifications,required"`
}
func (r FunctionDeploymentFunctionVersionUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Data Transfer Object(DTO) representing GPU specification.
type FunctionDeploymentFunctionVersionUpdateParamsDeploymentSpecification struct {
// GPU name from the cluster
GPU param.Field[string] `json:"gpu,required"`
// Instance type, based on GPU, assigned to a Worker
InstanceType param.Field[string] `json:"instanceType,required"`
// Maximum number of spot instances for the deployment
MaxInstances param.Field[int64] `json:"maxInstances,required"`
// Minimum number of spot instances for the deployment
MinInstances param.Field[int64] `json:"minInstances,required"`
// Specific attributes capabilities to deploy functions.
Attributes param.Field[[]string] `json:"attributes"`
// List of availability-zones(or clusters) in the cluster group
AvailabilityZones param.Field[[]string] `json:"availabilityZones"`
// Backend/CSP where the GPU powered instance will be launched
Backend param.Field[string] `json:"backend"`
// Specific clusters within spot instance or worker node powered by the selected
// instance-type to deploy function.
Clusters param.Field[[]string] `json:"clusters"`
Configuration param.Field[interface{}] `json:"configuration"`
// Max request concurrency between 1 (default) and 1024.
MaxRequestConcurrency param.Field[int64] `json:"maxRequestConcurrency"`
// Preferred order of deployment if there are several gpu specs.
PreferredOrder param.Field[int64] `json:"preferredOrder"`
// List of regions allowed to deploy. The instance or worker node will be in one of
// the specified geographical regions.
Regions param.Field[[]string] `json:"regions"`
}
func (r FunctionDeploymentFunctionVersionUpdateParamsDeploymentSpecification) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type FunctionDeploymentFunctionVersionDeleteParams struct {
// Query param to deactivate function for graceful shutdown
Graceful param.Field[bool] `query:"graceful"`
}
// URLQuery serializes [FunctionDeploymentFunctionVersionDeleteParams]'s query
// parameters as `url.Values`.
func (r FunctionDeploymentFunctionVersionDeleteParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}