api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const MaxConn = 4
View Source
const MaxRetry = 30
View Source
const OfflineNodeStatus = NodeStatus("offline")
View Source
const OnlineNodeStatus = NodeStatus("online")
View Source
const PveMaxVMID = 999999999
View Source
const RetryInterval = 3 * time.Second
View Source
const RunningVMStatus = VMStatus("running")
View Source
const StoppedVMStatus = VMStatus("stopped")
View Source
const UnknownNodeStatus = NodeStatus("unknown")

Variables

This section is empty.

Functions

func NewStatusError added in v0.2.0

func NewStatusError(status int, body string) error

Types

type Config

type Config struct {
	// CPU cores
	CPUCores int `url:"cores" json:"cores"`
	// CPU sockets
	CPUSockets int `url:"sockets" json:"sockets"`
	// VCPU cores
	VCPUs int `url:"vcpus" json:"vcpus"`
	// Memory size in megabytes
	Memory int `url:"memory" json:"memory"`
	// Cloud-init: user name
	User string `url:"ciuser" json:"ciuser"`
	// Cloud-init: SSH public keys
	SSHKeys string `url:"sshkeys" json:"sshkeys"`
	// Cloud-init: static IP address configuration
	// format: gw=<ipv4>,ip=<ipv4>/<CIDR>
	IPAddress string `url:"ipconfig0" json:"ipconfig0"`
}

type Dialer

type Dialer func(network, addr string) (net.Conn, error)

type NodeID

type NodeID string

type NodeInfo

type NodeInfo struct {
	ID NodeID `json:"node"`
	// Number of available CPUs.
	MaxCPU int `json:"maxcpu"`
	// Number of available memory in bytes.
	MaxMem int `json:"maxmem"`
	// Used memory in bytes.
	Mem int
	// Current node status
	//  - unknown
	//  - online
	//  - offline
	Status NodeStatus
}

type NodeStatus added in v0.3.0

type NodeStatus string

type NodeVMID

type NodeVMID struct {
	NodeID NodeID
	VMID   VMID
}

type PveClient

type PveClient struct {
	PveClientOption
	// contains filtered or unexported fields
}

See https://pve.proxmox.com/pve-docs/api-viewer/

func NewPveClient

func NewPveClient(option PveClientOption) *PveClient

func (*PveClient) CloneVM

func (c *PveClient) CloneVM(from, to NodeVMID, name, description, pool string) *Task

CloneVM creates a copy of virtual machine/template.

func (*PveClient) Config

func (c *PveClient) Config(id NodeVMID) (*Config, error)

Config returns current configuration of the specified VM.

func (*PveClient) DeleteVM

func (c *PveClient) DeleteVM(id NodeVMID) *Task

DeleteVM deletes the VM. If VM is running, it will be stop immediately and delete it.

func (*PveClient) FixCloudInitDrive added in v0.3.0

func (c *PveClient) FixCloudInitDrive(id NodeVMID) error

FixCloudInitDrive reconnects cloud-init drive. This method provides a workaround for the ProxmoxVE bug.

func (*PveClient) IDFromName

func (c *PveClient) IDFromName(name string) (NodeVMID, error)

IDFromName finds an VM with the given name and returns an ID.

func (*PveClient) ListAllVMs

func (c *PveClient) ListAllVMs() ([]*VMInfo, error)

ListAllVMs returns information of all VMs in the cluster.

func (*PveClient) ListNodes

func (c *PveClient) ListNodes() ([]*NodeInfo, error)

ListNodes returns all NodeIDs in the cluster.

func (*PveClient) ListVMs

func (c *PveClient) ListVMs(nodeID NodeID) ([]*VMInfo, error)

ListVMs returns information of all VMs in the specified node.

func (*PveClient) RandomVMID

func (c *PveClient) RandomVMID() (VMID, error)

RandomVMID returns an unused VMID.

func (*PveClient) ResizeVolume

func (c *PveClient) ResizeVolume(id NodeVMID, disk string, size int) error

ResizeVolume increases disk size. The size parameter is in gigabytes.

func (*PveClient) StartVM

func (c *PveClient) StartVM(id NodeVMID) *Task

StartVM starts the VM.

func (*PveClient) StopVM

func (c *PveClient) StopVM(id NodeVMID) *Task

StopVM stops the VM immediately. This operation is not safe. This is akin to pulling the power plug of a running computer and may cause VM data corruption.

func (*PveClient) Ticket

func (c *PveClient) Ticket() error

Ticket creates an authentication ticket.

func (*PveClient) UpdateConfig

func (c *PveClient) UpdateConfig(id NodeVMID, config *Config) error

UpdateConfig updates configuration of the specified VM.

func (*PveClient) VMInfo

func (c *PveClient) VMInfo(id NodeVMID) (*VMInfo, error)

VMInfo returns current status of the specified VM.

type PveClientOption

type PveClientOption struct {
	Address     string
	User        string
	Password    string
	Fingerprint string
}

type StatusError added in v0.2.0

type StatusError struct {
	Err        error
	StatusCode int
	Body       string
}

func (*StatusError) Error added in v0.2.0

func (e *StatusError) Error() string

type Task

type Task struct {
	TaskID TaskID
	NodeID NodeID
	Client *PveClient
	// contains filtered or unexported fields
}

func NewTask added in v0.2.0

func NewTask(fn func(task *Task) error) *Task

func (*Task) LogAll

func (t *Task) LogAll() ([]string, error)

func (*Task) Wait

func (t *Task) Wait(ctx context.Context) error

func (*Task) WaitFn added in v0.2.0

func (t *Task) WaitFn(ctx context.Context) error

type TaskID

type TaskID string

type TaskStatus

type TaskStatus struct {
	Status     string
	ExitStatus string `json:"exitstatus"`
}

func (*TaskStatus) IsOK

func (s *TaskStatus) IsOK() bool

func (*TaskStatus) IsStopped

func (s *TaskStatus) IsStopped() bool

type VMID

type VMID string

type VMInfo

type VMInfo struct {
	ID   NodeVMID
	Name string
	// Maximum usable CPUs.
	Cpus int
	// Maximum memory in bytes.
	Mem int
	// Qemu process status.
	// - stopped
	// - running
	Status VMStatus
}

func (*VMInfo) String

func (i *VMInfo) String() string

type VMStatus

type VMStatus string

Jump to

Keyboard shortcuts

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