scalewaysdkgo

package module
v1.0.0-beta.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

PkgGoDev GitHub Actions GoReportCard

Scaleway GO SDK

⚠ This is an early release, keep in mind that the API can break

Scaleway is a single way to create, deploy and scale your infrastructure in the cloud. We help thousands of businesses to run their infrastructures easily.

Documentation

Installation

go get github.com/scaleway/scaleway-sdk-go

Getting Started

package main

import (
	"fmt"

	"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
	"github.com/scaleway/scaleway-sdk-go/scw"
	"github.com/scaleway/scaleway-sdk-go/utils"
)

func main() {

	// Create a Scaleway client
	client, err := scw.NewClient(
		// Get your organization ID at https://console.scaleway.com/organization/settings
		scw.WithDefaultOrganizationID("SCW_DEFAULT_ORGANIZATION_ID"),
		// Get your credentials at https://console.scaleway.com/iam/api-keys
		scw.WithAuth("SCW_ACCESS_KEY", "SCW_SECRET_KEY"),
		// Get more about our availability zones at https://www.scaleway.com/en/docs/console/my-account/reference-content/products-availability/
		scw.WithDefaultRegion("SCW_REGION"),
	)
	if err != nil {
		panic(err)
	}

	// 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 {
		panic(err)
	}

	// Do something with the response...
	for _, server := range response.Servers {
		fmt.Println("Server", server.ID, server.Name)
	}

}

Examples

You can find additional examples in the GoDoc.

Development

This repository is at its early stage and is still in active development. If you are looking for a way to contribute please read CONTRIBUTING.md.

Reach us

We love feedback. Feel free to reach us on Scaleway Slack community, we are waiting for you on #opensource.

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/project/credentials
)
if err != nil {
	// handle error
}

// Create SDK objects for specific Scaleway Products
instanceAPI := instance.NewAPI(client)
lbAPI := lb.NewAPI(client)

// Start using the SDKs
_, _ = instanceAPI, lbAPI
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
instanceAPI := instance.NewAPI(client)
lbAPI := lb.NewAPI(client)

// Start using the SDKs
_, _ = instanceAPI, lbAPI
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/project/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: scw.StringPtr("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/project/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_focal"

// 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.
timeout := 5 * time.Minute
err = instanceAPI.ServerActionAndWait(&instance.ServerActionAndWaitRequest{
	ServerID: createRes.Server.ID,
	Action:   instance.ServerActionPoweron,
	Timeout:  &timeout,
})
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/project/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 (ListServersWithZones)
// Create a Scaleway client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/project/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{},
	// Add WithZones option to list servers from multiple zones
	scw.WithZones(scw.ZoneFrPar1, scw.ZoneNlAms1, scw.ZonePlWaw1))
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/project/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
timeout := 5 * time.Minute
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:  &timeout,
		})
		if err != nil {
			panic(err)
		}
	}
}
fmt.Println("All servers were successfully rebooted")
Output:

Directories

