proxmox

package
v0.0.0-...-d27d592 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const TaskStatusCheckInterval = 2

TaskStatusCheckInterval - time between async checks in seconds

View Source
const TaskTimeout = 300

TaskTimeout - default async task call timeout in seconds

Variables

View Source
var Debug = new(bool)

Functions

func GetMaxVmId

func GetMaxVmId() (max int, err error)

func GetNextVmId

func GetNextVmId(currentId int) (nextId int, err error)

func GetNodeList

func GetNodeList() (list map[string]interface{}, err error)

func GetStorageAndVolumeName

func GetStorageAndVolumeName(
	fullDiskName string,
	separator string,
) (storageName string, volumeName string)

Extract disk storage and disk volume, since disk name is saved in Proxmox with its storage.

func GetStorageList

func GetStorageList() (list map[string]interface{}, err error)

func GetVmList

func GetVmList() (vmlist []interface{}, err error)

func Itob

func Itob(i int) bool

func ParamsToBody

func ParamsToBody(params map[string]interface{}) (body []byte)

func ParseSubConf

func ParseSubConf(
	element string,
	separator string,
) (key string, value interface{})

ParseSubConf - Parse standard sub-conf strings `key=value`.

func ResponseJSON

func ResponseJSON(resp *http.Response) (jbody map[string]interface{}, err error)

func TypedResponse

func TypedResponse(resp *http.Response, v interface{}) error

Types

type AgentNetworkInterface

type AgentNetworkInterface struct {
	MACAddress  string
	IPAddresses []net.IP
	Name        string
	Statistics  map[string]int64
}

func (*AgentNetworkInterface) UnmarshalJSON

func (a *AgentNetworkInterface) UnmarshalJSON(b []byte) (err error)

type Client

type Client struct {
	ApiUrl   string
	Username string
	Password string
	// contains filtered or unexported fields
}

Client - URL, user and password to specifc Proxmox node

func GetClient

func GetClient() *Client

func NewClient

func NewClient(apiUrl string, hclient *http.Client, tls *tls.Config) (client *Client, err error)

func (*Client) GetJsonRetryable

func (c *Client) GetJsonRetryable(url string, data *map[string]interface{}, tries int) error

func (*Client) GetTaskExitstatus

func (c *Client) GetTaskExitstatus(taskUpid string) (exitStatus interface{}, err error)

func (*Client) Login

func (c *Client) Login(username string, password string) (err error)

func (*Client) Set

func (c *Client) Set()

func (*Client) WaitForCompletion

func (c *Client) WaitForCompletion(taskResponse map[string]interface{}) (waitExitStatus string, err error)

WaitForCompletion - poll the API for task completion

type ConfigLxc

type ConfigLxc struct {
	Arch         string    `json:"arch"`
	Cmode        string    `json:"cmode"`
	Console      bool      `json:"console"`
	Cores        int       `json:"cores"`
	Cpuunits     int       `json:"cpuunits"`
	Description  string    `json:"description"`
	Digest       string    `json:"digest"`
	Hostname     string    `json:"hostname"`
	Memory       int       `json:"memory"`
	Mp           VmDevices `json:"mp"`
	Nameserver   string    `json:"nameserver"`
	Net          VmDevices `json:"net"`
	Onboot       bool      `json:"onboot"`
	Ostype       string    `json:"ostype"`
	Ostemplate   string    `json:"ostemplate"`
	Password     string    `json:"password"`
	Protection   bool      `json:"protection"`
	Rootfs       VmDevice  `json:"rootfs"`
	Searchdomain string    `json:"searchdomain"`
	Startup      string    `json:"startup"`
	Sshkeys      string    `json:"ssh-public-keys"`
	Swap         int       `json:"swap"`
	Tty          int       `json:"tty"`
	Unprivileged bool      `json:"unprivileged"`
}

ConfigLxc - Proxmox API LXC options

func NewConfigLxc

func NewConfigLxc() *ConfigLxc

this factory returns a new struct with the members set to defaults

func NewConfigLxcFromApi

func NewConfigLxcFromApi(vm *Vm) (config *ConfigLxc, err error)

func NewConfigLxcFromJson

func NewConfigLxcFromJson(io io.Reader, bare bool) (config *ConfigLxc, err error)

func (ConfigLxc) CreateDisksParams

func (c ConfigLxc) CreateDisksParams(
	vmID int,
	params map[string]interface{},
	cloned bool,
)

Create parameters for each mountpoint

func (ConfigLxc) CreateNetParams

func (c ConfigLxc) CreateNetParams(vmID int, params map[string]interface{})

Create parameters for each Nic device.

func (ConfigLxc) CreateVm

func (config ConfigLxc) CreateVm(vm *Vm) (err error)

CreateVm - Tell Proxmox API to make the VM

func (ConfigLxc) UpdateConfig

func (config ConfigLxc) UpdateConfig(vm *Vm) (err error)

type ConfigQemu

