cepgo

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2016 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

README

cepgo

Cepko implements easy-to-use communication with CloudSigma's VMs through a virtual serial port without bothering with formatting the messages properly nor parsing the output with the specific and sometimes confusing shell tools for that purpose.

Having the server definition accessible by the VM can be useful in various ways. For example it is possible to easily determine from within the VM, which network interfaces are connected to public and which to private network. Another use is to pass some data to initial VM setup scripts, like setting the hostname to the VM name or passing ssh public keys through server meta.

Example usage:

package main

import (
        "fmt"

        "github.com/cloudsigma/cepgo"
)

func main() {
        c := cepgo.NewCepgo()
        result, err := c.Meta()
        if err != nil {
                panic(err)
        }
        fmt.Printf("%#v", result)
}

Output:

map[string]interface {}{
    "optimize_for":"custom",
    "ssh_public_key":"ssh-rsa AAA...",
    "description":"[...]",
}

For more information take a look at the Server Context section of CloudSigma API Docs: http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html

Documentation

Overview

Cepko implements easy-to-use communication with CloudSigma's VMs through a virtual serial port without bothering with formatting the messages properly nor parsing the output with the specific and sometimes confusing shell tools for that purpose.

Having the server definition accessible by the VM can be useful in various ways. For example it is possible to easily determine from within the VM, which network interfaces are connected to public and which to private network. Another use is to pass some data to initial VM setup scripts, like setting the hostname to the VM name or passing ssh public keys through server meta.

Example usage:

package main

import (
        "fmt"

        "github.com/cloudsigma/cepgo"
)

func main() {
        c := cepgo.NewCepgo()
        result, err := c.Meta()
        if err != nil {
                panic(err)
        }
        fmt.Printf("%#v", result)
}

Output:

map[string]string{
	"optimize_for":"custom",
	"ssh_public_key":"ssh-rsa AAA...",
	"description":"[...]",
}

For more information take a look at the Server Context section API Docs: http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html

Index

Constants

View Source
const (
	EOT = '\x04' // End Of Transmission
)

Variables

View Source
var (
	SerialPort string = "/dev/ttyS1"
	Baud       int    = 115200
)

Functions

This section is empty.

Types

type Cepgo

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

Queries to the serial port can be executed only from instance of this type. The result from each of them can be either interface{}, map[string]string or a single in case of single value is returned. There is also a public metod who directly calls the fetcher and returns raw []byte from the serial port.

func NewCepgo

func NewCepgo() *Cepgo

Creates a Cepgo instance with the default serial port fetcher.

func NewCepgoFetcher

func NewCepgoFetcher(fetcher func(string) ([]byte, error)) *Cepgo

Creates a Cepgo instance with custom fetcher.

func (*Cepgo) All

func (c *Cepgo) All() (interface{}, error)

Fetches all the server context. Equivalent of c.Key("")

func (*Cepgo) FetchRaw

func (c *Cepgo) FetchRaw(key string) ([]byte, error)

Fetches raw []byte from the serial port using directly the fetcher member.

func (*Cepgo) GlobalContext

func (c *Cepgo) GlobalContext() (map[string]string, error)

Fetches only the global context and makes sure to return a proper map[string]string

func (*Cepgo) Key

func (c *Cepgo) Key(key string) (interface{}, error)

Fetches a single key and tries to unmarshal the result to json and returns it. If the unmarshalling fails it's safe to assume the result it's just a string and returns it.

func (*Cepgo) Meta

func (c *Cepgo) Meta() (map[string]string, error)

Fetches only the object meta field and makes sure to return a proper map[string]string

Jump to

Keyboard shortcuts

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