libcarina

package module
v0.0.0-...-049d33f Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2017 License: Apache-2.0 Imports: 19 Imported by: 20

README

libcarina

GoDoc

Provisional Go bindings for the beta release of Carina by Rackspace. The carina client source code can be found at https://github.com/getcarina/carina.

Examples

Create

Create a new cluster

package main

import (
	"time"

	"github.com/getcarina/libcarina"
)

func createCluster(username string, apikey string, clusterName string) error {
	// Connect to Carina
	cli, _ := libcarina.NewClusterClient(libcarina.BetaEndpoint, username, apikey, "")

	// Create a new cluster
	cluster, err := cli.Create(libcarina.Cluster{
	    Name: clusterName,
	    ClusterTypeId: 1,
	})

	// Wait for the cluster to become active
	for cluster.Status == "creating" {
		time.Sleep(10 * time.Second)
		cluster, err = cli.Get(cluster.ID)
	}

	return err
}
Swarm

Connect to a Docker Swarm cluster

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/getcarina/libcarina"
	"github.com/samalba/dockerclient"
)

func connectCluster(username string, apikey string, clusterID string) {
	// Connect to Carina
	cli, _ := libcarina.NewClusterClient(libcarina.BetaEndpoint, username, apikey, "")

	// Download the cluster credentials
	creds, _ := cli.GetCredentials(clusterID)

	// Get the IP of the host and the TLS configuration
	host, _ := creds.ParseHost()
	cfg, _ := creds.GetTLSConfig()

	// Do the Dockers!
	docker, _ := dockerclient.NewDockerClient(host, cfg)
	info, _ := docker.Info()
	fmt.Println(info)
}
Kubernetes

Connect to a Kubernetes cluster

package main

import (
	"fmt"
	"github.com/getcarina/libcarina"

	client "k8s.io/kubernetes/pkg/client/unversioned"
	"k8s.io/kubernetes/pkg/client/restclient"
	"k8s.io/kubernetes/pkg/api"
)

func connectCluster(username string, apikey string, clusterID string) {
	// Connect to Carina
	cli, _ := libcarina.NewClusterClient(libcarina.BetaEndpoint, username, apikey, "")

	// Download the cluster credentials
	creds, _ := cli.GetCredentials(clusterID)

	// K8s stuff and things!
	k8cfg := &restclient.Config{
		Host:     creds.ParseHost(),
		CertData: creds.Cert,
		CAData:   creds.CA,
		KeyData:  creds.Key,
	}
	client, err := client.New(config)
	pods, err := client.Pods(api.NamespaceDefault).List(api.ListOptions{})
	
	return err
}

Documentation

Index

Constants

View Source
const CarinaEndpointType = "rax:container"

CarinaEndpointType is the endpoint type in the service catalog

View Source
const LibVersion = "2.0.0"

LibVersion is the version of this library, and should be keep synchronized with the git tag

View Source
const SupportedAPIVersion = "1.0"

SupportedAPIVersion is the version of the API against which this library was developed

View Source
const UserAgentPrefix = "libcarina/" + LibVersion

UserAgentPrefix is the default user agent string, consumers should append their application version to `CarinaClient.UserAgent`.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIMetadata

type APIMetadata struct {
	// Versions is a list of supported API versions
	Versions []*APIVersion
}

APIMetadata contains information about the API

type APIVersion

type APIVersion struct {
	ID      string `json:"id"`
	Status  string `json:"current"`
	Minimum string `json:"min_version"`
	Maximum string `json:"max_version"`
}

APIVersion defines a version of the API

type CarinaClient

type CarinaClient struct {
	Client    *http.Client
	Username  string
	Token     string
	Endpoint  string
	UserAgent string
}

CarinaClient accesses Carina directly

func NewClient

func NewClient(username string, apikey string, region string, authEndpointOverride string, cachedToken string, cachedEndpoint string) (*CarinaClient, error)

NewClient create an authenticated CarinaClient

func (*CarinaClient) Create

func (c *CarinaClient) Create(clusterOpts *CreateClusterOpts) (*Cluster, error)

Create a new cluster with cluster options

func (*CarinaClient) Delete

func (c *CarinaClient) Delete(token string) (*Cluster, error)

Delete nukes a cluster out of existence

func (*CarinaClient) Get

func (c *CarinaClient) Get(token string) (*Cluster, error)

Get a cluster by cluster by its name or id

func (*CarinaClient) GetCredentials

func (c *CarinaClient) GetCredentials(token string) (*CredentialsBundle, error)

GetCredentials returns a Credentials struct for the given cluster name

func (*CarinaClient) List

func (c *CarinaClient) List() ([]*Cluster, error)

List the current clusters

