Documentation ¶
Overview ¶
Package scalewaysdkgo is the Scaleway API SDK for Go.
In order to use the available APIs, create a `Client`. Once created, it can be used to instantiate an API. To use the `instance` API, for example, instantiate it (with the client object) `instance.NewApi(client)`. On this instance API, all the available API functions can be called.
Example (ApiClient) ¶
// Create a Scaleway client client, err := scw.NewClient( scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials ) if err != nil { // handle error } // Create SDK objects for specific Scaleway Products instance := instance.NewAPI(client) lb := lb.NewAPI(client) // Start using the SDKs _, _ = instance, lb
Output:
Example (ApiClientWithConfig) ¶
// Get Scaleway Config config, err := scw.LoadConfig() if err != nil { // handle error } // Use active profile profile, err := config.GetActiveProfile() if err != nil { // handle error } // Create a Scaleway client client, err := scw.NewClient( scw.WithProfile(profile), scw.WithEnv(), // env variable may overwrite profile values ) if err != nil { // handle error } // Create SDK objects for specific Scaleway Products instance := instance.NewAPI(client) lb := lb.NewAPI(client) // Start using the SDKs _, _ = instance, lb
Output:
Example (CreateLoadBalancer) ¶
// Create a Scaleway client client, err := scw.NewClient( scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials ) if err != nil { // handle error } // Create SDK objects for Scaleway LoadConfig Balancer product lbAPI := lb.NewAPI(client) // Call the CreateLb method on the LB SDK to create a new load balancer. newLb, err := lbAPI.CreateLb(&lb.CreateLbRequest{ Name: "My new load balancer", Description: "This is a example of a load balancer", OrganizationID: "000a115d-2852-4b0a-9ce8-47f1134ba95a", Region: scw.RegionFrPar, }) if err != nil { // handle error } // Do something with the newly created LB... fmt.Println(newLb)
Output:
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) }
Output:
Example (ListServers) ¶
// Create a Scaleway client client, err := scw.NewClient( scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials ) if err != nil { // handle error } // Create SDK objects for Scaleway Instance product instanceAPI := instance.NewAPI(client) // Call the ListServers method on the Instance SDK response, err := instanceAPI.ListServers(&instance.ListServersRequest{ Zone: scw.ZoneFrPar1, }) if err != nil { // handle error } // Do something with the response... fmt.Println(response)
Output:
Example (RebootAllServers) ¶
// 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.WithDefaultZone(scw.ZoneFrPar1), ) if err != nil { panic(err) } // Create SDK objects for Scaleway Instance product instanceAPI := instance.NewAPI(client) // Call the ListServers method of the Instance SDK response, err := instanceAPI.ListServers(&instance.ListServersRequest{}) if err != nil { panic(err) } // For each server if they are running we reboot them using ServerActionAndWait for _, server := range response.Servers { if server.State == instance.ServerStateRunning { fmt.Println("Rebooting server with ID", server.ID) err = instanceAPI.ServerActionAndWait(&instance.ServerActionAndWaitRequest{ ServerID: server.ID, Action: instance.ServerActionReboot, Timeout: 5 * time.Minute, }) if err != nil { panic(err) } } } fmt.Println("All servers were successfully rebooted")
Output:
Click to show internal directories.
Click to hide internal directories.