client

package
v0.0.0-...-adefa03 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Maximum message size allowed from peer.
	MaxMessageSize = 4096
	PongWait       = 60 * time.Second
)

Variables

This section is empty.

Functions

func FindHostForTests

func FindHostForTests(hostId string, host *Host)

func FindNetworkForTests

func FindNetworkForTests(poolId string, network *Network)

func FindOrCreateVmForTests

func FindOrCreateVmForTests(vm *Vm, poolId, srId, templateName, tag string)

func FindPoolForTests

func FindPoolForTests(pool *Pool)

func FindStorageRepositoryForTests

func FindStorageRepositoryForTests(pool Pool, sr *StorageRepository, tag string)

func FindTemplateForTests

func FindTemplateForTests(template *Template, poolId, templateEnvVar string)

func GetVmPowerState

func GetVmPowerState(c *Client, id string) func() (result interface{}, state string, err error)

func RemoveCloudConfigsWithPrefix

func RemoveCloudConfigsWithPrefix(cloudConfigPrefix string) func(string) error

func RemoveNetworksWithNamePrefix

func RemoveNetworksWithNamePrefix(prefix string) func(string) error

func RemoveResourceSetsWithNamePrefix

func RemoveResourceSetsWithNamePrefix(rsNamePrefix string) func(string) error

func RemoveTagFromAllObjects

func RemoveTagFromAllObjects(tag string) func(string) error

func RemoveUsersWithPrefix

func RemoveUsersWithPrefix(usernamePrefix string) func(string) error

Types

type Acl

type Acl struct {
	Id      string
	Action  string
	Subject string
	Object  string
}

func (Acl) Compare

func (acl Acl) Compare(obj interface{}) bool

type Boot

type Boot struct {
	Firmware string `json:"firmware,omitempty"`
}

type CPUs

type CPUs struct {
	Number int `json:"number"`
	Max    int `json:"max"`
}

type Client

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

func (Client) AddResourceSetLimit

func (c Client) AddResourceSetLimit(rsReq ResourceSet, limit string, quantity int) error

func (Client) AddResourceSetObject

func (c Client) AddResourceSetObject(rsReq ResourceSet, object string) error

func (Client) AddResourceSetSubject

func (c Client) AddResourceSetSubject(rsReq ResourceSet, subject string) error

func (*Client) AddTag

func (c *Client) AddTag(id, tag string) error

func (*Client) Call

func (c *Client) Call(method string, params, result interface{}, opt ...jsonrpc2.CallOption) error

func (*Client) ConnectDisk

func (c *Client) ConnectDisk(d Disk) error

func (*Client) ConnectVIF

func (c *Client) ConnectVIF(vifReq *VIF) (err error)

func (*Client) CreateAcl

func (c *Client) CreateAcl(acl Acl) (*Acl, error)

func (*Client) CreateCloudConfig

func (c *Client) CreateCloudConfig(name, template string) (*CloudConfig, error)

func (*Client) CreateDisk

func (c *Client) CreateDisk(vm Vm, d Disk) (string, error)

func (*Client) CreateNetwork

func (c *Client) CreateNetwork(netReq Network) (*Network, error)

func (Client) CreateResourceSet

func (c Client) CreateResourceSet(rsReq ResourceSet) (*ResourceSet, error)

func (*Client) CreateUser

func (c *Client) CreateUser(user User) (*User, error)

func (*Client) CreateVIF

func (c *Client) CreateVIF(vm *Vm, vif *VIF) (*VIF, error)

func (*Client) CreateVm

func (c *Client) CreateVm(vmReq Vm, createTime time.Duration) (*Vm, error)

func (*Client) DeleteAcl

func (c *Client) DeleteAcl(acl Acl) error

func (*Client) DeleteCloudConfig

func (c *Client) DeleteCloudConfig(id string) error

func (*Client) DeleteDisk

func (c *Client) DeleteDisk(vm Vm, d Disk) error

func (*Client) DeleteNetwork

func (c *Client) DeleteNetwork(id string) error

func (Client) DeleteResourceSet

func (c Client) DeleteResourceSet(rsReq ResourceSet) error

