gridscale

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

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

Go to latest
Published: Dec 16, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

Golang gridscale SDK

GoDoc Go Report Card Build Status Coverage Status

Introduction

This is a Go (Golang) library to consume the Gridscale API (http://www.gridscale.de).

Malte Janduda from Parce has initiated this project.

This code is not officially supported by Gridscale.

All coders are invited to use this library and send pull requests!

Usage

package main

import (
    "github.com/parce-iot/gridscale"

    "fmt"
    "os"
)

func main() {
    userID := os.Getenv("GRIDSCALE_USERID")
    apiToken := os.Getenv("GRIDSCALE_APITOKEN")
    endpoint := "https://api.gridscale.io"

    c, err := gridscale.NewClient(userID, apiToken, endpoint)
    if err != nil {
        fmt.Printf("ERROR: %s", err)
        return
    }
    
    c.GetPrices()
}

License

This library is under the Apache License v2.0. For more information have a look into the LICENSE file. When contributing to this project (e.g. by sending pull requests) you accept your work to be under the same license. To show your consent please git sign your commits (git commit -s -m 'foo').

We only accept signed commits!

Development

General

Please sign your git commits to show your consent to put your work under the Apache License v2.

Please go lint your code before committing and sending pull requests.

Please keep your pull requests small! Send multiple pull requests for bigger changes! Use the GitHub issues to talk to us beforehand.

Testing

Clone this repository into your GOPATH:

go get github.com/parce-iot/gridscale
cd $GOPATH/src/github.com/parce-iot/gridscale

At first you have to provide your gridscale API credentials as environment variables:

export GRIDSCALE_USERID=c702de16-a89f-4edb-b05a-09c7593ac65a
export GRIDSCALE_APITOKEN=5df171ddd552b7c47fc67c83100c06e1268021b2a2e5827d535ddef7333fe64b

then change into the project directory gridscale and execute

make test
Dependencies

This library uses and ships with the shopspring/decimal library (MIT License) to handle fixed-point decimal numbers.

TODO

  • Read object events
  • Create Storage Snapshots
  • Locations
  • Templates
  • ISO images
  • Deleted objects

Documentation

Overview

Package gridscale is a Go library to consume the Gridscale API (http://www.gridscale.de). The source is hosted on GitHub at https://github.com/parce-iot/gridscale

Usage:

package main

import (
    "github.com/parce-iot/gridscale"

    "fmt"
    "os"
)

func main() {
    userID := os.Getenv("GRIDSCALE_USERID")
    apiToken := os.Getenv("GRIDSCALE_APITOKEN")
    endpoint := "https://api.gridscale.io"

    c, err := gridscale.NewClient(userID, apiToken, endpoint)
    if err != nil {
        fmt.Printf("ERROR: %s", err)
        return
    }

    c.GetPrices()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the gridscale Client class

func NewClient

func NewClient(userID, authToken, endpoint string) (*Client, error)

NewClient creates a new gridscale Client. You have to provide the gridscale API user-id UUID, auth token and the API endpoint URL.

func (*Client) AddSSHKey

func (c *Client) AddSSHKey(name string, publicKey string, labels []string) (*SSHKey, error)

AddSSHKey adds a new ssh key.

func (*Client) ConnectIPAddress

func (c *Client) ConnectIPAddress(ipAddressID, serverID string) error

ConnectIPAddress maps a public IP address to a server connected to the public network.

func (*Client) ConnectIsoImage

func (c *Client) ConnectIsoImage(isoImageID, serverID string) error

ConnectIsoImage connects an ISO image as an optical disk drive to a virtual machine.

func (*Client) ConnectNetwork

func (c *Client) ConnectNetwork(networkID string, ordering int, serverID string) error

ConnectNetwork connects a server to a network. A new ethernet device is added to the server.

func (*Client) ConnectStorage

func (c *Client) ConnectStorage(storageID string, bootdevice bool, serverID string) error

ConnectStorage connects a storage volume to a server.

func (*Client) CreateIPv4

func (c *Client) CreateIPv4(locationID string, failover bool, labels []string, reverseDNS *string) (*IP, error)

CreateIPv4 creates a new IPv4 address. locationID is the location ID (required). failover defines if the IP address is a failover IP. labels is a slice of strings (optional, set to nil if not used). reverseDNS is the reverse DNS entry (optional, set to nil if not used).

func (*Client) CreateIPv6

func (c *Client) CreateIPv6(locationID string, failover bool, labels []string, reverseDNS *string) (*IP, error)

CreateIPv6 creates a new IPv6 address. locationID is the location ID (required). failover defines if the IP address is a failover IP. labels is a slice of strings (optional, set to nil if not used). reverseDNS is the reverse DNS entry (optional, set to nil if not used).

func (*Client) CreateNetwork

func (c *Client) CreateNetwork(locationID string, name string, l2security bool, labels []string) (*Network, error)

CreateNetwork creates a new network. locationID is required. name is required. labels are optional. returns information about the created network or an error.

func (*Client) CreateServer

func (c *Client) CreateServer(locationID string, name string, cores int, memoryGB int, labels []string) (*Server, error)

CreateServer creates a new server volume.

func (*Client) CreateStorage

func (c *Client) CreateStorage(locationID string, name string, capacity int, template *StorageTemplateParameters, labels []string) (*Storage, error)

CreateStorage creates a new storage volume.

func (*Client) DeleteIP

func (c *Client) DeleteIP(objectID string) error

DeleteIP deletes an IP address. This is only possible if the IP address has no relation to a server - remove the relation first!

func (*Client) DeleteNetwork

func (c *Client) DeleteNetwork(networkID string) error

DeleteNetwork deletes a network or answers with an error message.

func (*Client) DeleteSSHKey

func (c *Client) DeleteSSHKey(sshkeyID string) error

DeleteSSHKey deletes an SSH key or answers with an error message.

func (*Client) DeleteServer

func (c *Client) DeleteServer(serverID string) error

DeleteServer deletes a server or answers with an error message.

func (*Client) DeleteStorage

func (c *Client) DeleteStorage(storageID string) error

DeleteStorage deletes a storage or answers with an error message.

func (*Client) DisconnectIPAddress

func (c *Client) DisconnectIPAddress(ipAddressID, serverID string) error

DisconnectIPAddress disconnects an IP address from a server.

func (*Client) DisconnectIsoImage

func (c *Client) DisconnectIsoImage(isoImageID, serverID string) error

DisconnectIsoImage disconnects an ISO image from a virtual machine.

func (*Client) DisconnectNetwork

func (c *Client) DisconnectNetwork(networkID, serverID string) error

DisconnectNetwork disconnects a network from a server.

func (*Client) DisconnectStorage

func (c *Client) DisconnectStorage(storageID, serverID string) error

DisconnectStorage disconnects a storage volume from a server.

func (*Client) GetIP

func (c *Client) GetIP(objectID string) (*IP, error)

GetIP returns IP information.

func (*Client) GetIPs

func (c *Client) GetIPs() ([]IP, error)

GetIPs returns a list of IP addresses.

func (*Client) GetLocations

func (c *Client) GetLocations() ([]Location, error)

GetLocations returns a list of all gridscale locations.

func (*Client) GetNetwork

func (c *Client) GetNetwork(networkID string) (*Network, error)

GetNetwork returns information about a network identified by its ID.

func (*Client) GetNetworks

func (c *Client) GetNetworks() ([]Network, error)

GetNetworks returns a list of all networks.

func (*Client) GetPrices

func (c *Client) GetPrices() ([]Price, error)

GetPrices returns a list of object prices.

func (*Client) GetPublicNetwork

func (c *Client) GetPublicNetwork() (*Network, error)

GetPublicNetwork returns a reference to a public network.

func (*Client) GetSSHKey

func (c *Client) GetSSHKey(sshKeyID string) (*SSHKey, error)

GetSSHKey returns information about an ssh key identified by its ID.

func (*Client) GetSSHKeys

func (c *Client) GetSSHKeys() ([]SSHKey, error)

GetSSHKeys returns a list of all ssh keys.

func (*Client) GetServer

func (c *Client) GetServer(serverID string) (*Server, error)

GetServer returns information about a server identified by its ID.

func (*Client) GetServers

func (c *Client) GetServers() ([]Server, error)

GetServers returns a list of all servers.

func (*Client) GetStorage

func (c *Client) GetStorage(storageID string) (*Storage, error)

GetStorage returns information about a storage identified by its ID.

func (*Client) GetStorages

func (c *Client) GetStorages() ([]Storage, error)

GetStorages returns a list of all storages.

func (*Client) GetTemplateByName

func (c *Client) GetTemplateByName(name string) (*Template, error)

GetTemplateByName returns a template starting with `name`. Returns an error if not found or found more than one template.

func (*Client) GetTemplates

func (c *Client) GetTemplates() ([]Template, error)

GetTemplates returns a list templates.

func (*Client) PowerOffServer

func (c *Client) PowerOffServer(serverID string) error

PowerOffServer turns a server off.

func (*Client) PowerOnServer

func (c *Client) PowerOnServer(serverID string) error

PowerOnServer turns a server on.

func (*Client) UpdateIPFailover

func (c *Client) UpdateIPFailover(ipID string, failover bool) error

UpdateIPFailover enables or disables the IP's failover capability

func (*Client) UpdateIPLabels

func (c *Client) UpdateIPLabels(ipID string, labels []string) error

UpdateIPLabels sets the IP object's labels

func (*Client) UpdateIPReverseDNS

func (c *Client) UpdateIPReverseDNS(ipID string, reverseDNS string) error

UpdateIPReverseDNS updates an IP's reverse DNS entry.

func (*Client) UpdateNetworkLabels

func (c *Client) UpdateNetworkLabels(networkID string, labels []string) error

UpdateNetworkLabels changes the labels of a network identified by its id.

func (*Client) UpdateNetworkName

func (c *Client) UpdateNetworkName(networkID string, name string) error

UpdateNetworkName updates a networks name identified by the network id.

func (*Client) UpdateSSHKeyLabels

func (c *Client) UpdateSSHKeyLabels(sshkeyID string, labels []string) error

UpdateSSHKeyLabels changes the labels of an SSH key identified by its id.

func (*Client) UpdateSSHKeyName

func (c *Client) UpdateSSHKeyName(sshkeyID string, name string) error

UpdateSSHKeyName updates an SSH key name identified by the SSH key id.

func (*Client) UpdateSSHKeyPublicKey

func (c *Client) UpdateSSHKeyPublicKey(sshkeyID string, publicKey string) error

UpdateSSHKeyPublicKey updates an SSH public key.

func (*Client) UpdateServerCores

func (c *Client) UpdateServerCores(serverID string, cores int) error

UpdateServerCores changes the server's number of cores.

func (*Client) UpdateServerLabels

func (c *Client) UpdateServerLabels(serverID string, labels []string) error

UpdateServerLabels changes the labels of a server identified by its id.

func (*Client) UpdateServerMemory

func (c *Client) UpdateServerMemory(serverID string, memoryGB int) error

UpdateServerMemory changes the server's memory [GB].

func (*Client) UpdateServerName

func (c *Client) UpdateServerName(serverID string, name string) error

UpdateServerName updates a server's name identified by the network id.

func (*Client) UpdateStorageCapacity

func (c *Client) UpdateStorageCapacity(storageID string, capacity int) error

UpdateStorageCapacity changes the capacity of a storage identified by its id.

func (*Client) UpdateStorageLabels

func (c *Client) UpdateStorageLabels(storageID string, labels []string) error

UpdateStorageLabels changes the labels of a storage identified by its id.

func (*Client) UpdateStorageName

func (c *Client) UpdateStorageName(storageID string, name string) error

UpdateStorageName updates a storage's name identified by the network id.

type IP

type IP struct {
	ID         string
	Failover   bool
	Servers    []IPServerRelation
	LocationID string
	ReverseDNS string
	Labels     []string
	IP         net.IP
	Prefix     net.IPNet
	IPVersion  int
}

IP information from Gridscale

type IPServerRelation

type IPServerRelation struct {
	ServerName      string    `json:"server_name"`
	ServerID        string    `json:"server_uuid"`
	RelationCreated time.Time `json:"create_time"`
}

IPServerRelation holds server name and uuid and creation date of a serrver/object relation

type Location

type Location struct {
	ID      string `json:"object_uuid"`
	Name    string `json:"name"`
	Iata    string `json:"iata"`
	Country string `json:"country"`
}

Location holds information about a gridscale Location.

type Network

type Network struct {
	ID         string
	Name       string
	Status     string
	Labels     []string
	PublicNet  bool
	L2Security bool
	Relations  []NetworkServerRelation
	LocationID string
}

Network holds information about a network.

type NetworkServerRelation

type NetworkServerRelation struct {
	ServerName      string    `json:"object_name"`
	ServerID        string    `json:"object_uuid"`
	Ordering        int       `json:"ordering"`
	MAC             string    `json:"mac"`
	RelationCreated time.Time `json:"create_time"`
}

NetworkServerRelation is a relation that describes the connection between a network and a server including the server's MAC address.

type Price

type Price struct {
	Type         string          `json:"type"`
	PricePerUnit decimal.Decimal `json:"price_per_unit"`
	Name         string          `json:"name"`
	ProductNo    int             `json:"product_no"`
	Currency     string          `json:"currency"`
	Unit         string          `json:"unit"`
}

Price holds pricing information about a gridscale object type.

type SSHKey

type SSHKey struct {
	ID        string   `json:"object_uuid"`
	Name      string   `json:"name"`
	Labels    []string `json:"labels"`
	PublicKey string   `json:"sshkey"`
}

SSHKey holds information about an ssh key.

type Server

type Server struct {
	ID              string          `json:"object_uuid"`
	Name            string          `json:"name"`
	Status          string          `json:"status"`
	Labels          []string        `json:"labels"`
	Cores           int             `json:"cores"`
	Power           bool            `json:"power"`
	ConsoleToken    string          `json:"console_token"`
	CurrentPrice    decimal.Decimal `json:"current_price"`
	Relations       ServerRelations `json:"relations"`
	CreateTime      time.Time       `json:"create_time"`
	ChangeTime      time.Time       `json:"change_time"`
	LocationName    string          `json:"location_name"`
	LocationIata    string          `json:"location_iata"`
	LocationID      string          `json:"location_uuid"`
	LocationCountry string          `json:"location_country"`
}

Server holds information about a server.

type ServerNetworkRelation

type ServerNetworkRelation struct {
	NetworkID   string `json:"object_uuid"`
	NetworkName string `json:"object_name"`
	MAC         string `json:"mac"`
	Ordering    int    `json:"ordering"`
}

ServerNetworkRelation contains information about a network connected to a server.

type ServerRelations

type ServerRelations struct {
	Distance  []interface{}           `json:"distance"`  // TODO: what's that?
	IsoImages []interface{}           `json:"isoimages"` // TODO
	Networks  []ServerNetworkRelation `json:"networks"`
	PublicIPs []interface{}           `json:"public_ips"` // TODO
	Storages  []ServerStorageRelation `json:"storages"`
}

ServerRelations holds all relations to other gridscale objects (storages, networks etc.).

type ServerStorageRelation

type ServerStorageRelation struct {
	StorageID   string `json:"object_uuid"`
	StorageName string `json:"object_name"`
	BootDevice  bool   `json:"bootdevice"`
	Bus         int    `json:"bus"`
	Capacity    int    `json:"capacity"`
	Controller  int    `json:"controller"`
	LUN         int    `json:"lun"`
}

ServerStorageRelation contains information about a storage volume connected to a server

type Storage

type Storage struct {
	ID                 string
	ParentID           string
	LastUsedTemplateID *string
	Name               string
	Status             string
	Labels             []string
	Capacity           int
	Snapshots          []StorageSnapshot
	CurrentPrice       decimal.Decimal
	Relations          []StorageServerRelation
	CreateTime         time.Time
	ChangeTime         time.Time
	LocationID         string
}

Storage holds information about a storage.

type StorageServerRelation

type StorageServerRelation struct {
	ServerID        string    `json:"object_uuid"`
	ServerName      string    `json:"object_name"`
	RelationCreated time.Time `json:"create_time"`
	Lun             int       `json:"lun"`
	Bus             int       `json:"bus"`
	BootDevice      bool      `json:"bootdevice"`
	Controller      int       `json:"controller"`
	Target          int       `json:"target"`
}

StorageServerRelation holds information about a server connected to a storage.

type StorageSnapshot

type StorageSnapshot struct {
	ID                 string    `json:"object_uuid"`
	Name               string    `json:"object_name"`
	Capacity           string    `json:"object_capacity"`
	LastUsedTemplateID *string   `json:"last_used_template,omitempty"`
	CreateTime         time.Time `json:"create_time"`
}

StorageSnapshot holds information of a storage snapshot.

type StorageTemplateParameters

type StorageTemplateParameters struct {
	Hostname     string   `json:"hostname,omitempty"`
	Password     string   `json:"password,omitempty"`
	PasswordType string   `json:"password_type,omitempty"` // plain
	TemplateID   string   `json:"template_uuid"`
	SSHKeyIDs    []string `json:"sshkeys,omitempty"`
}

StorageTemplateParameters holds parameters to create a storage volume from a template

type Template

type Template struct {
	Capacity        int             `json:"capacity"`
	ChangeTime      time.Time       `json:"change_time"`
	CreateTime      time.Time       `json:"create_time"`
	CurrentPrice    decimal.Decimal `json:"current_price"`
	Description     string          `json:"description"`
	LocationCountry string          `json:"location_country"`
	LocationIATA    string          `json:"location_iata"`
	LocationName    string          `json:"location_name"`
	LocationID      string          `json:"location_uuid"`
	Name            string          `json:"name"`
	ID              string          `json:"object_uuid"`
	OSType          string          `json:"ostype"`
	Private         bool            `json:"private"`
	Status          string          `json:"status"`
	Version         string          `json:"version"`
}

Template holds information about a storage volume template

Jump to

Keyboard shortcuts

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