onapp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2015 License: MIT Imports: 12 Imported by: 2

README

OnApp API for Golang and CLI

Build Status

This is to be a library for accessing the OnApp API with a Go interface.

In addition, there is to be a command line client that will mimic the feature set of the OnApp dashboard. Install via go install github.com/alexzorin/onapp/onapp

API

Documentation for the API can be found at godoc.org

CLI

You can install the onapp CLI command into your $GOPATH/bin via:

go get github.com/alexzorin/onapp + go install github.com/alexzorin/onapp/onapp

or download a binary release from here, if available.

Get started with onapp config, find usage via onapp help and onapp help [command].

Commands
  • config - Configure the tool to connect to a particular OnApp Dashboard Server (saves by default in ~/.onapp)
  • test: Test the config
  • help: Help text for all commands and subcommands
  • vm: Management of virtual machines
    • list <query>: List virtual machines and their current status in a table
    • start <id>: Start a virtual machine
    • stop <id>: Stop a virtual machine
    • reboot <id>: Reboot a virtual machine
    • ssh <id>: Launches ssh at the VM's first IP address and provides you with the root password
    • vnc <id>: Etablishes a VNC session on the cloud server and launches vncviewer (needs to be in path, at this time only RealVNC Viewer is supported)
    • copy-id <id>: Copies the user's ~/.ssh/id_rsa.pub to the server's authorized_keys
    • stat <id>: SSH's into the machine (no password prompt) and runs vmstat 1 10, which it relays to stdout
    • tx <id> [num_to_list]: List of recent transactions on that VM
    • pass <id>: Copy password to the clipboard

Where <query> is mentioned, you can search via any exported field in onapp.VirtualMachine, i.e onapp vm list User=1 Booted=false. Try onapp help vm list for a list of fields.

Where <id> is mentioned, you may either provide exact #ID, exact Label or Hostname, or the CLI will attempt to guess which VM you mean via text similarity. Inexact matches will prompt confirmation.

Cache

Since the OnApp API can at times be slow (when listing all virtual machines, for example), the CLI will cache a copy of the list to ~/.onapp_cache. This copy is stripped of all root and VNC passwords.

If an item is found in the cache initially, the CLI will look the VM up at the API again (by ID, which is much faster) and retreive the passwords again.

You can also clear it using onapp vm clear-cache.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(hostname string, email string, apiKey string) (*Client, error)

Creates a new API client with the specified hostname, email address and API key. The hostname needs to be the DNS-resolvable hostname of the dashboard server (such as dashboard.example.org).

func (*Client) GetProfile

func (c *Client) GetProfile() (*Profile, error)

Fetches the user profile from the dashboard server

func (*Client) GetRemoteAccessSession

func (c *Client) GetRemoteAccessSession(id int) (RemoteAccessSession, error)

func (*Client) GetTransactions

func (c *Client) GetTransactions() (Transactions, error)

func (*Client) GetVirtualMachine

func (c *Client) GetVirtualMachine(id int) (VirtualMachine, error)

Fetches an individual Virtual Machine from the dashboard server

func (*Client) GetVirtualMachines

func (c *Client) GetVirtualMachines() (VirtualMachines, error)

Fetches a list of Virtual Machines from the dashboard server

func (*Client) VirtualMachineGetLatestTransaction

func (c *Client) VirtualMachineGetLatestTransaction(vmId int, statuses ...string) (Transaction, error)

func (*Client) VirtualMachineGetTransactions

func (c *Client) VirtualMachineGetTransactions(vmId int) (Transactions, error)

func (*Client) VirtualMachineReboot

func (c *Client) VirtualMachineReboot(id int) error

func (*Client) VirtualMachineShutdown

func (c *Client) VirtualMachineShutdown(id int) error

func (*Client) VirtualMachineStartup

func (c *Client) VirtualMachineStartup(id int) error

type IpAddress

