glesys

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2017 License: MIT Imports: 12 Imported by: 0

README

glesys-go

This is the official client library for interacting with the GleSYS API.

Requirements

  • Go 1.7 or higher (relies on context)

Getting Started

Installation
go get github.com/glesys/glesys-go
Authentication

To use the glesys-go library you need a GleSYS Cloud account and a valid API key. You can sign up for an account at https://glesys.com/signup. After signing up visit https://customer.glesys.com to create an API key for your Project.

Set up a Client
client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")
Create a Server
// Create a Server
server, err := client.Servers.Create(context.Background(), glesys.CreateServerParams{Password: "..."}.WithDefaults())
List all Servers
// List all Servers
servers, err := client.Servers.List(context.Background())
User agent

To be able to monitor usage and help track down issues, we encourage you to provide a user agent string identifying your application or library. Recommended syntax is my-library/version or www.example.com.

Context

glesys-go uses Go's context library to handle timeouts and deadlines. All functions making HTTP requests requires a context argument.

Documentation

Full documentation is available at https://godoc.org/github.com/glesys/glesys-go.

Contribute

We love Pull Requests ♥
  1. Fork the repo.
  2. Make sure to run the tests to verify that you're starting with a clean slate.
  3. Add a test for your change, make sure it fails. Refactoring existing code or improving documentation does not require new tests.
  4. Make the changes and ensure the test pass.
  5. Commit your changes, push to your fork and submit a Pull Request.
Syntax

Please use the formatting provided by gofmt.

License

The contents of this repository are distributed under the MIT license, see LICENSE.

Documentation

Overview

Package glesys is the official Go client for interacting with the GleSYS API.

Please note that only a subset of features available in the GleSYS API has been implemented. We greatly appreciate contributions.

Getting Started

To get started you need to signup for an account to GleSYS Cloud and create an API key. Signup is available at https://glesys.com/signup and API keys can be created at https://customer.glesys.com.

client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

CL12345 is the key of the Project you want to work with.

To be able to monitor usage and help track down issues, we encourage you to provide a user agent string identifying your application or library. Recommended syntax is "my-library/version" or "www.example.com".

The different modules of the GleSYS API are available on the client. For example:

client.IPs.List(...)
client.Servers.Create(...)

More examples provided below.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AvailableIPsParams

type AvailableIPsParams struct {
	DataCenter string `json:"datacenter"`
	Platform   string `json:"platform"`
	Version    int    `json:"ipversion"`
}

AvailableIPsParams is used to filter results when listing available IP addresses

type Client

type Client struct {
	IPs     *IPService
	Servers *ServerService
	// contains filtered or unexported fields
}

Client is used to interact with the GleSYS API

func NewClient

func NewClient(project, apiKey, userAgent string) *Client

NewClient creates a new Client for interacting with the GleSYS API. This is the main entrypoint for API interactions.

type CreateServerParams

type CreateServerParams struct {
	Bandwidth    int    `json:"bandwidth"`
	CampaignCode string `json:"campaigncode,omitempty"`
	CPU          int    `json:"cpucores"`
	DataCenter   string `json:"datacenter"`
	Description  string `json:"description,omitempty"`
	Hostname     string `json:"hostname"`
	IPv4         string `json:"ip"`
	IPv6         string `json:"ipv6"`
	Memory       int    `json:"memorysize"`
	Password     string `json:"rootpassword,omitempty"`
	Platform     string `json:"platform"`
	PublicKey    string `json:"sshkey,omitempty"`
	Storage      int    `json:"disksize"`
	Template     string `json:"templatename"`
}

CreateServerParams is used when creating a new server

func (CreateServerParams) WithDefaults

func (p CreateServerParams) WithDefaults() CreateServerParams

WithDefaults populates the parameters with default values. Existing parameters will not be overwritten.

type DestroyServerParams

type DestroyServerParams struct {
	KeepIP bool `json:"keepip"`
}

DestroyServerParams is used when destroying a server

type IP

type IP struct {
	Address string `json:"ipaddress"`
}

IP represents an IP address

type IPService

type IPService struct {
	// contains filtered or unexported fields
}

IPService provides functions to interact with IP addresses

func (*IPService) Available

func (s *IPService) Available(context context.Context, params AvailableIPsParams) (*[]IP, error)

Available returns a list of IP addresses available for reservation

Example
package main

import (
	"context"
	"fmt"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	ips, _ := client.IPs.Available(context.Background(), glesys.AvailableIPsParams{
		DataCenter: "Falkenberg",
		Platform:   "OpenVZ",
		Version:    4,
	})

	for _, ip := range *ips {
		fmt.Println(ip.Address)
	}
}
Output:

func (*IPService) Release

func (s *IPService) Release(context context.Context, ipAddress string) error

Release releases a reserved IP address

Example
package main