func (*Client) DeleteUser

func (c *Client) DeleteUser(user User) error

func (*Client) DeleteVIF

func (c *Client) DeleteVIF(vifReq *VIF) (err error)

func (*Client) DeleteVm

func (c *Client) DeleteVm(id string) error

func (*Client) DisconnectDisk

func (c *Client) DisconnectDisk(d Disk) error

func (*Client) DisconnectVIF

func (c *Client) DisconnectVIF(vifReq *VIF) (err error)

func (*Client) EjectCd

func (c *Client) EjectCd(id string) error

func (*Client) EjectVmCd

func (c *Client) EjectVmCd(vm *Vm) error

func (*Client) FindFromGetAllObjects

func (c *Client) FindFromGetAllObjects(obj XoObject) (interface{}, error)

func (*Client) GetAcl

func (c *Client) GetAcl(aclReq Acl) (*Acl, error)

func (*Client) GetAcls

func (c *Client) GetAcls() ([]Acl, error)

func (*Client) GetAllCloudConfigs

func (c *Client) GetAllCloudConfigs() ([]CloudConfig, error)

func (*Client) GetAllObjectsOfType

func (c *Client) GetAllObjectsOfType(obj XoObject, response interface{}) error

func (*Client) GetAllUsers

func (c *Client) GetAllUsers() ([]User, error)

func (*Client) GetCdroms

func (c *Client) GetCdroms(vm *Vm) ([]Disk, error)

func (*Client) GetCloudConfig

func (c *Client) GetCloudConfig(id string) (*CloudConfig, error)

func (*Client) GetCloudConfigByName

func (c *Client) GetCloudConfigByName(name string) ([]CloudConfig, error)

func (*Client) GetDisks

func (c *Client) GetDisks(vm *Vm) ([]Disk, error)

func (*Client) GetHostById

func (c *Client) GetHostById(id string) (host Host, err error)

func (*Client) GetHostByName

func (c *Client) GetHostByName(nameLabel string) (hosts []Host, err error)

func (*Client) GetNetwork

func (c *Client) GetNetwork(netReq Network) (*Network, error)

func (*Client) GetNetworks

func (c *Client) GetNetworks() ([]Network, error)

func (*Client) GetObjectsWithTags

func (c *Client) GetObjectsWithTags(tags []string) ([]Object, error)

func (*Client) GetPIF

func (c *Client) GetPIF(pifReq PIF) (pifs []PIF, err error)

func (*Client) GetPIFByDevice

func (c *Client) GetPIFByDevice(dev string, vlan int) ([]PIF, error)

func (*Client) GetParentVDI

func (c *Client) GetParentVDI(vbd VBD) (VDI, error)

func (*Client) GetPoolByName

func (c *Client) GetPoolByName(name string) (pools []Pool, err error)

func (*Client) GetPools

func (c *Client) GetPools(pool Pool) (pools []Pool, err error)

func (Client) GetResourceSet

func (c Client) GetResourceSet(rsReq ResourceSet) ([]ResourceSet, error)

func (Client) GetResourceSetById

func (c Client) GetResourceSetById(id string) (*ResourceSet, error)

func (Client) GetResourceSets

func (c Client) GetResourceSets() ([]ResourceSet, error)

func (*Client) GetSortedHosts

func (c *Client) GetSortedHosts(host Host, sortBy, sortOrder string) (hosts []Host, err error)

func (*Client) GetStorageRepository

func (c *Client) GetStorageRepository(sr StorageRepository) ([]StorageRepository, error)

func (*Client) GetStorageRepositoryById

func (c *Client) GetStorageRepositoryById(id string) (StorageRepository, error)

func (*Client) GetTemplate

func (c *Client) GetTemplate(template Template) ([]Template, error)

func (*Client) GetUser

func (c *Client) GetUser(userReq User) (*User, error)

func (*Client) GetVDIs

func (c *Client) GetVDIs(vdiReq VDI) ([]VDI, error)

func (*Client) GetVIF

func (c *Client) GetVIF(vifReq *VIF) (*VIF, error)

func (*Client) GetVIFs

