Go bindings for Carina™
Go Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Makefile
README.md
cluster.go
credentials.go
glide.lock
glide.yaml
libcarina.go
libcarina_test.go
metadata.go
task.go

README.md

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
}