-
Notifications
You must be signed in to change notification settings - Fork 152
baremetal: add install command with a wait flag #873
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
659d26b
baremetal: add install command with a wait flag
remyleone 05d3cc2
Fix
remyleone 8d0d620
Fix
remyleone 456173b
Update internal/namespaces/baremetal/v1alpha1/custom_server_install.go
remyleone 1a5d09b
Update internal/namespaces/baremetal/v1alpha1/custom_server_install.go
remyleone 1111abf
Fix
remyleone ba038cc
Fix
remyleone f10740d
Fix
remyleone 191c5c6
FIx
remyleone bcb1995
Update internal/namespaces/baremetal/v1alpha1/custom_server_install.go
remyleone a33d599
FIx
remyleone 247c2f7
Fix
remyleone 1ffd1ee
Fix
remyleone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
internal/namespaces/baremetal/v1alpha1/custom_server_install.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package baremetal | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/scaleway/scaleway-cli/internal/core" | ||
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1" | ||
) | ||
|
||
func serverInstallBuilder(c *core.Command) *core.Command { | ||
c.Examples = []*core.Example{ | ||
{ | ||
Short: "Install an OS on a given server", | ||
Request: `{"os_id":"11111111-1111-1111-1111-111111111111","server_id":"11111111-1111-1111-1111-111111111111"}`, | ||
}, | ||
} | ||
|
||
c.SeeAlsos = []*core.SeeAlso{ | ||
{ | ||
Short: "List OS (useful to get all OS IDs)", | ||
Command: "scw baremetal os list", | ||
}, | ||
{ | ||
Short: "Create a server", | ||
Command: "scw baremetal server create", | ||
}, | ||
} | ||
|
||
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) { | ||
api := baremetal.NewAPI(core.ExtractClient(ctx)) | ||
return api.WaitForServerInstall(&baremetal.WaitForServerInstallRequest{ | ||
Zone: argsI.(*baremetal.InstallServerRequest).Zone, | ||
ServerID: respI.(*baremetal.Server).ID, | ||
Timeout: serverActionTimeout, | ||
}) | ||
} | ||
|
||
return c | ||
} |
38 changes: 38 additions & 0 deletions
38
internal/namespaces/baremetal/v1alpha1/custom_server_install_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package baremetal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/scaleway/scaleway-cli/internal/core" | ||
account "github.com/scaleway/scaleway-cli/internal/namespaces/account/v2alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
func Test_InstallServer(t *testing.T) { | ||
// All test below should succeed to create an instance. | ||
t.Run("Simple", func(t *testing.T) { | ||
// baremetal api requires that the key must be at least 1024 bits long. Regardless of the algorithm | ||
sshKey := `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCbJuYSOQc01zjHsMyn4OUsW61cqRvttKt3StJgbvt2WBuGpwi1/5RtSoMQpudYlZpdeivFb21S8QRas8zcOc+6WqgWa2nj/8yA+cauRlV6CMWY+hOTkkg39xaekstuQ+WR2/AP7O/9hjVx5735+9ZNIxxHsFjVYdBEuk9gEX+1Rw== foobar@foobar` | ||
osID := `d859aa89-8b4a-4551-af42-ff7c0c27260a` // Ubuntu 18.04 | ||
cmds := GetCommands() | ||
cmds.Merge(account.GetCommands()) | ||
|
||
t.Run("With ID", core.Test(&core.TestConfig{ | ||
BeforeFunc: core.BeforeFuncCombine( | ||
addSSH("key", sshKey), | ||
createServerAndWait("Server"), | ||
), | ||
Commands: cmds, | ||
Cmd: "scw baremetal server install {{ .Server.ID }} hostname=test-install-server ssh-key-ids.0={{ .key.ID }} os-id=" + osID + " -w", | ||
Check: core.TestCheckCombine( | ||
core.TestCheckGolden(), | ||
core.TestCheckExitCode(0), | ||
), | ||
AfterFunc: core.AfterFuncCombine( | ||
deleteSSH("key"), | ||
deleteServer("Server"), | ||
), | ||
DefaultZone: scw.ZoneFrPar2, | ||
})) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.