type ConfigQemu struct {
	Name        string    `json:"name"`
	Description string    `json:"desc"`
	Onboot      bool      `json:"onboot"`
	Agent       string    `json:"agent"`
	Memory      int       `json:"memory"`
	Ostype      string    `json:"ostype"`
	Cores       int       `json:"cores"`
	Sockets     int       `json:"sockets"`
	Iso         string    `json:"iso"`
	Disk        VmDevices `json:"disk"`
	Net         VmDevices `json:"net"`

	// cloud-init options
	CIuser     string `json:"ciuser"`
	CIpassword string `json:"cipassword"`

	Searchdomain string `json:"searchdomain"`
	Nameserver   string `json:"nameserver"`
	Sshkeys      string `json:"sshkeys"`

	// arrays are hard, support 2 interfaces for now
	Ipconfig0 string `json:"ipconfig0"`
	Ipconfig1 string `json:"ipconfig1"`

	Delete string `json:"delete"`
}

ConfigQemu - Proxmox API QEMU options

func NewConfigQemuFromApi

func NewConfigQemuFromApi(vm *Vm) (config *ConfigQemu, err error)

func NewConfigQemuFromJson

func NewConfigQemuFromJson(io io.Reader) (config *ConfigQemu, err error)

func (ConfigQemu) CreateDisksParams

func (c ConfigQemu) CreateDisksParams(
	vmID int,
	params map[string]interface{},
	cloned bool,
)

Create parameters for each disk.

func (ConfigQemu) CreateNetParams

func (c ConfigQemu) CreateNetParams(vmID int, params map[string]interface{})

Create parameters for each Nic device.

func (ConfigQemu) CreateVm

func (config ConfigQemu) CreateVm(vm *Vm) (err error)

CreateVm - Tell Proxmox API to make the VM

func (ConfigQemu) HasCloudInit

func (config ConfigQemu) HasCloudInit() bool

HasCloudInit - are there cloud-init options?

func (ConfigQemu) UpdateConfig

func (config ConfigQemu) UpdateConfig(vm *Vm) (err error)

type Node

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

func FindNode

func FindNode(name string) (node *Node, err error)

factory by name getInfo for nodes already looks up by name, so use that

func NewNode

func NewNode(name string) *Node

base factory

func (*Node) Check

func (node *Node) Check() (err error)

func (*Node) CreateVolume

func (node *Node) CreateVolume(fullDiskName string, diskParams map[string]interface{}) (err error)

TODO: add autodetection of existant volumes and act accordingly

func (*Node) DeleteVolume

func (node *Node) DeleteVolume(fullDiskName string) (err error)

func (*Node) GetInfo

func (node *Node) GetInfo() (nodeInfo map[string]interface{}, err error)

func (*Node) Name

func (node *Node) Name() string

type Response

type Response struct {
	Resp *http.Response
	Body []byte
}

type Session

type Session struct {
	ApiUrl     string
	AuthTicket string
	CsrfToken  string
	Headers    http.Header
	// contains filtered or unexported fields
}

func NewSession

func NewSession(apiUrl string, hclient *http.Client, tls *tls.Config) (session *Session, err error)

func (*Session) Delete

func (s *Session) Delete(
	url string,
	params *url.Values,
	headers *http.Header,
) (resp *http.Response, err error)

func (*Session) Do

func (s *Session) Do(req *http.Request) (*http.Response, error)

func (*Session) Get

func (s *Session) Get(
	url string,
	params *url.Values,
	headers *http.Header,
) (resp *http.Response, err error)

func (*Session) GetJSON

func (s *Session) GetJSON(
	url string,
	params *url.Values,
	headers *http.Header,
	responseContainer interface{},
) (resp *http.Response, err error)

func (*Session) Head

func (s *Session) Head(
	url string,
	params *url.Values,
	headers *http.Header,
) (resp *http.Response, err error)

func (*Session) Login

func (s *Session) Login(username string, password string) (err error)

func (*Session) NewRequest

func (s *Session) NewRequest(method, url string, headers *http.Header, body io.Reader) (req *http.Request, err error)

func (*Session) Post

func (s *Session) Post(
	url string,
	params *url.Values,
	headers *http.Header,
	body *[]byte,
) (resp *http.Response, err error)

func (*Session) PostJSON

func (s *Session) PostJSON(
	url string,
	params *url.Values,
	headers *http.Header,
	body interface{},
	responseContainer interface{},
) (resp *http.Response, err error)

func (*Session) Put

func (s *Session) Put(
	url string,
	params *url.Values,
	headers *http.Header,
	body *[]byte,
) (resp *http.Response, err error)

func (*Session) Request

func (s *Session) Request(
	method string,
	url string,
	params *url.Values,
	headers *http.Header,
	body *[]byte,
) (resp *http.Response, err error)

Perform a simple get to an endpoint

func (*Session) RequestJSON

func (s *Session) RequestJSON(
	method string,
	url string,
	params *url.Values,
	headers *http.Header,
	body interface{},
	responseContainer interface{},
) (resp *http.Response, err error)

Perform a simple get to an endpoint and unmarshall returned JSON

type Storage

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

func FindStorage

func FindStorage(name string) (storage *Storage, err error)

factory by name getInfo for storage already looks up by name, so use that

func NewStorage

func NewStorage(name string) *Storage

