Skip to content

Commit

Permalink
doc: add create server exemple (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome-quere authored Sep 6, 2019
1 parent 2dcb84a commit 1a11352
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ func Example_listServers() {
fmt.Println(response)
}

func Example_createServer() {

// Create a Scaleway client
client, err := scw.NewClient(
scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials
scw.WithDefaultOrganizationID("ORGANIZATION_ID"),
scw.WithDefaultZone(scw.ZoneFrPar1),
)
if err != nil {
panic(err)
}

// Create SDK objects for Scaleway Instance and marketplace
instanceAPI := instance.NewAPI(client)

serverType := "DEV1-S"
image := "ubuntu-bionic"

// Create a new DEV1-S server
createRes, err := instanceAPI.CreateServer(&instance.CreateServerRequest{
Name: "my-server-01",
CommercialType: serverType,
Image: image,
DynamicIPRequired: scw.BoolPtr(true),
})
if err != nil {
panic(err)
}

// Start the server and wait until it's ready.
err = instanceAPI.ServerActionAndWait(&instance.ServerActionAndWaitRequest{
ServerID: createRes.Server.ID,
Action: instance.ServerActionPoweron,
Timeout: 5 * time.Minute,
})
if err != nil {
panic(err)
}
}

func Example_rebootAllServers() {

// Create a Scaleway client
Expand Down

0 comments on commit 1a11352

Please sign in to comment.