Path Synopsis
api
account/v2
Package account provides methods and message types of the account v2 API.
Package account provides methods and message types of the account v2 API.
account/v2alpha1
Package account provides methods and message types of the account v2alpha1 API.
Package account provides methods and message types of the account v2alpha1 API.
account/v3
Package account provides methods and message types of the account v3 API.
Package account provides methods and message types of the account v3 API.
applesilicon/v1alpha1
Package applesilicon provides methods and message types of the applesilicon v1alpha1 API.
Package applesilicon provides methods and message types of the applesilicon v1alpha1 API.
baremetal/v1
Package baremetal provides methods and message types of the baremetal v1 API.
Package baremetal provides methods and message types of the baremetal v1 API.
billing/v2alpha1
Package billing provides methods and message types of the billing v2alpha1 API.
Package billing provides methods and message types of the billing v2alpha1 API.
billing/v2beta1
Package billing provides methods and message types of the billing v2beta1 API.
Package billing provides methods and message types of the billing v2beta1 API.
block/v1alpha1
Package block provides methods and message types of the block v1alpha1 API.
Package block provides methods and message types of the block v1alpha1 API.
cockpit/v1beta1
Package cockpit provides methods and message types of the cockpit v1beta1 API.
Package cockpit provides methods and message types of the cockpit v1beta1 API.
container/v1beta1
Package container provides methods and message types of the container v1beta1 API.
Package container provides methods and message types of the container v1beta1 API.
dedibox/v1
Package dedibox provides methods and message types of the dedibox v1 API.
Package dedibox provides methods and message types of the dedibox v1 API.
documentdb/v1beta1
Package documentdb provides methods and message types of the documentdb v1beta1 API.
Package documentdb provides methods and message types of the documentdb v1beta1 API.
domain/v2beta1
Package domain provides methods and message types of the domain v2beta1 API.
Package domain provides methods and message types of the domain v2beta1 API.
flexibleip/v1alpha1
Package flexibleip provides methods and message types of the flexibleip v1alpha1 API.
Package flexibleip provides methods and message types of the flexibleip v1alpha1 API.
function/v1beta1
Package function provides methods and message types of the function v1beta1 API.
Package function provides methods and message types of the function v1beta1 API.
iam/v1alpha1
Package iam provides methods and message types of the iam v1alpha1 API.
Package iam provides methods and message types of the iam v1alpha1 API.
instance/v1
Package instance provides methods and message types of the instance v1 API.
Package instance provides methods and message types of the instance v1 API.
iot/v1
Package iot provides methods and message types of the iot v1 API.
Package iot provides methods and message types of the iot v1 API.
ipam/v1
Package ipam provides methods and message types of the ipam v1 API.
Package ipam provides methods and message types of the ipam v1 API.
ipam/v1alpha1
Package ipam provides methods and message types of the ipam v1alpha1 API.
Package ipam provides methods and message types of the ipam v1alpha1 API.
ipfs/v1alpha1
Package ipfs provides methods and message types of the ipfs v1alpha1 API.
Package ipfs provides methods and message types of the ipfs v1alpha1 API.
jobs/v1alpha1
Package jobs provides methods and message types of the jobs v1alpha1 API.
Package jobs provides methods and message types of the jobs v1alpha1 API.
k8s/v1
Package k8s provides methods and message types of the k8s v1 API.
Package k8s provides methods and message types of the k8s v1 API.
lb/v1
Package lb provides methods and message types of the lb v1 API.
Package lb provides methods and message types of the lb v1 API.
llm_inference/v1beta1
Package llm_inference provides methods and message types of the llm_inference v1beta1 API.
Package llm_inference provides methods and message types of the llm_inference v1beta1 API.
marketplace/v2
Package marketplace provides methods and message types of the marketplace v2 API.
Package marketplace provides methods and message types of the marketplace v2 API.
mnq/v1beta1
Package mnq provides methods and message types of the mnq v1beta1 API.
Package mnq provides methods and message types of the mnq v1beta1 API.
rdb/v1
Package rdb provides methods and message types of the rdb v1 API.
Package rdb provides methods and message types of the rdb v1 API.
redis/v1
Package redis provides methods and message types of the redis v1 API.
Package redis provides methods and message types of the redis v1 API.
registry/v1
Package registry provides methods and message types of the registry v1 API.
Package registry provides methods and message types of the registry v1 API.
secret/v1alpha1
Package secret provides methods and message types of the secret v1alpha1 API.
Package secret provides methods and message types of the secret v1alpha1 API.
secret/v1beta1
Package secret provides methods and message types of the secret v1beta1 API.
Package secret provides methods and message types of the secret v1beta1 API.
serverless_sqldb/v1alpha1
Package serverless_sqldb provides methods and message types of the serverless_sqldb v1alpha1 API.
Package serverless_sqldb provides methods and message types of the serverless_sqldb v1alpha1 API.
std
Package std provides methods and message types of the std API.
Package std provides methods and message types of the std API.
tem/v1alpha1
Package tem provides methods and message types of the tem v1alpha1 API.
Package tem provides methods and message types of the tem v1alpha1 API.
test/v1
Package test provides methods and message types of the test v1 API.
Package test provides methods and message types of the test v1 API.
vpc/v1
Package vpc provides methods and message types of the vpc v1 API.
Package vpc provides methods and message types of the vpc v1 API.
vpc/v2
Package vpc provides methods and message types of the vpc v2 API.
Package vpc provides methods and message types of the vpc v2 API.
vpcgw/v1
Package vpcgw provides methods and message types of the vpcgw v1 API.
Package vpcgw provides methods and message types of the vpcgw v1 API.
webhosting/v1alpha1
Package webhosting provides methods and message types of the webhosting v1alpha1 API.
Package webhosting provides methods and message types of the webhosting v1alpha1 API.
internal
Package validation provides format validation functions.
Package validation provides format validation functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL