brain

package
v2.5.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: MIT Imports: 13 Imported by: 48

Documentation

Index

Constants

View Source
const (
	// ClusterAdminPrivilege allows a user to administer the cluster managed by the brain, and do things like create/delete VMs on accounts they have no explicit right on, grant others AccountAdminPrivilege, and set disc iops_limit
	ClusterAdminPrivilege PrivilegeLevel = "cluster_admin"
	// AccountAdminPrivilege allows a user to create, modify & delete groups and servers in an account.
	AccountAdminPrivilege = "account_admin"
	// GroupAdminPrivilege allows a user to create, modify & delete servers in a specific group.
	GroupAdminPrivilege = "group_admin"
	// VMAdminPrivilege allows a user to modify & administer a server, including increasing the performance (and hence the price on the uk0 cluster) and accessing the console.
	VMAdminPrivilege = "vm_admin"
	// VMConsolePrivilege allows a user to access the console for a particular server.
	VMConsolePrivilege = "vm_console"
)
View Source
const (
	// PrivilegeTargetTypeVM is the prefix for all privilege levels that affect VMs
	PrivilegeTargetTypeVM = "vm"
	// PrivilegeTargetTypeGroup is the prefix for all privilege levels that affect Groups
	PrivilegeTargetTypeGroup = "group"
	// PrivilegeTargetTypeAccount is the prefix for all privilege levels that affect Accounts
	PrivilegeTargetTypeAccount = "account"
	// PrivilegeTargetTypeCluster is the prefix for all privilege levels that affect the whole cluster.
	PrivilegeTargetTypeCluster = "cluster"
)

Variables

View Source
var ColdStorageGrade = "iceberg"

ColdStorageGrade is the name for the storage grade used as 'cold storage' - i.e. where backups get sent after being taken.

Functions

This section is empty.

Types

type Account

type Account struct {
	Name string `json:"name"`

	// the following cannot be set
	ID        int      `json:"id"`
	Suspended bool     `json:"suspended"`
	Groups    []*Group `json:"groups"`
}

Account represents an account object that's returned by the brain

type Backup

type Backup struct {
	Disc
	ParentDiscID int  `json:"parent_disc_id"`
	Manual       bool `json:"manual"`
}

Backup represents a single backup of a disc. Backups are taken on the same tail as the disc, and then migrated to a different storage grade immediately.

func (Backup) OnColdStorage

func (s Backup) OnColdStorage() bool

OnColdStorage returns true if the disc is currently on cold storage (whatever storage grade that is)

func (Backup) PrettyPrint

func (s Backup) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs a nicely-formatted string detailing the backup to the given writer.

type BackupSchedule

type BackupSchedule struct {
	ID        int    `json:"id,omitempty"`
	StartDate string `json:"start_at"`
	Interval  int    `json:"interval_seconds"`
	// Capacity is how many backups will be kept
	Capacity int `json:"capacity"`
}

BackupSchedule represents a schedule to take backups on. It is represented as a start date in YYYY-MM-DD hh:mm:ss format (and assuming UK timezones of some kind.)

func (BackupSchedule) IntervalInWords

func (sched BackupSchedule) IntervalInWords() string

IntervalInWords returns a nice human readable version of the interval for this BackupSchedule Formats include "every %d weeks/days/hours/seconds", "weekly", "daily", and "hourly"

func (BackupSchedule) PrettyPrint

func (sched BackupSchedule) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs a nicely-formatted human-readable version of the schedule to the given writer. All the detail levels are the same.

func (BackupSchedule) String

func (sched BackupSchedule) String() string

type BackupSchedules

type BackupSchedules []*BackupSchedule

BackupSchedules represents multiple backup schedules

func (BackupSchedules) MapTemplateFragment

func (scheds BackupSchedules) MapTemplateFragment(templateFrag string) (strs []string, err error)

MapTemplateFragment takes a template fragment (as if it was starting within a {{ }}) and executes it against every schedule in scheds, returning all the results as a slice of strings, or an error if one occurred. it is called by the 'map' template function, as used in BackupSchedules.PrettyPrint Is this the most heinous thing ever?

func (BackupSchedules) PrettyPrint

func (scheds BackupSchedules) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs a nicely-formatted human-readable version of the schedules to the given writer. detail levels: SingleLine - outputs one line "Backups are taken every m, n, o, & p seconds" or "No backups scheduled" Medium - same Full - outputs one line per schedule, "• #ID - " followed by the SingleLine PrettyPrint of the schedule

type Backups

type Backups []*Backup

Backups represents a collection of backups

func (Backups) PrettyPrint

func (ss Backups) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) (err error)

PrettyPrint outputs a nicely-formatted string detailing the backup to the given writer.

type Disc

type Disc struct {
	Label        string `json:"label,omitempty"`
	StorageGrade string `json:"storage_grade,omitempty"`
	Size         int    `json:"size,omitempty"`

	ID               int    `json:"id,omitempty"`
	VirtualMachineID int    `json:"virtual_machine_id,omitempty"`
	StoragePool      string `json:"storage_pool,omitempty"`

	BackupCount     int             `json:"backup_count,omitempty"`
	BackupSchedules BackupSchedules `json:"backup_schedules,omitempty"`
	BackupsEnabled  bool            `json:"backups_enabled,omitempty"`

	ResourceName      string `json:"resource_name,omitempty"`
	MigrationProgress int    `json:"migration_progress,omitempty"`
	MigrationEta      int    `json:"migration_eta,omitempty"`
	MigrationSpeed    int    `json:"migration_speed,omitempty"`

	NewStorageGrade string `json:"new_storage_grade,omitempty"`
	NewStoragePool  string `json:"new_storage_pool,omitempty"`
}

Disc is a representation of a VM's disc.

func (Disc) EstimateBackupScheduleSize

func (d Disc) EstimateBackupScheduleSize() int

EstimateBackupScheduleSize returns an estimate for the maximum amount of iceberg storage this disk will use for its backups, in MiB

func (Disc) PrettyPrint

func (d Disc) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs the disc nicely-formatted to the writer.

func (Disc) String

func (d Disc) String() string

String returns the disc formatted as a string (the same as PrettyPrint with prettyprint.SingleLine detail)

func (Disc) Validate

func (d Disc) Validate() (*Disc, error)

Validate makes sure the disc has a storage grade.

type DistributionDefinition

type DistributionDefinition struct {
	Name        string
	Description string
}

DistributionDefinition is an object we assemble from distributions and distribution_descriptions from the /definitions API call in the future (bytemark-client 3.0?) a slice of these this will replace the Definitions.Distributions slice and Definitions.DistributionDescriptions map.

type Group

type Group struct {
	Name string `json:"name"`

	// the following cannot be set
	AccountID       int               `json:"account_id"`
	ID              int               `json:"id"`
	VirtualMachines []*VirtualMachine `json:"virtual_machines"`
}

Group represents a group

func (Group) String

func (g Group) String() string

type HardwareProfileDefinition

type HardwareProfileDefinition struct {
	Name        string
	Description string
}

HardwareProfileDefinition is an object we assemble from hardwareprofiles in the /definitions API call and some static data in lib/definitions.go in the future (bytemark-client 3.0?) a slice of these this will replace the Definitions.HardwareProfiles slice.

type Head struct {
	ID       int    `json:"id,omitempty"`
	UUID     string `json:"uuid,omitempty"`
	Label    string `json:"label,omitempty"`
	ZoneName string `json:"zone,omit_empty"`

	Architecture  string   `json:"arch,omitempty"`
	CCAddress     *net.IP  `json:"cnc_address,omitempty"`
	LastNote      string   `json:"last_note, omitempty"`
	TotalMemory   int      `json:"total_memory,omitempty"`
	UsageStrategy string   `json:"usage_strategy,omitempty"`
	Models        []string `json:"models,omitempty"`

	FreeMemory int  `json:"free_memory,omitempty"`
	IsOnline   bool `json:"online,omitempty"`
	UsedCores  int  `json:"used_cores,omitempty"`

	VirtualMachineCount int      `json:"virtual_machines_count,omitempty"`
	VirtualMachines     []string `json:"virtual_machines,omitempty"`
}

Head represents a Bytemark Cloud Servers head server.

func (Head) CountVirtualMachines

func (h Head) CountVirtualMachines() int

CountVirtualMachines returns the number of virtual machines running on this head

func (Head) PrettyPrint

func (h Head) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint writes an overview of this head out to the given writer.

type IP

type IP struct {
	RDns string `json:"rdns"`

	// this cannot be set.
	IP *net.IP `json:"ip"`
}

IP represents an IP for the purpose of setting RDNS

type IPCreateRequest

type IPCreateRequest struct {
	Addresses  int    `json:"addresses"`
	Family     string `json:"family"`
	Reason     string `json:"reason"`
	Contiguous bool   `json:"contiguous"`
	// don't actually specify the IPs - this is for filling in from the response!
	IPs []*net.IP `json:"ips"`
}

IPCreateRequest is used by the create_ip endpoint on a nic

type IPRange

type IPRange struct {
	ID        int      `json:"id"`
	Spec      string   `json:"spec"`
	VLANNum   int      `json:"vlan_num"`
	Zones     []string `json:"zones"`
	Available *big.Int `json:"available"`
}

IPRange is a representation of an IP range

func (IPRange) PrettyPrint

func (ipr IPRange) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint writes an overview of this IP range out to the given writer.

func (IPRange) String

func (ipr IPRange) String() string

String serialises an IP range to easily be output

type IPSpec

type IPSpec struct {
	IPv4 string `json:"ipv4"`
	IPv6 string `json:"ipv6"`
}

IPSpec represents one v4 and one v6 address to assign to a server during creation.

type IPs

type IPs []*net.IP

IPs represent multiple net.IPs

func (IPs) Len

func (ips IPs) Len() int

Len returns how many ips there are in this IPs

func (IPs) Less

func (ips IPs) Less(i, j int) bool

Less looks at the ips at index i and j, and returns true if i should come before j.

func (IPs) Sort

func (ips IPs) Sort() IPs

Sort sorts the given IPs in-place and also returns it, for daisy chaining. Sorting is done by the golang sort package, which uses the Less, Len and Swap functions defined below

func (IPs) String

func (ips IPs) String() string

func (IPs) StringSep

func (ips IPs) StringSep(sep string) string

StringSep combines all the IPs into a single string with the given seperator

func (IPs) Strings

func (ips IPs) Strings() (strings []string)

Strings returns each IP in this IPs as a string.

func (IPs) Swap

func (ips IPs) Swap(i, j int)

Swap moves the ip at i to j, and vice versa.

type ImageInstall

type ImageInstall struct {
	Distribution    string `json:"distribution"`
	FirstbootScript string `json:"firstboot_script"`
	RootPassword    string `json:"root_password"`
	PublicKeys      string `json:"ssh_public_key"`
}

ImageInstall represents what image was most recently installed on a VM along with its root password. This might only be returned when creating a VM.

func (ImageInstall) PrettyPrint

func (pp ImageInstall) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs the image install with the given level of detail. TODO(telyn): rewrite to use templates & prettyprint.Run

type JSONUser

type JSONUser struct {
	Username       string `json:"username"`
	Email          string `json:"email"`
	AuthorizedKeys string `json:"authorized_keys"`
}

JSONUser is used as an intermediate type that gets processed into a User. It should not have been exported.

func (*JSONUser) Process

func (jsonUser *JSONUser) Process(into *User)

Process turns this JSONUser into a User.

type NetworkInterface

type NetworkInterface struct {
	Label string `json:"label"`

	Mac string `json:"mac"`

	ID      int `json:"id"`
	VlanNum int `json:"vlan_num"`
	IPs     IPs `json:"ips"`
	// sadly we can't use map[net.IP]*net.IP because net.IP is a slice and slices don't have equality
	// and we can't use map[*net.IP]*net.IP because we could have two identical IPs in different memory locations and they wouldn't be equal. Rubbish.
	ExtraIPs         map[string]*net.IP `json:"extra_ips"`
	VirtualMachineID int                `json:"virtual_machine_id"`
}

NetworkInterface represents a virtual NIC and what IPs it has routed.

func (NetworkInterface) String

func (nic NetworkInterface) String() string

type Privilege

type Privilege struct {
	// ID is the numeric ID used mostly by the brain
	ID int `json:"id,omitempty"`
	// Username is the user who the privilege is granted to
	Username string `json:"username,omitempty"`
	// VirtualMachineID is the ID of the virtual machine the privilege is granted on
	VirtualMachineID int `json:"virtual_machine_id,omitempty"`
	// AccountID is the ID of the account the privilege is granted on
	AccountID int `json:"account_id,omitempty"`
	// GroupID is the ID of the group the privilege is granted on
	GroupID int `json:"group_id,omitempty"`
	// Level is the PrivilegeLevel they have
	Level PrivilegeLevel `json:"level,omitempty"`
	// YubikeyRequired is true if the user should have to authenticate with a yubikey in order to use this privilege. Only set it to true if you're sure the user has a yubikey set up on their account, and that they know where it is!
	YubikeyRequired bool `json:"yubikey_required"`
	// YubikeyOTPMaxAge should set how long (in seconds) a yubikey one-time-password would be accepted for, but it might not be used?
	YubikeyOTPMaxAge int `json:"yubikey_otp_max_age,omitempty"`
}

