Skip to content

Commit 37ae749

Browse files
committed
update cassettes AllUsage
1 parent 31fafe3 commit 37ae749

9 files changed

+3147
-106
lines changed

cmd/scw/testdata/test-all-usage-inference-deployment-create-usage.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ ARGS:
1414
[tags.{index}] List of tags to apply to the deployment
1515
[min-size] Defines the minimum size of the pool
1616
[max-size] Defines the maximum size of the pool
17+
[endpoints.{index}.is-public=false] Will configure your public endpoint if true
1718
[endpoints.{index}.private-network.private-network-id]
1819
[endpoints.{index}.disable-auth=false] Disable the authentication on the endpoint.
1920
[quantization.bits] The number of bits each model parameter should be quantized to. The quantization method is chosen based on this value.
2021
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)
2122

2223
FLAGS:
2324
-h, --help help for create
25+
-w, --wait wait until the deployment is ready
2426

2527
GLOBAL FLAGS:
2628
-c, --config string The path to the config file

cmd/scw/testdata/test-all-usage-inference-deployment-delete-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ARGS:
1111

1212
FLAGS:
1313
-h, --help help for delete
14+
-w, --wait wait until the deployment is ready
1415

1516
GLOBAL FLAGS:
1617
-c, --config string The path to the config file

internal/namespaces/inference/v1/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func GetCommands() *core.Commands {
1919
human.RegisterMarshalerFunc(inference.Deployment{}, DeploymentMarshalerFunc)
2020

2121
cmds.MustFind("inference", "deployment", "create").Override(deploymentCreateBuilder)
22+
cmds.MustFind("inference", "deployment", "delete").Override(deploymentDeleteBuilder)
2223

2324
return cmds
2425
}

internal/namespaces/inference/v1/custom_deployment.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package inference
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
7+
"net/http"
58
"reflect"
6-
"strings"
79
"time"
810

911
"github.com/fatih/color"
@@ -15,6 +17,8 @@ import (
1517

1618
const (
1719
deploymentActionTimeout = 60 * time.Minute
20+
deploymentActionCreate = 1
21+
deploymentActionDelete = 2
1822
)
1923

2024
var deploymentStateMarshalSpecs = human.EnumMarshalSpecs{
@@ -43,40 +47,13 @@ func DeploymentMarshalerFunc(i any, opt *human.MarshalOpt) (string, error) {
4347
return str, nil
4448
}
4549

46-
var completeListNodeTypesCache *inference.ListNodeTypesResponse
50+
func deploymentDeleteBuilder(c *core.Command) *core.Command {
51+
c.WaitFunc = waitForDeploymentFunc(deploymentActionDelete)
4752

48-
func autocompleteDeploymentNodeType(
49-
ctx context.Context,
50-
prefix string,
51-
request any,
52-
) core.AutocompleteSuggestions {
53-
req := request.(*inference.CreateDeploymentRequest)
54-
suggestions := core.AutocompleteSuggestions(nil)
55-
56-
client := core.ExtractClient(ctx)
57-
api := inference.NewAPI(client)
58-
59-
if completeListNodeTypesCache == nil {
60-
res, err := api.ListNodeTypes(&inference.ListNodeTypesRequest{
61-
Region: req.Region,
62-
})
63-
if err != nil {
64-
return nil
65-
}
66-
completeListNodeTypesCache = res
67-
}
68-
69-
for _, nodeType := range completeListNodeTypesCache.NodeTypes {
70-
if strings.HasPrefix(nodeType.Name, prefix) {
71-
suggestions = append(suggestions, nodeType.Name)
72-
}
73-
}
74-
75-
return suggestions
53+
return c
7654
}
7755

7856
func deploymentCreateBuilder(c *core.Command) *core.Command {
79-
c.ArgSpecs.GetByName("node-type-name").AutoCompleteFunc = autocompleteDeploymentNodeType
8057
type llmInferenceEndpointSpecCustom struct {
8158
*inference.EndpointSpec
8259
IsPublic bool `json:"is-public"`
@@ -96,17 +73,8 @@ func deploymentCreateBuilder(c *core.Command) *core.Command {
9673

9774
c.ArgsType = reflect.TypeOf(llmInferenceCreateDeploymentRequestCustom{})
9875

99-
c.WaitFunc = func(ctx context.Context, _, respI any) (any, error) {
100-
api := inference.NewAPI(core.ExtractClient(ctx))
76+
c.WaitFunc = waitForDeploymentFunc(deploymentActionCreate)
10177

102-
return api.WaitForDeployment(&inference.WaitForDeploymentRequest{
103-
DeploymentID: respI.(*inference.Deployment).ID,
104-
Region: respI.(*inference.Deployment).Region,
105-
Status: respI.(*inference.Deployment).Status,
106-
Timeout: scw.TimeDurationPtr(deploymentActionTimeout),
107-
RetryInterval: core.DefaultRetryInterval,
108-
})
109-
}
11078
c.Interceptor = func(ctx context.Context, argsI any, runner core.CommandRunner) (any, error) {
11179
deploymentCreateCustomRequest := argsI.(*llmInferenceCreateDeploymentRequestCustom)
11280
deploymentRequest := deploymentCreateCustomRequest.CreateDeploymentRequest
@@ -145,3 +113,35 @@ func deploymentCreateBuilder(c *core.Command) *core.Command {
145113

146114
return c
147115
}
116+
117+
func waitForDeploymentFunc(action int) core.WaitFunc {
118+
return func(ctx context.Context, _, respI any) (any, error) {
119+
deployment, err := inference.NewAPI(core.ExtractClient(ctx)).WaitForDeployment(&inference.WaitForDeploymentRequest{
120+
DeploymentID: respI.(*inference.Deployment).ID,
121+
Region: respI.(*inference.Deployment).Region,
122+
Timeout: scw.TimeDurationPtr(deploymentActionTimeout),
123+
RetryInterval: core.DefaultRetryInterval,
124+
})
125+
126+
switch action {
127+
case deploymentActionCreate:
128+
return deployment, err
129+
case deploymentActionDelete:
130+
if err != nil {
131+
// if we get a 404 here, it means the resource was successfully deleted
132+
notFoundError := &scw.ResourceNotFoundError{}
133+
responseError := &scw.ResponseError{}
134+
if errors.As(err, &responseError) &&
135+
responseError.StatusCode == http.StatusNotFound ||
136+
errors.As(err, &notFoundError) {
137+
return fmt.Sprintf(
138+
"Server %s successfully deleted.",
139+
respI.(*inference.Deployment).ID,
140+
), nil
141+
}
142+
}
143+
}
144+
145+
return nil, err
146+
}
147+
}

internal/namespaces/inference/v1/custom_deployment_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ func Test_CreateDeploymentPrivateEndpoint(t *testing.T) {
5151
Commands: cmds,
5252
BeforeFunc: CreatePN(),
5353
Cmd: fmt.Sprintf(
54-
"scw inference deployment create model-id=%s node-type-name=%s accept-eula=true endpoints.0.private-network.private-network-id={{ .PN.ID }}",
54+
"scw inference deployment create model-id=%s node-type-name=H100-SXM-2 accept-eula=true endpoints.0.private-network.private-network-id={{ .PN.ID }} --wait",
5555
ModelID,
56-
NodeTypeName,
5756
),
5857
Check: core.TestCheckCombine(
5958
core.TestCheckGolden(),
6059
),
6160
AfterFunc: core.AfterFuncCombine(
61+
core.ExecAfterCmd("scw inference deployment delete {{ .CmdResult.ID }} --wait"),
6262
DeletePrivateNetwork(),
63-
DeleteDeployment(),
6463
),
6564
}))
6665
}

internal/namespaces/inference/v1/helper_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,3 @@ func CreatePN() core.BeforeFunc {
2727
func DeletePrivateNetwork() core.AfterFunc {
2828
return core.ExecAfterCmd("scw vpc private-network delete {{ .PN.ID }}")
2929
}
30-
31-
func DeleteDeployment() core.AfterFunc {
32-
return core.ExecAfterCmd("scw inference deployment delete {{ .DEPLOYMENT.ID }}")
33-
}

0 commit comments

Comments
 (0)