func (*CarinaClient) ListClusterTypes

func (c *CarinaClient) ListClusterTypes() ([]*ClusterType, error)

ListClusterTypes returns a list of cluster types

func (*CarinaClient) NewRequest

func (c *CarinaClient) NewRequest(method string, uri string, body io.Reader) (*http.Response, error)

NewRequest handles a request using auth used by Carina

func (*CarinaClient) Resize

func (c *CarinaClient) Resize(token string, nodes int) (*Cluster, error)

Resize a cluster with resize task options

type CarinaError

type CarinaError struct {
	Code      string `json:"code"`
	Detail    string `json:"detail"`
	RequestID string `json:"request_id"`
	Status    int    `json:"status"`
	Title     string `json:"title"`
}

CarinaError represents an error message from the Carina API

type CarinaGenericErrorResponse

type CarinaGenericErrorResponse struct {
	Errors []CarinaError `json:"errors"`
}

CarinaGenericErrorResponse represents the response returned by Carina when a request fails

type CarinaUnacceptableError

type CarinaUnacceptableError struct {
	CarinaError
	MaxVersion string `json:"max_version"`
	MinVersion string `json:"min_version"`
}

CarinaUnacceptableError represents a 406 response from the Carina API

type CarinaUnacceptableErrorResonse

type CarinaUnacceptableErrorResonse struct {
	Errors []CarinaUnacceptableError `json:"errors"`
}

CarinaUnacceptableErrorResonse represents the response returned by Carina when the StatusCode is 406

type Cluster

type Cluster struct {
	// ID of the cluster
	ID string `json:"id"`

	// Name of the cluster
	Name string `json:"name"`

	// Type of cluster
	Type *ClusterType `json:"cluster_type"`

	// Nodes in the cluster
	Nodes int `json:"node_count,omitempty"`

	// Status of the cluster
	Status string `json:"status,omitempty"`
}

Cluster is a cluster of Docker nodes

type ClusterType

type ClusterType struct {
	// ID of the cluster type
	ID int `json:"id"`

	// Name of the cluster type
	Name string `json:"name"`

	// Specifies if the cluster type is available to be used for new clusters
	IsActive bool `json:"active"`

	// COE (container orchestration engine) used by the cluster
	COE string `json:"coe"`

	// Underlying type of the host nodes, such as lxc or vm
	HostType string `json:"host_type"`
}

ClusterType defines a type of cluster Essentially the template used to create a new cluster

type CreateClusterOpts

type CreateClusterOpts struct {
	// Name of the cluster
	Name string `json:"name"`

	// Type of cluster
	ClusterTypeID int `json:"cluster_type_id"`

	// Nodes in the cluster
	Nodes int `json:"node_count,omitempty"`
}

CreateClusterOpts defines the set of parameters when creating a cluster

type CredentialsBundle

type CredentialsBundle struct {
	Files map[string][]byte
	Err   error
}

CredentialsBundle is a set of certificates and environment information necessary to connect to a cluster

func LoadCredentialsBundle

func LoadCredentialsBundle(credentialsPath string) *CredentialsBundle

LoadCredentialsBundle loads a credentials bundle from the filesystem

func NewCredentialsBundle

func NewCredentialsBundle() *CredentialsBundle

NewCredentialsBundle initializes an empty credentials bundle

func (*CredentialsBundle) GetCA

func (creds *CredentialsBundle) GetCA() []byte

GetCA returns the contents of ca.pem

func (*CredentialsBundle) GetCert

func (creds *CredentialsBundle) GetCert() []byte

GetCert returns the contents of cert.pem

func (*CredentialsBundle) GetKey

func (creds *CredentialsBundle) GetKey() []byte

GetKey returns the contents of key.pem

func (*CredentialsBundle) GetTLSConfig

func (creds *CredentialsBundle) GetTLSConfig() (*tls.Config, error)

GetTLSConfig puts together the necessary TLS configuration to connect to the COE Endpoint returned by ParseHost

func (*CredentialsBundle) ParseHost

func (creds *CredentialsBundle) ParseHost() (string, error)

ParseHost finds the COE Endpoint, e.g. the swarm or kubernetes ip and port

func (*CredentialsBundle) Verify

func (creds *CredentialsBundle) Verify() error

Verify validates that we can connect to the Docker host specified in the credentials bundle

type HTTPErr

type HTTPErr struct {
	Method     string
	URL        string
	StatusCode int
	Status     string
	Body       string
}

HTTPErr is returned when API requests are not successful

func (HTTPErr) Error

func (err HTTPErr) Error() string

Error routes to either genericError or other, more-specific, response formatters to give provide a user-friendly error

Jump to

Keyboard shortcuts

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