Privilege represents a privilege on the brain. A user may have multiple privileges, and multiple privileges may be granted on the same object. At the moment we're not worried about the extra fields that privileges have on the brain (IP restrictions) because they're unused

func (Privilege) PrettyPrint

func (p Privilege) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) (err error)

PrettyPrint nicely formats the Privilege and sends it to the given writer. At the moment, the detail parameter is ignored.

func (Privilege) String

func (p Privilege) String() string

String returns a string representation of the Privilege in English. Privileges are a little tricky to represent in English because the Privilege itself doesn't know if it exists on a user or if it has just been removed from a user, nor does it now anything about the target it's been granted on/revoked from other than a numerical ID. So we do the best we can.

func (Privilege) Target

func (p Privilege) Target() string

Target returns a formatted string containing the target type and its ID.

func (Privilege) TargetType

func (p Privilege) TargetType() string

TargetType returns the prefix of the PrivilegeLevel, which should be one of the PrivilegeTargetType* constants.

type PrivilegeLevel

type PrivilegeLevel string

PrivilegeLevel is a type to represent different privilege levels. since privilege levels in the brain are just strings, they're just a string type here too.

func (PrivilegeLevel) String

func (pl PrivilegeLevel) String() string

String returns the privilege level cast to a string.

type Privileges

type Privileges []*Privilege

Privileges is used to allow API consumers to use IndexOf on the array of privileges.

func (Privileges) IndexOf

func (ps Privileges) IndexOf(priv Privilege) int

IndexOf finds the privilege given in the list of privileges, ignoring the Privilege ID and returns the index. If it couldn't find it, returns -1.

type StorageGradeDefinition

type StorageGradeDefinition struct {
	Name        string
	Description string
}

StorageGradeDefinition is an object we assemble from storage_grades and storage_grade_descriptions in the /definitions API call in the future (bytemark-client 3.0?) a slice of these this will replace the Definitions.StorageGrades slice and Definitions.StorageGradeDescriptions map.

type StoragePool

type StoragePool struct {
	Name            string   `json:"name"`
	Label           string   `json:"label"`
	Zone            string   `json:"zone"`
	Size            int      `json:"size"`
	FreeSpace       int      `json:"free_space"`
	AllocatedSpace  int      `json:"alloc"`
	Discs           []string `json:"discs"`
	OvercommitRatio int      `json:"overcommit_ratio"`
	UsageStrategy   string   `json:"usage_strategy"`
	StorageGrade    string   `json:"grade"`
	Note            string   `json:"note"`
}

StoragePool represents a Bytemark Cloud Servers disk storage pool, as returned by the admin API.

func (StoragePool) PercentFull

func (sp StoragePool) PercentFull() int

PercentFull gives us the (numeric) percentage of how full the disc is

func (StoragePool) PrettyPrint

func (sp StoragePool) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint writes an overview of this storage pool out to the given writer.

type Tail

type Tail struct {
	ID    int    `json:"id"`
	UUID  string `json:"uuid"`
	Label string `json:"label"`

	CCAddress *net.IP `json:"cnc_address"`
	ZoneName  string  `json:"zone"`

	IsOnline     bool     `json:"online"`
	StoragePools []string `json:"pools"`
}

Tail represents a Bytemark Cloud Servers tail (disk storage machine), as returned by the admin API.

func (Tail) PrettyPrint

func (t Tail) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint writes an overview of this tail out to the given writer.

type User

type User struct {
	Username       string
	Email          string
	AuthorizedKeys []string
}

User represents a Bytemark user.

func (*User) MarshalJSON

func (user *User) MarshalJSON() ([]byte, error)

MarshalJSON marshals the User into a JSON bytestream.

type VLAN

type VLAN struct {
	ID        int        `json:"id"`
	Num       int        `json:"num"`
	UsageType string     `json:"usage_type"`
	IPRanges  []*IPRange `json:"ip_ranges"`
}