base factory

func (*Storage) Check

func (storage *Storage) Check() (err error)

func (*Storage) GetInfo

func (storage *Storage) GetInfo() (storageInfo map[string]interface{}, err error)

func (*Storage) Name

func (storage *Storage) Name() string

type Vm

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

func FindVm

func FindVm(name string) (vm *Vm, err error)

factory by name

func NewVm

func NewVm(id int) *Vm

base factory

func (*Vm) Check

func (vm *Vm) Check() (err error)

func (*Vm) Clone

func (vm *Vm) Clone(newid int, cloneParams map[string]interface{}) (exitStatus interface{}, err error)

func (*Vm) Create

func (vm *Vm) Create(vmParams map[string]interface{}) (exitStatus string, err error)

func (*Vm) CreateBackup

func (vm *Vm) CreateBackup(bkpParams map[string]interface{}) (exitStatus string, err error)

func (*Vm) CreateSnapshot

func (vm *Vm) CreateSnapshot(snapParams map[string]interface{}) (exitStatus string, err error)

func (*Vm) CreateTemplate

func (vm *Vm) CreateTemplate() (exitStatus interface{}, err error)

func (*Vm) Delete

func (vm *Vm) Delete() (exitStatus string, err error)

func (*Vm) DeleteSnapshot

func (vm *Vm) DeleteSnapshot(snapName string) (exitStatus interface{}, err error)

func (*Vm) GetAgentNetworkInterfaces

func (vm *Vm) GetAgentNetworkInterfaces() (ifs []AgentNetworkInterface, err error)

func (*Vm) GetConfig

func (vm *Vm) GetConfig() (config map[string]interface{}, err error)

func (*Vm) GetInfo

func (vm *Vm) GetInfo() (vmInfo map[string]interface{}, err error)

func (*Vm) GetSnapshotList

func (vm *Vm) GetSnapshotList() (list map[string]interface{}, err error)

func (*Vm) GetSpiceProxy

func (vm *Vm) GetSpiceProxy() (vmSpiceProxy map[string]interface{}, err error)

func (*Vm) GetStatus

func (vm *Vm) GetStatus() (vmState map[string]interface{}, err error)

func (*Vm) Id

func (vm *Vm) Id() int

func (*Vm) Migrate

func (vm *Vm) Migrate(migrateParams map[string]interface{}) (exitStatus interface{}, err error)

func (*Vm) MonitorCmd

func (vm *Vm) MonitorCmd(command string) (monitorRes map[string]interface{}, err error)

func (*Vm) MoveDisk

func (vm *Vm) MoveDisk(moveParams map[string]interface{}) (exitStatus interface{}, err error)

func (*Vm) Node

func (vm *Vm) Node() *Node

func (*Vm) RemoveSshForwardUsernet

func (vm *Vm) RemoveSshForwardUsernet() (err error)

device_del net1 netdev_del net1

func (*Vm) Reset

func (vm *Vm) Reset() (exitStatus string, err error)

func (*Vm) ResizeDisk

func (vm *Vm) ResizeDisk(disk string, sizeGB string) (exitStatus interface{}, err error)

sizeGB can be a number to set an absolute size, or a number preceded by + to grow the volume by that many GB. If using an absolute size this has to be larger than the current size (shrinking is not supported by PVE)

func (*Vm) Resume

func (vm *Vm) Resume() (exitStatus string, err error)

func (*Vm) Rollback

func (vm *Vm) Rollback(snapName string) (exitStatus string, err error)

func (*Vm) SendKeysString

func (vm *Vm) SendKeysString(keys string) (err error)

func (*Vm) SetConfig

func (vm *Vm) SetConfig(vmParams map[string]interface{}) (exitStatus interface{}, err error)

func (*Vm) SetNode

func (vm *Vm) SetNode(n *Node)

func (*Vm) SetStatus

func (vm *Vm) SetStatus(status string) (exitStatus string, err error)

func (*Vm) SetType

func (vm *Vm) SetType(t string)

func (*Vm) Shutdown

func (vm *Vm) Shutdown() (exitStatus string, err error)

func (*Vm) SshForwardUsernet

func (vm *Vm) SshForwardUsernet() (sshPort string, err error)

This is because proxmox create/config API won't let us make usernet devices

func (*Vm) Start

func (vm *Vm) Start() (exitStatus string, err error)

func (*Vm) Stop

func (vm *Vm) Stop() (exitStatus string, err error)

func (*Vm) Suspend

func (vm *Vm) Suspend() (exitStatus string, err error)

func (*Vm) Type

func (vm *Vm) Type() string

func (*Vm) WaitForShutdown

func (vm *Vm) WaitForShutdown() (err error)

Useful waiting for ISO install to complete

type VmDevice

type VmDevice map[string]interface{}

func ParseConf

func ParseConf(
	kvString string,
	confSeparator string,
	subConfSeparator string,
) VmDevice

ParseConf - Parse standard device conf string `key1=val1,key2=val2`.

type VmDeviceParam

type VmDeviceParam []string

type VmDevices

type VmDevices map[int]map[string]interface{}

Jump to

Keyboard shortcuts

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