type IpAddress struct {
	Address        string `json:"address"`
	Gateway        string `json:"gateway"`
	Broadcast      string `json:"broadcast"`
	NetworkAddress string `json:"network_address"`
	Netmask        string `json:"netmask"`
}

IP address of a virtual machine as represented by /virtual_machines/:id.json

type Profile

type Profile struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Login     string `json:"login"`
	Id        int    `json:"id"`
	Email     string `json:"email"`
}

The OnApp user profile as according to /profile.json

type RemoteAccessSession

type RemoteAccessSession struct {
	Port int `json:"port"`
}

Remote Access Session

type Transaction

type Transaction struct {
	Id         int    `json:"id"`
	Status     string `json:"status"`
	Parent     int    `json:"parent_id"`
	User       int    `json:"user_id"`
	ParentType string `json:"parent_type"`
	Action     string `json:"action"`
	CreatedAt  string `json:"created_at"`
	StartedAt  string `json:"started_at"`
	UpdatedAt  string `json:"updated_at"`
	Dependent  int    `json:"dependent_transaction_id"`
	// contains filtered or unexported fields
}

func (*Transaction) CreatedAtTime

func (tx *Transaction) CreatedAtTime() (time.Time, error)

func (*Transaction) IsValid

func (t *Transaction) IsValid() bool

func (*Transaction) StatusColored

func (t *Transaction) StatusColored() string

type Transactions

type Transactions []Transaction

type VirtualMachine

type VirtualMachine struct {
	Id             int                    `json:"id"`
	Label          string                 `json:"label"`
	Booted         bool                   `json:"booted"`
	Hostname       string                 `json:"hostname"`
	HV             int                    `json:"hypervisor_id"`
	Cpus           int                    `json:"cpus"`
	CpuShares      int                    `json:"cpu_shares"`
	Memory         int                    `json:"memory"`
	Template       string                 `json:"template_label"`
	User           int                    `json:"user_id"`
	Locked         bool                   `json:"locked"`
	RootPassword   string                 `json:"initial_root_password"`
	IpAddressesRaw []map[string]IpAddress `json:"ip_addresses"`
	VncPassword    string                 `json:"remote_access_password"`
	// contains filtered or unexported fields
}

The OnApp Virtual Machine as according to /virtual_machines.json

func (*VirtualMachine) BootedString

func (vm *VirtualMachine) BootedString() string

func (*VirtualMachine) BootedStringColored

func (vm *VirtualMachine) BootedStringColored() string

func (*VirtualMachine) GetIpAddress

func (vm *VirtualMachine) GetIpAddress() IpAddress

This prefers non-rfc5735 addresses if possible

func (*VirtualMachine) GetIpAddresses

func (vm *VirtualMachine) GetIpAddresses() ([]IpAddress, error)

func (*VirtualMachine) GetRemoteAccessSession

func (vm *VirtualMachine) GetRemoteAccessSession() (*RemoteAccessSession, error)

func (*VirtualMachine) GetRunningTransaction

func (vm *VirtualMachine) GetRunningTransaction() (Transaction, error)

func (*VirtualMachine) GetTransactions

func (vm *VirtualMachine) GetTransactions() (Transactions, error)

func (*VirtualMachine) Reboot

func (vm *VirtualMachine) Reboot() error

func (*VirtualMachine) Shutdown

func (vm *VirtualMachine) Shutdown() error

func (*VirtualMachine) Startup

func (vm *VirtualMachine) Startup() error

type VirtualMachines

type VirtualMachines []VirtualMachine

sort.Sort'ing over this type will sort by UserId

func (VirtualMachines) AsList

func (vms VirtualMachines) AsList() list.List

func (VirtualMachines) Len

func (vms VirtualMachines) Len() int

func (VirtualMachines) Less

func (vms VirtualMachines) Less(i, j int) bool

func (VirtualMachines) Swap

func (vms VirtualMachines) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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