lyrasdkgo

package module
v0.0.0-...-ea44b77 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: Apache-2.0 Imports: 0 Imported by: 0

README

Lyra GO SDK

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

Lyra is a single way to create, deploy and sell and fund valueable GitNFT's on LyraSwap. We help thousands of engineers and investors, and corporations.

Documentation

Installation

go get github.com/lyraswap/lyra-sdk-go

Getting Started

package main

import (
	"fmt"

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

func main() {

	// Create a Lyra client
	client, err := scw.NewClient(
		// Get your credentials at https://console.lyra.com/project/credentials
		scw.WithDefaultOrganizationID("ORGANISATION_ID"),
		scw.WithAuth("ACCESS_KEY", "SECRET_KEY"),
	)
	if err != nil {
		panic(err)
	}

	// Create SDK objects for Lyra 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 Lyra Slack community, we are waiting for you on #opensource.

Documentation

Overview

Package lyrasdkgo is the Lyra 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 Lyra client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.lyra.com/project/credentials
)
if err != nil {
	// handle error
}

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

// Start using the SDKs
_, _ = instanceAPI, lbAPI
Output:

Example (ApiClientWithConfig)
// Get Lyra Config
config, err := scw.LoadConfig()
if err != nil {
	// handle error
}

// Use active profile
profile, err := config.GetActiveProfile()
if err != nil {
	// handle error
}

// Create a Lyra 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 Lyra Products
instanceAPI := instance.NewAPI(client)
lbAPI := lb.NewAPI(client)

// Start using the SDKs
_, _ = instanceAPI, lbAPI
Output:

Example (CreateLoadBalancer)
// Create a Lyra client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.lyra.com/project/credentials
)
if err != nil {
	// handle error
}

// Create SDK objects for Lyra 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 Lyra client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.lyra.com/project/credentials
	scw.WithDefaultOrganizationID("ORGANIZATION_ID"),
	scw.WithDefaultZone(scw.ZoneFrPar1),
)
if err != nil {
	panic(err)
}

// Create SDK objects for Lyra 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 Lyra client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.lyra.com/project/credentials
)
if err != nil {
	// handle error
}

// Create SDK objects for Lyra 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 Lyra client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.lyra.com/project/credentials
)
if err != nil {
	// handle error
}

// Create SDK objects for Lyra 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 Lyra client
client, err := scw.NewClient(
	scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.lyra.com/project/credentials
	scw.WithDefaultZone(scw.ZoneFrPar1),
)
if err != nil {
	panic(err)
}

// Create SDK objects for Lyra 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.
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.
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.
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.
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.
marketplace/v1
Package marketplace provides methods and message types of the marketplace v1 API.
Package marketplace provides methods and message types of the marketplace v1 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/v1alpha1
Package mnq provides methods and message types of the mnq v1alpha1 API.
Package mnq provides methods and message types of the mnq v1alpha1 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.
redis/v1alpha1
Package redis provides methods and message types of the redis v1alpha1 API.
Package redis provides methods and message types of the redis v1alpha1 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.
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.
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.
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