Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dedibox): add waiter support dedibox #4024

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/namespaces/dedibox/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

cmds.MustFind("dedibox", "server", "create").Override(serviceCreateBuilder)

for _, commandPath := range [][]string{
{"dedibox", "server", "list"},
{"dedibox", "service", "list"},
Expand Down
1 change: 1 addition & 0 deletions internal/namespaces/dedibox/v1/custom_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package dedibox
50 changes: 50 additions & 0 deletions internal/namespaces/dedibox/v1/custom_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dedibox

import (
"context"
"errors"
"fmt"
"github.com/scaleway/scaleway-cli/v2/internal/core"

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / Ensure docs are generated

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-and-test (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-and-test (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:

Check failure on line 7 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, ubuntu-latest)

no required module provides package github.com/scaleway/scaleway-cli/v2/internal/core; to add it:
"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"net/http"
"time"
)

const (
serviceActionTimeout = time.Minute * 60
)

const (
serviceActionCreate = iota
serviceActionDelete
)

func serviceCreateBuilder(c *core.Command) *core.Command {
c.WaitFunc = waitForServiceFunc(serviceActionCreate)
return c
}

func waitForServiceFunc(action int) core.WaitFunc {
return func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
service, err := dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService(&dedibox.WaitForServiceRequest{
ServiceID: respI.(*dedibox.Service).ID,
Zone: argsI.(*dedibox.CreateServerRequest).Zone,
Timeout: scw.TimeDurationPtr(serviceActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
switch action {
case serviceActionCreate:
return service, err
case serviceActionDelete:
if err != nil {
notFoundError := &scw.ResourceNotFoundError{}
responseError := &scw.ResponseError{}
if errors.As(err, &responseError) && responseError.StatusCode == http.StatusNotFound || errors.As(err, &notFoundError) {
return fmt.Sprintf("Server %s successfully deleted.", respI.(*dedibox.Service).ID), nil
}
}
}
return nil, err
}
}
Loading