VLAN is a representation of a VLAN, as used by admin endpoints

func (VLAN) PrettyPrint

func (v VLAN) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint writes an overview of this VLAN out to the given writer.

type VirtualMachine

type VirtualMachine struct {
	Autoreboot            bool   `json:"autoreboot_on,omitempty"`
	CdromURL              string `json:"cdrom_url,omitempty"`
	Cores                 int    `json:"cores,omitempty"`
	Memory                int    `json:"memory,omitempty"`
	Name                  string `json:"name,omitempty"`
	PowerOn               bool   `json:"power_on,omitempty"`
	HardwareProfile       string `json:"hardware_profile,omitempty"`
	HardwareProfileLocked bool   `json:"hardware_profile_locked,omitempty"`
	GroupID               int    `json:"group_id,omitempty"`

	// zone name can be set during creation but not changed
	ZoneName string `json:"zone_name,omitempty"`

	// the following cannot be set
	Discs             []*Disc             `json:"discs,omitempty"`
	ID                int                 `json:"id,omitempty"`
	ManagementAddress *net.IP             `json:"management_address,omitempty"`
	Deleted           bool                `json:"deleted,omitempty"`
	Hostname          string              `json:"hostname,omitempty"`
	Head              string              `json:"head,omitempty"`
	NetworkInterfaces []*NetworkInterface `json:"network_interfaces,omitempty"`
}

VirtualMachine represents a VirtualMachine, as passed around from the virtual_machines endpoint

func (VirtualMachine) AllIPv4Addresses

func (vm VirtualMachine) AllIPv4Addresses() (ips IPs)

AllIPv4Addresses flattens all the IPs for a VM into a single IPs (a []*net.IP with some convenience methods)

func (VirtualMachine) AllIPv6Addresses

func (vm VirtualMachine) AllIPv6Addresses() (ips IPs)

AllIPv6Addresses flattens all the v6 IPs for a VM into a single IPs (a []*net.IP with some convenience methods)

func (VirtualMachine) FullName

func (vm VirtualMachine) FullName() string

FullName returns the first three parts of the hostname (i.e. name.group.account)

func (VirtualMachine) GetDiscLabelOffset

func (vm VirtualMachine) GetDiscLabelOffset() (offset int)

GetDiscLabelOffset gets the highest disc number for this VM, by looking for discs labelled disc-N and using N or the number of discs attached to the VM, whichever is higher

func (VirtualMachine) PrettyPrint

func (vm VirtualMachine) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs a nice human-readable overview of the server to the given writer.

func (VirtualMachine) PrimaryIP

func (vm VirtualMachine) PrimaryIP() net.IP

PrimaryIP returns the VM's primary IP - the (usually) IPv4 address that was created first.

func (VirtualMachine) ShortName

func (vm VirtualMachine) ShortName() string

ShortName returns the first two parts of the hostname (i.e. name.group)

func (VirtualMachine) String

func (vm VirtualMachine) String() string

func (VirtualMachine) TotalDiscSize

func (vm VirtualMachine) TotalDiscSize(storageGrade string) (total int)

TotalDiscSize returns the sum of all disc capacities in the VM for the given storage grade. Provide the empty string to sum all discs regardless of storage grade.

type VirtualMachineSpec

type VirtualMachineSpec struct {
	VirtualMachine *VirtualMachine `json:"virtual_machine"`
	Discs          []Disc          `json:"discs,omitempty"`
	Reimage        *ImageInstall   `json:"reimage,omitempty"`
	IPs            *IPSpec         `json:"ips,omitempty"`
}

VirtualMachineSpec represents the specification for a VM that is passed to the create_vm endpoint

func (VirtualMachineSpec) PrettyPrint

func (spec VirtualMachineSpec) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error

PrettyPrint outputs a human-readable spec to the given writer. TODO(telyn): rewrite using templates

func (VirtualMachineSpec) String

func (spec VirtualMachineSpec) String() string

type ZoneDefinition

type ZoneDefinition struct {
	Name        string
	Description string
}

ZoneDefinition is an object we assemble from zone_names in the /definitions API call and some static data in lib/definitions.go in the future (bytemark-client 3.0?) a slice of these this will replace the Definitions.ZoneNames slice.

Jump to

Keyboard shortcuts

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