proxmox

package
v0.0.0-...-a295664 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: MIT Imports: 18 Imported by: 0

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 Itob

func Itob(i int) bool

func MaxVmId

func MaxVmId(client *Client) (max int, err error)

func NewConfigLxc

func NewConfigLxc() configLxc

func NewConfigLxcFromApi

func NewConfigLxcFromApi(vmr *VmRef, client *Client) (config *configLxc, err error)

func NewConfigLxcFromJson

func NewConfigLxcFromJson(io io.Reader) (config configLxc, err error)

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 RemoveSshForwardUsernet

func RemoveSshForwardUsernet(vmr *VmRef, client *Client) (err error)

device_del net1 netdev_del net1

func ResponseJSON

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

func SendKeysString

func SendKeysString(vmr *VmRef, client *Client, keys string) (err error)

func SshForwardUsernet

func SshForwardUsernet(vmr *VmRef, client *Client) (sshPort string, err error)

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

func TypedResponse

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

func WaitForShutdown

func WaitForShutdown(vmr *VmRef, client *Client) (err error)

Useful waiting for ISO install to complete

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) error

type Client

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

Client - URL, user and password to specifc Proxmox node

func NewClient

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

func (*Client) CheckVmRef

func (c *Client) CheckVmRef(vmr *VmRef) (err error)

func (*Client) CloneQemuVm

func (c *Client) CloneQemuVm(vmr *VmRef, vmParams map[string]interface{}) (exitStatus string, err error)

func (*Client) CreateLxcContainer

func (c *Client) CreateLxcContainer(node string, vmParams map[string]interface{}) (exitStatus string, err error)

func (*Client) CreateQemuVm

func (c *Client) CreateQemuVm(node string, vmParams map[string]interface{}) (exitStatus string, err error)

func (*Client) CreateTemplate

func (c *Client) CreateTemplate(vmr *VmRef) error

func (*Client) CreateVMDisk

func (c *Client) CreateVMDisk(
	nodeName string,
	storageName string,
	fullDiskName string,
	diskParams map[string]interface{},
) error

CreateVMDisk - Create single disk for VM on host node.

func (*Client) DeleteVMDisks

func (c *Client) DeleteVMDisks(
	node string,
	disks []string,
) error

DeleteVMDisks - Delete VM disks from host node. By default the VM disks are deteled when the VM is deleted, so mainly this is used to delete the disks in case VM creation didn't complete.

func (*Client) DeleteVm

func (c *Client) DeleteVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) GetJsonRetryable

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

func (*Client) GetNextID

func (c *Client) GetNextID(currentID int) (nextID int, err error)

GetNextID - Get next free VMID

func (*Client) GetNodeList

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

func (*Client) GetTaskExitstatus

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

func (*Client) GetVmAgentNetworkInterfaces

func (c *Client) GetVmAgentNetworkInterfaces(vmr *VmRef) ([]AgentNetworkInterface, error)

func (*Client) GetVmConfig

func (c *Client) GetVmConfig(vmr *VmRef) (vmConfig map[string]interface{}, err error)

func (*Client) GetVmInfo

func (c *Client) GetVmInfo(vmr *VmRef) (vmInfo map[string]interface{}, err error)

func (*Client) GetVmList

func (c *Client) GetVmList() (list map[string]interface{}, err error)

func (*Client) GetVmRefByName

func (c *Client) GetVmRefByName(vmName string) (vmr *VmRef, err error)

func (*Client) GetVmSpiceProxy

func (c *Client) GetVmSpiceProxy(vmr *VmRef) (vmSpiceProxy map[string]interface{}, err error)

func (*Client) GetVmState

func (c *Client) GetVmState(vmr *VmRef) (vmState map[string]interface{}, err error)

func (*Client) Login

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

func (*Client) MigrateNode

func (c *Client) MigrateNode(vmr *VmRef, newTargetNode string, online bool) (exitStatus interface{}, err error)

MigrateNode - Migrate a VM

func (*Client) MonitorCmd

func (c *Client) MonitorCmd(vmr *VmRef, command string) (monitorRes map[string]interface{}, err error)

func (*Client) MoveQemuDisk

func (c *Client) MoveQemuDisk(vmr *VmRef, disk string, storage string) (exitStatus interface{}, err error)

func (*Client) NextId

func (c *Client) NextId() (id int, err error)

NextId - Get next free VMID

func (*Client) ResetVm

func (c *Client) ResetVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) ResizeQemuDisk

func (c *Client) ResizeQemuDisk(vmr *VmRef, disk string, moreSizeGB int) (exitStatus interface{}, err error)

func (*Client) ResumeVm

func (c *Client) ResumeVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) RollbackQemuVm

func (c *Client) RollbackQemuVm(vmr *VmRef, snapshot string) (exitStatus string, err error)

func (*Client) Sendkey

func (c *Client) Sendkey(vmr *VmRef, qmKey string) error

func (*Client) SetLxcConfig

func (c *Client) SetLxcConfig(vmr *VmRef, vmParams map[string]interface{}) (exitStatus interface{}, err error)

SetLxcConfig - send config options

func (*Client) SetVmConfig

func (c *Client) SetVmConfig(vmr *VmRef, vmParams map[string]interface{}) (exitStatus interface{}, err error)

SetVmConfig - send config options

func (*Client) ShutdownVm

func (c *Client) ShutdownVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) StartVm

func (c *Client) StartVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) StatusChangeVm