func (c *Client) GetVIFs(vm *Vm) ([]VIF, error)

func (*Client) GetVm

func (c *Client) GetVm(vmReq Vm) (*Vm, error)

func (*Client) GetVms

func (c *Client) GetVms(vm Vm) ([]Vm, error)

func (*Client) HaltVm

func (c *Client) HaltVm(vmReq Vm) error

func (*Client) InsertCd

func (c *Client) InsertCd(vmId, cdId string) error

func (Client) RemoveResourceSetLimit

func (c Client) RemoveResourceSetLimit(rsReq ResourceSet, limit string) error

func (Client) RemoveResourceSetObject

func (c Client) RemoveResourceSetObject(rsReq ResourceSet, object string) error

func (Client) RemoveResourceSetSubject

func (c Client) RemoveResourceSetSubject(rsReq ResourceSet, subject string) error

func (*Client) RemoveTag

func (c *Client) RemoveTag(id, tag string) error

func (*Client) StartVm

func (c *Client) StartVm(id string) error

func (*Client) UpdateVDI

func (c *Client) UpdateVDI(d Disk) error

func (*Client) UpdateVm

func (c *Client) UpdateVm(vmReq Vm) (*Vm, error)

type CloudConfig

type CloudConfig struct {
	Name     string `json:"name"`
	Template string `json:"template"`
	Id       string `json:"id"`
}

func (CloudConfig) Compare

func (c CloudConfig) Compare(obj interface{}) bool

type CloudConfigResponse

type CloudConfigResponse struct {
	Result []CloudConfig `json:"result"`
}

type Config

type Config struct {
	Url                string
	Username           string
	Password           string
	InsecureSkipVerify bool
}

func GetConfigFromEnv

func GetConfigFromEnv() Config

type CpuInfo

type CpuInfo struct {
	Cores   int64 `json:"cores,float64`
	Sockets int64 `json:"sockets,float64`
}

type Disk

type Disk struct {
	VBD
	VDI
}

type Host

type Host struct {
	Id        string           `json:"id"`
	NameLabel string           `json:"name_label"`
	Tags      []interface{}    `json:"tags,omitempty"`
	Pool      string           `json:"$pool"`
	Memory    HostMemoryObject `json:"memory"`
	Cpus      CpuInfo          `json:"cpus"`
}

func (Host) Compare

func (h Host) Compare(obj interface{}) bool

type HostMemoryObject

type HostMemoryObject struct {
	Usage int `json:"usage"`
	Size  int `json:"size"`
}

type Installation

type Installation struct {
	Method     string `json:"-"`
	Repository string `json:"-"`
}

type MemoryObject

type MemoryObject struct {
	Dynamic []int `json:"dynamic"`
	Static  []int `json:"static"`
	Size    int   `json:"size"`
}

type Network

type Network struct {
	Id        string `json:"id"`
	NameLabel string `json:"name_label"`
	Bridge    string `json:"bridge"`
	PoolId    string `json:"$poolId"`
}

func (Network) Compare

func (net Network) Compare(obj interface{}) bool

type NotFound

type NotFound struct {
	Query XoObject
}

func (NotFound) Error

func (e NotFound) Error() string

type NotFoundError