import (
	"context"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	client.IPs.Release(context.Background(), "1.2.3.4")
}
Output:

func (*IPService) Reserve

func (s *IPService) Reserve(context context.Context, ipAddress string) (*IP, error)

Reserve reserves an available IP address

Example
package main

import (
	"context"
	"fmt"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	ip, _ := client.IPs.Reserve(context.Background(), "1.2.3.4")

	fmt.Println(ip.Address)
}
Output:

func (*IPService) Reserved

func (s *IPService) Reserved(context context.Context) (*[]IP, error)

Reserved returns a list of reserved IP addresses

Example
package main

import (
	"context"
	"fmt"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	ips, _ := client.IPs.Reserved(context.Background())

	for _, ip := range *ips {
		fmt.Println(ip.Address)
	}
}
Output:

type Server

type Server struct {
	DataCenter string `json:"datacenter"`
	Hostname   string `json:"hostname"`
	ID         string `json:"serverid"`
	Platform   string `json:"platform"`
}

Server is a simplified version of a server

type ServerDetails

type ServerDetails struct {
	CPU        int    `json:"cpucores"`
	DataCenter string `json:"datacenter"`
	Hostname   string `json:"hostname"`
	ID         string `json:"serverid"`
	IPList     []IP   `json:"iplist"`
	Platform   string `json:"platform"`
	Memory     int    `json:"memorysize"`
	State      string `json:"state"`
	Storage    int    `json:"disksize"`
}

ServerDetails is a more complete representation of a server

func (*ServerDetails) IsLocked

func (sd *ServerDetails) IsLocked() bool

IsLocked returns true if the server is currently locked, false otherwise

func (*ServerDetails) IsRunning

func (sd *ServerDetails) IsRunning() bool

IsRunning returns true if the server is currently running, false otherwise

type ServerService

type ServerService struct {
	// contains filtered or unexported fields
}

ServerService provides functions to interact with servers

func (*ServerService) Create

func (s *ServerService) Create(context context.Context, params CreateServerParams) (*ServerDetails, error)

Create creates a new server

Example
package main

import (
	"context"
	"fmt"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	server, _ := client.Servers.Create(context.Background(), glesys.CreateServerParams{
		Bandwidth:    100,
		CampaignCode: "",
		CPU:          2,
		DataCenter:   "Falkenberg",
		Description:  "",
		Hostname:     "my-hostname",
		IPv4:         "any",
		IPv6:         "any",
		Memory:       2048,
		Password:     "...",
		Platform:     "OpenVZ",
		PublicKey:    "...",
		Storage:      50,
		Template:     "Debian 8 64-bit",
	})

	fmt.Println(server.ID)

	// NOTE: You can also use the WithDefaults() to provide defaults values for
	// all required parameters except Password (or PublicKey)

	server2, _ := client.Servers.Create(context.Background(), glesys.CreateServerParams{
		Password: "...",
	}.WithDefaults())

	fmt.Println(server2.ID)
}
Output:

func (*ServerService) Destroy

func (s *ServerService) Destroy(context context.Context, serverID string, params DestroyServerParams) error

Destroy deletes a server

Example
package main

import (
	"context"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	client.Servers.Destroy(context.Background(), "vz12345", glesys.DestroyServerParams{
		KeepIP: true, // KeepIP defaults to false
	})
}
Output:

func (*ServerService) Details

func (s *ServerService) Details(context context.Context, serverID string) (*ServerDetails, error)

Details returns detailed information about one server

Example
package main

import (
	"context"
	"fmt"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	server, _ := client.Servers.Details(context.Background(), "vz12345")

	fmt.Println(server.Hostname)
}
Output:

func (*ServerService) List

func (s *ServerService) List(context context.Context) (*[]Server, error)

List returns a list of servers

Example
package main

import (
	"context"
	"fmt"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	servers, _ := client.Servers.List(context.Background())

	for _, server := range *servers {
		fmt.Println(server.Hostname)
	}
}
Output:

func (*ServerService) Start

func (s *ServerService) Start(context context.Context, serverID string) error

Start turns on a server

Example
package main

import (
	"context"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	client.Servers.Start(context.Background(), "vz12345")
}
Output:

func (*ServerService) Stop

func (s *ServerService) Stop(context context.Context, serverID string, params StopServerParams) error

Stop turns off a server

Example
package main

import (
	"context"

	glesys "github.com/glesys/glesys-go"
)

func main() {
	client := glesys.NewClient("CL12345", "your-api-key", "my-application/0.0.1")

	client.Servers.Stop(context.Background(), "vz12345", glesys.StopServerParams{
		Type: "reboot", // Type "soft", "hard" and "reboot" available
	})
}
Output:

type StopServerParams

type StopServerParams struct {
	Type string `json:"type"`
}

StopServerParams is used when stopping a server. Supported types are `soft` `hard` and `reboot`.

Jump to

Keyboard shortcuts

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