func (c *Client) StatusChangeVm(vmr *VmRef, setStatus string) (exitStatus string, err error)

func (*Client) StopVm

func (c *Client) StopVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) SuspendVm

func (c *Client) SuspendVm(vmr *VmRef) (exitStatus string, err error)

func (*Client) UpdateVMHA

func (c *Client) UpdateVMHA(vmr *VmRef, haState string) (exitStatus interface{}, err error)

func (*Client) UpdateVMPool

func (c *Client) UpdateVMPool(vmr *VmRef, pool string) (exitStatus interface{}, err error)

func (*Client) Upload

func (c *Client) Upload(node string, storage string, contentType string, filename string, file io.Reader) error

func (*Client) VMIdExists

func (c *Client) VMIdExists(vmID int) (id int, err error)

VMIdExists - If you pass an VMID that exists it will raise an error otherwise it will return the vmID

func (*Client) WaitForCompletion

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

WaitForCompletion - poll the API for task completion

type ConfigQemu

type ConfigQemu struct {
	VmID         int         `json:"vmid"`
	Name         string      `json:"name"`
	Description  string      `json:"desc"`
	Pool         string      `json:"pool,omitempty"`
	Bios         string      `json:"bios"`
	Onboot       bool        `json:"onboot"`
	Agent        int         `json:"agent"`
	Memory       int         `json:"memory"`
	Balloon      int         `json:"balloon"`
	QemuOs       string      `json:"os"`
	QemuCores    int         `json:"cores"`
	QemuSockets  int         `json:"sockets"`
	QemuVcpus    int         `json:"vcpus"`
	QemuCpu      string      `json:"cpu"`
	QemuNuma     bool        `json:"numa"`
	Hotplug      string      `json:"hotplug"`
	QemuIso      string      `json:"iso"`
	FullClone    *int        `json:"fullclone"`
	Boot         string      `json:"boot"`
	BootDisk     string      `json:"bootdisk,omitempty"`
	Scsihw       string      `json:"scsihw,omitempty"`
	QemuDisks    QemuDevices `json:"disk"`
	QemuVga      QemuDevice  `json:"vga,omitempty"`
	QemuNetworks QemuDevices `json:"network"`
	QemuSerials  QemuDevices `json:"serial,omitempty"`
	HaState      string      `json:"hastate,omitempty"`

	// Deprecated single disk.
	DiskSize    float64 `json:"diskGB"`
	Storage     string  `json:"storage"`
	StorageType string  `json:"storageType"` // virtio|scsi (cloud-init defaults to scsi)

	// Deprecated single nic.
	QemuNicModel string `json:"nic"`
	QemuBrige    string `json:"bridge"`
	QemuVlanTag  int    `json:"vlan"`
	QemuMacAddr  string `json:"mac"`

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

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

	// arrays are hard, support 3 interfaces for now
	Ipconfig0 string `json:"ipconfig0"`
	Ipconfig1 string `json:"ipconfig1"`
	Ipconfig2 string `json:"ipconfig2"`
}

ConfigQemu - Proxmox API QEMU options

func NewConfigQemuFromApi

func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err error)

func NewConfigQemuFromJson

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

func (ConfigQemu) CloneVm

func (config ConfigQemu) CloneVm(sourceVmr *VmRef, vmr *VmRef, client *Client) (err error)

CloneVm Example: Request

nodes/proxmox1-xx/qemu/1012/clone

newid:145 name:tf-clone1 target:proxmox1-xx full:1 storage:xxx

func (ConfigQemu) CreateQemuDisksParams

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

Create parameters for each disk.

func (ConfigQemu) CreateQemuNetworksParams

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

Create parameters for each Nic device.

func (ConfigQemu) CreateQemuSerialsParams

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

Create parameters for serial interface

func (ConfigQemu) CreateVm

func (config ConfigQemu) CreateVm(vmr *VmRef, client *Client) (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) String

func (c ConfigQemu) String() string

func (ConfigQemu) UpdateConfig

func (config ConfigQemu) UpdateConfig(vmr *VmRef, client *Client) (err error)

type QemuDevice

type QemuDevice map[string]interface{}

func ParseConf

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

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

type QemuDeviceParam

type QemuDeviceParam []string

type QemuDevices

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

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, otp 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 VmRef

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

VmRef - virtual machine ref parts map[type:qemu node:proxmox1-xx id:qemu/132 diskread:5.57424738e+08 disk:0 netin:5.9297450593e+10 mem:3.3235968e+09 uptime:1.4567097e+07 vmid:132 template:0 maxcpu:2 netout:6.053310416e+09 maxdisk:3.4359738368e+10 maxmem:8.592031744e+09 diskwrite:1.49663619584e+12 status:running cpu:0.00386980694947209 name:appt-app1-dev.xxx.xx]

func NewVmRef

func NewVmRef(vmId int) (vmr *VmRef)

func (*VmRef) GetVmType

func (vmr *VmRef) GetVmType() string

func (*VmRef) HaState

func (vmr *VmRef) HaState() string

func (*VmRef) Node

func (vmr *VmRef) Node() string

func (*VmRef) Pool

func (vmr *VmRef) Pool() string

func (*VmRef) SetNode

func (vmr *VmRef) SetNode(node string)

func (*VmRef) SetPool

func (vmr *VmRef) SetPool(pool string)

func (*VmRef) SetVmType

func (vmr *VmRef) SetVmType(vmType string)

func (*VmRef) VmId

func (vmr *VmRef) VmId() int

Jump to

Keyboard shortcuts

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