type NotFoundError struct {
	LastError    error
	LastRequest  interface{}
	LastResponse interface{}
	Message      string
	Retries      int
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Object

type Object struct {
	Id   string
	Type string
}

type PIF

type PIF struct {
	Device   string `json:"device"`
	Host     string `json:"$host"`
	Network  string `json:"$network"`
	Id       string `json:"id"`
	Uuid     string `json:"uuid"`
	PoolId   string `json:"$poolId"`
	Attached bool   `json:"attached"`
	Vlan     int    `json:"vlan"`
}

func (PIF) Compare

func (p PIF) Compare(obj interface{}) bool

type Pool

type Pool struct {
	Id          string  `json:"id"`
	NameLabel   string  `json:"name_label"`
	Description string  `json:"name_description"`
	Cpus        CpuInfo `json:"cpus"`
	DefaultSR   string  `json:"default_SR"`
	Master      string  `json:"master"`
}

func (Pool) Compare

func (p Pool) Compare(obj interface{}) bool

type Preferences

type Preferences struct {
	SshKeys []SshKey `json:"sshKeys,omitempty"`
}

type ResourceSet

type ResourceSet struct {
	Id       string            `json:"id"`
	Limits   ResourceSetLimits `json:"limits"`
	Name     string            `json:"name"`
	Subjects []string          `json:"subjects"`
	Objects  []string          `json:"objects"`
}

func (ResourceSet) Compare

func (rs ResourceSet) Compare(obj interface{}) bool

type ResourceSetLimit

type ResourceSetLimit struct {
	Available int `json:"available,omitempty"`
	Total     int `json:"total,omitempty"`
}

type ResourceSetLimits

type ResourceSetLimits struct {
	Cpus   ResourceSetLimit `json:"cpus,omitempty"`
	Memory ResourceSetLimit `json:"memory,omitempty"`
	Disk   ResourceSetLimit `json:"disk,omitempty"`
}

type SshKey

type SshKey struct {
	Title string
	Key   string
}

type StateChangeConf

type StateChangeConf struct {
	Delay          time.Duration    // Wait this time before starting checks
	Pending        []string         // States that are "allowed" and will continue trying
	Refresh        StateRefreshFunc // Refreshes the current state
	Target         []string         // Target state
	Timeout        time.Duration    // The amount of time to wait before timeout
	MinTimeout     time.Duration    // Smallest time to wait before refreshes
	PollInterval   time.Duration    // Override MinTimeout/backoff and only poll this often
	NotFoundChecks int              // Number of times to allow not found

	// This is to work around inconsistent APIs
	ContinuousTargetOccurence int // Number of times the Target state has to occur continuously
}

StateChangeConf is the configuration struct used for `WaitForState`.

func (*StateChangeConf) WaitForState

func (conf *StateChangeConf) WaitForState() (interface{}, error)

WaitForState watches an object and waits for it to achieve the state specified in the configuration using the specified Refresh() func, waiting the number of seconds specified in the timeout configuration.

If the Refresh function returns an error, exit immediately with that error.

If the Refresh function returns a state other than the Target state or one listed in Pending, return immediately with an error.

If the Timeout is exceeded before reaching the Target state, return an error.

Otherwise, the result is the result of the first call to the Refresh function to reach the target state.

type StateRefreshFunc

type StateRefreshFunc func() (result interface{}, state string, err error)

StateRefreshFunc is a function type used for StateChangeConf that is responsible for refreshing the item being watched for a state change.

It returns three results. `result` is any object that will be returned as the final object after waiting for state change. This allows you to return the final updated object, for example an EC2 instance after refreshing it.

`state` is the latest state of that object. And `err` is any error that may have happened while refreshing the state.

type StorageRepository

type StorageRepository struct {
	Id            string   `json:"id"`
	Uuid          string   `json:"uuid"`
	NameLabel     string   `json:"name_label"`
	PoolId        string   `json:"$poolId"`
	SRType        string   `json:"SR_type"`
	Container     string   `json:"$container"`
	PhysicalUsage int      `json:"physical_usage"`
	Size          int      `json:"size"`
	Usage         int      `json:"usage"`
	Tags          []string `json:"tags,omitempty"`
}

func (StorageRepository) Compare

func (s StorageRepository) Compare(obj interface{}) bool

type Template

type Template struct {
	Id           string       `json:"id"`
	Uuid         string       `json:"uuid"`
	NameLabel    string       `json:"name_label"`
	PoolId       string       `json:"$poolId"`
	TemplateInfo TemplateInfo `json:"template_info"`
}

func (Template) Compare

func (t Template) Compare(obj interface{}) bool

type TemplateDisk

type TemplateDisk struct {
	Bootable bool   `json:"bootable"`
	Device   string `json:"device"`
	Size     int    `json:"size"`
	Type     string `json:"type"`
	SR       string `json:"SR"`
}

type TemplateInfo

type TemplateInfo struct {
	Arch  string         `json:"arch"`
	Disks []TemplateDisk `json:"disks"`
}

type TimeoutError

type TimeoutError struct {
	LastError     error
	LastState     string
	Timeout       time.Duration
	ExpectedState []string
}

TimeoutError is returned when WaitForState times out

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

type UnexpectedStateError

type UnexpectedStateError struct {
	LastError     error
	State         string
	ExpectedState []string
}

UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending

func (*UnexpectedStateError) Error

func (e *UnexpectedStateError) Error() string

type User

type User struct {
	Id          string
	Email       string
	Password    string `json:"-"`
	Groups      []string
	Permission  string
	Preferences Preferences
}

func (User) Compare

func (user User) Compare(obj interface{}) bool

type VBD

type VBD struct {
	Id        string `json:"id"`
	Attached  bool
	Device    string
	ReadOnly  bool   `json:"read_only"`
	VmId      string `json:"VM"`
	VDI       string `json:"VDI"`
	IsCdDrive bool   `json:"is_cd_drive"`
	Position  string
	Bootable  bool
	PoolId    string `json:"$poolId"`
}

TODO: Change this file to storage or disks?

func (VBD) Compare

func (v VBD) Compare(obj interface{}) bool

type VDI

type VDI struct {
	VDIId           string   `json:"id"`
	SrId            string   `json:"$SR"`
	NameLabel       string   `json:"name_label"`
	NameDescription string   `json:"name_description"`
	Size            int      `json:"size"`
	VBDs            []string `json:"$VBDs"`
	PoolId          string   `json:"$poolId"`
	Tags            []string `json:"tags,omitempty"`
}

func (VDI) Compare

func (v VDI) Compare(obj interface{}) bool

type VIF

type VIF struct {
	Id         string `json:"id"`
	Attached   bool   `json:"attached"`
	Network    string `json:"$network"`
	Device     string `json:"device"`
	MacAddress string `json:"MAC"`
	VmId       string `json:"$VM"`
}

func (VIF) Compare

func (v VIF) Compare(obj interface{}) bool

type Videoram

type Videoram struct {
	Value int `json:"-"`
}

The XO api sometimes returns the videoram field as an int and sometimes as a string. This overrides the default json unmarshalling so that we can handle both of these cases

func (*Videoram) UnmarshalJSON

func (v *Videoram) UnmarshalJSON(data []byte) (err error)

type Vm

type Vm struct {
	Addresses          map[string]string `json:"addresses,omitempty"`
	BlockedOperations  map[string]string `json:"blockedOperations,omitempty"`
	Boot               Boot              `json:"boot,omitempty"`
	Type               string            `json:"type,omitempty"`
	Id                 string            `json:"id,omitempty"`
	AffinityHost       string            `json:"affinityHost,omitempty"`
	NameDescription    string            `json:"name_description"`
	NameLabel          string            `json:"name_label"`
	CPUs               CPUs              `json:"CPUs"`
	ExpNestedHvm       bool              `json:"expNestedHvm,omitempty"`
	Memory             MemoryObject      `json:"memory"`
	PowerState         string            `json:"power_state"`
	VIFs               []string          `json:"VIFs"`
	VBDs               []string          `json:"$VBDs"`
	VirtualizationMode string            `json:"virtualizationMode"`
	PoolId             string            `json:"$poolId"`
	Template           string            `json:"template"`
	AutoPoweron        bool              `json:"auto_poweron"`
	HA                 string            `json:"high_availability"`
	CloudConfig        string            `json:"cloudConfig"`
	ResourceSet        string            `json:"resourceSet,omitempty"`
	// TODO: (#145) Uncomment this once issues with secure_boot have been figured out
	// SecureBoot         bool              `json:"secureBoot,omitempty"`
	Tags       []string `json:"tags"`
	Videoram   Videoram `json:"videoram,omitempty"`
	Vga        string   `json:"vga,omitempty"`
	StartDelay int      `json:startDelay,omitempty"`
	Host       string   `json:"$container"`

	// These fields are used for passing in disk inputs when
	// creating Vms, however, this is not a real field as far
	// as the XO api or XAPI is concerned
	Disks              []Disk              `json:"-"`
	CloudNetworkConfig string              `json:"-"`
	VIFsMap            []map[string]string `json:"-"`
	WaitForIps         bool                `json:"-"`
	Installation       Installation        `json:"-"`
}

func (Vm) Compare

func (v Vm) Compare(obj interface{}) bool

type XOClient

type XOClient interface {
	GetObjectsWithTags(tags []string) ([]Object, error)

	CreateVm(vmReq Vm, d time.Duration) (*Vm, error)
	GetVm(vmReq Vm) (*Vm, error)
	GetVms(vm Vm) ([]Vm, error)
	UpdateVm(vmReq Vm) (*Vm, error)
	DeleteVm(id string) error
	HaltVm(vmReq Vm) error
	StartVm(id string) error

	GetCloudConfigByName(name string) ([]CloudConfig, error)
	CreateCloudConfig(name, template string) (*CloudConfig, error)
	GetCloudConfig(id string) (*CloudConfig, error)
	DeleteCloudConfig(id string) error
	GetAllCloudConfigs() ([]CloudConfig, error)

	GetHostById(id string) (host Host, err error)
	GetHostByName(nameLabel string) (hosts []Host, err error)

	GetPools(pool Pool) ([]Pool, error)
	GetPoolByName(name string) (pools []Pool, err error)

	GetSortedHosts(host Host, sortBy, sortOrder string) (hosts []Host, err error)

	CreateResourceSet(rsReq ResourceSet) (*ResourceSet, error)
	GetResourceSets() ([]ResourceSet, error)
	GetResourceSet(rsReq ResourceSet) ([]ResourceSet, error)
	GetResourceSetById(id string) (*ResourceSet, error)
	DeleteResourceSet(rsReq ResourceSet) error
	AddResourceSetSubject(rsReq ResourceSet, subject string) error
	AddResourceSetObject(rsReq ResourceSet, object string) error
	AddResourceSetLimit(rsReq ResourceSet, limit string, quantity int) error
	RemoveResourceSetSubject(rsReq ResourceSet, subject string) error
	RemoveResourceSetObject(rsReq ResourceSet, object string) error
	RemoveResourceSetLimit(rsReq ResourceSet, limit string) error

	CreateUser(user User) (*User, error)
	GetAllUsers() ([]User, error)
	GetUser(userReq User) (*User, error)
	DeleteUser(userReq User) error

	CreateNetwork(netReq Network) (*Network, error)
	GetNetwork(netReq Network) (*Network, error)
	GetNetworks() ([]Network, error)
	DeleteNetwork(id string) error

	GetPIF(pifReq PIF) (pifs []PIF, err error)
	GetPIFByDevice(dev string, vlan int) ([]PIF, error)

	GetStorageRepository(sr StorageRepository) ([]StorageRepository, error)
	GetStorageRepositoryById(id string) (StorageRepository, error)

	GetTemplate(template Template) ([]Template, error)

	GetVDIs(vdiReq VDI) ([]VDI, error)
	UpdateVDI(d Disk) error

	CreateAcl(acl Acl) (*Acl, error)
	GetAcl(aclReq Acl) (*Acl, error)
	DeleteAcl(acl Acl) error

	AddTag(id, tag string) error
	RemoveTag(id, tag string) error

	GetDisks(vm *Vm) ([]Disk, error)
	CreateDisk(vm Vm, d Disk) (string, error)
	DeleteDisk(vm Vm, d Disk) error
	ConnectDisk(d Disk) error
	DisconnectDisk(d Disk) error

	GetVIF(vifReq *VIF) (*VIF, error)
	GetVIFs(vm *Vm) ([]VIF, error)
	CreateVIF(vm *Vm, vif *VIF) (*VIF, error)
	DeleteVIF(vifReq *VIF) (err error)
	DisconnectVIF(vifReq *VIF) (err error)
	ConnectVIF(vifReq *VIF) (err error)

	GetCdroms(vm *Vm) ([]Disk, error)
	EjectCd(id string) error
	InsertCd(vmId, cdId string) error
}

func NewClient

func NewClient(config Config) (XOClient, error)

type XoObject

type XoObject interface {
	Compare(obj interface{}) bool
}

Jump to

Keyboard shortcuts

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