proxmox

package module
v0.0.0-...-0c9b8e2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2017 License: MIT Imports: 21 Imported by: 0

README

Proxmox Go Client

This is an partial implementation of Proxmox's REST API in Go.

It allows a client to provision VMs, LXC containers and storages.

It is in an unfinished state, released as opensource in the hopes that it helps someone out there in the world of hypervisors.

Documentation

Overview

Package proxmox implements the VMProvider and ContainerProvider methods It makes requests to the Proxmox VE on behalf of Raijin

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorJSON

func ErrorJSON(err error) string

ErrorJSON returns a string for use in http.Error

func HashPassword

func HashPassword(password string) string

HashPassword encrypts a plaintext string and returns the hashed version

func MustDecodeJSON

func MustDecodeJSON(body io.Reader, target interface{})

MustDecodeJSON receives a pointer to struct, and updates the struct values with the values from the JSON in the http request

func MustGetInt

func MustGetInt(r *http.Request, name string) int

MustGetInt will get an integer from ninjarouter URL or panic

func MustGetString

func MustGetString(r *http.Request, name string) string

MustGetString will get an string from ninjarouter URL or panic

func MustMarshalJSON

func MustMarshalJSON(input interface{}) []byte

MustMarshalJSON will return a byte array representation of a struct

func MustReadAll

func MustReadAll(r io.Reader) string

MustReadAll will read the response body as a string

Types

type AuthResponse

type AuthResponse struct {
	CSRFToken string `json:"csrfToken"`
	Ticket    string `json:"ticket"`
}

AuthResponse is the response from the Proxmox API container the CSRF token and ticket for authenticated requests

type AuthTicketResponse

type AuthTicketResponse struct {
	Data struct {
		Ticket              string `json:"ticket"`
		Username            string `json:"username"`
		CSRFPreventionToken string `json:"CSRFPreventionToken"`
	} `json:"data"`
}

AuthTicketResponse is the response from the Proxmox API after a successful auth

type Client

type Client struct {
	CSRFToken string
	Ticket    string
	// contains filtered or unexported fields
}

Client contains the state for the proxmox client

func New

func New(host, username, password string) (*Client, error)

New returns a new Proxmox client

func (*Client) ContainerAdd

func (c *Client) ContainerAdd(container *Resource) error

ContainerAdd runs the Add action for the Proxmox containers

func (*Client) ContainerConfig

func (c *Client) ContainerConfig(params *ContainerConfigRequest) (*ContainerConfig, error)

ContainerConfig returns the container config

func (*Client) ContainerCreate

func (c *Client) ContainerCreate(params *ContainerCreateRequest) error

ContainerCreate runs the Create action for the Proxmox containers

func (*Client) ContainerDelete

func (c *Client) ContainerDelete(node string, vmid int) error

ContainerDelete runs the Delete action for the Proxmox containers

func (*Client) ContainerResume

func (c *Client) ContainerResume(params *ContainerVMStatusRequest) error

ContainerResume will start the container

func (*Client) ContainerShutdown

func (c *Client) ContainerShutdown(params *ContainerVMStatusRequest) error

ContainerShutdown will shutdown the container

func (*Client) ContainerStart

func (c *Client) ContainerStart(params *ContainerVMStatusRequest) error

ContainerStart will start the container

func (*Client) ContainerStop

func (c *Client) ContainerStop(params *ContainerVMStatusRequest) error

ContainerStop will stop the container

func (*Client) ContainerUpdate

func (c *Client) ContainerUpdate(container *Resource) error

ContainerUpdate runs the Update action for the Proxmox containers

func (*Client) ISOList

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

ISOList returns a list of ISOs

func (*Client) NextID

func (c *Client) NextID() (int, error)

NextID returns the next available VMID

func (*Client) NodeStatus

func (c *Client) NodeStatus(node string) (*NodeStatus, error)

NodeStatus returns the Node's RAM, CPU and storage

func (*Client) PickNode

func (c *Client) PickNode() (string, error)

PickNode returns node with the least provisioned memory

func (*Client) ResourceList

func (c *Client) ResourceList() (Resources, error)

ResourceList runs the List action for the Proxmox resources

func (*Client) SignIn

func (c *Client) SignIn() error

SignIn will signin the user and update the embedded client with the ticket

func (*Client) StorageCreate

func (c *Client) StorageCreate(vmid, size string) error

StorageCreate will create a storage for a VM

func (*Client) TemplateList

func (c *Client) TemplateList(node string) ([]*Template, error)

TemplateList returns a list of templates

func (*Client) VerifyTicket

func (c *Client) VerifyTicket() (bool, error)

VerifyTicket confirms that the currently held ticket in the client is valid

type ContainerConfig

type ContainerConfig struct {
	Memory      int    `json:"memory"`
	Cpulimit    string `json:"cpulimit"`
	Digest      string `json:"digest"`
	Cores       int    `json:"cores"`
	Ostype      string `json:"ostype"`
	Rootfs      string `json:"rootfs"`
	Hostname    string `json:"hostname"`
	Arch        string `json:"arch"`
	Description string `json:"description"`
	Swap        int    `json:"swap"`
	Net0        string `json:"net0"`
}

ContainerConfig is the response from the Proxmox API for a VM's configuration

type ContainerConfigRequest

type ContainerConfigRequest struct {
	Node string
	VMID int
}

ContainerConfigRequest is a request to the Proxmox API for a VM's configuration

type ContainerConfigResponse

type ContainerConfigResponse struct {
	Data *ContainerConfig `json:"data"`
}

ContainerConfigResponse is the response from the Proxmox API for a VM's configuration

type ContainerCreateRequest

type ContainerCreateRequest struct {
	MAC             string
	Template        *ParsedTemplate
	Node            string
	VMID            int
	CPUCores        int
	Memory          int
	StorageCapacity int
	StorageID       string
	SSHPublicKey    string
	Password        string
	HostName        string
	IPAddress       string
}

ContainerCreateRequest is a request to the Proxmox API to create a container

type ContainerVMStatusRequest

type ContainerVMStatusRequest struct {
	Node      string
	VMID      int
	StorageID string
}

ContainerVMStatusRequest is the request for the Proxmox API to modify a container or VM's status

type Error

type Error struct {
	Message string
}

Error is a struct with which we can marshal into JSON for a HTTP response

type ISO

type ISO struct {
	Content string `json:"content"`
	Volid   string `json:"volid"`
	Format  string `json:"format"`
	Size    int    `json:"size"`
}

ISO is the response from the proxmox API for ISO content in a storage

type ISOListResponse

type ISOListResponse struct {
	Data []*ISO `json:"data"`
}

ISOListResponse is a list of ISOs from the Proxmox API

type NextIDResponse

type NextIDResponse struct {
	Data string `json:"data"`
}

NextIDResponse is the next available VMID from the Proxmox API

type NodeStatus

type NodeStatus struct {
	CPU     int `json:"cpu"`
	Cpuinfo struct {
		Cpus    int    `json:"cpus"`
		Hvm     int    `json:"hvm"`
		Mhz     string `json:"mhz"`
		Model   string `json:"model"`
		Sockets int    `json:"sockets"`
		UserHz  int    `json:"user_hz"`
	} `json:"cpuinfo"`
	Idle int `json:"idle"`
	Ksm  struct {
		Shared int `json:"shared"`
	} `json:"ksm"`
	Kversion string   `json:"kversion"`
	Loadavg  []string `json:"loadavg"`
	Memory   struct {
		Free  int64 `json:"free"`
		Total int64 `json:"total"`
		Used  int   `json:"used"`
	} `json:"memory"`
	Pveversion string `json:"pveversion"`
	Rootfs     struct {
		Avail int64 `json:"avail"`
		Free  int64 `json:"free"`
		Total int64 `json:"total"`
		Used  int64 `json:"used"`
	} `json:"rootfs"`
	Swap struct {
		Free  int64 `json:"free"`
		Total int64 `json:"total"`
		Used  int   `json:"used"`
	} `json:"swap"`
	Uptime int `json:"uptime"`
	Wait   int `json:"wait"`
}

NodeStatus is the response from the Proxmox API

type NodeStatusResponse

type NodeStatusResponse struct {
	Data *NodeStatus `json:"data"`
}

NodeStatusResponse is the response from the Proxmox API for a node's status

type ParsedTemplate

type ParsedTemplate struct {
	OS         string
	OSVersion  string
	Name       string
	OSVersion2 string
	Arch       string
	Extension  string
}

ParsedTemplate is the result of magical regex on a filepath to get template info

func (*ParsedTemplate) String

func (pt *ParsedTemplate) String() string

String returns a string version of the template struct

type RaijinTemplate

type RaijinTemplate struct {
	OS         string `json:"os"`
	OSVersion  string `json:"osVersion"`
	Name       string `json:"Name"`
	OSVersion2 string `json:"osVersion2"`
	Arch       string `json:"arch"`
	Extension  string `json:"extension"`
}

RaijinTemplate is the values needed to create a container based on a template

func ParseTemplate

func ParseTemplate(templateStr string) (*RaijinTemplate, error)

ParseTemplate will convert a proxmox template string into a struct

type Resource

type Resource struct {
	CPU       float64 `json:"cpu,omitempty"`
	Disk      int     `json:"disk,omitempty"`
	Diskread  int     `json:"diskread,omitempty"`
	Diskwrite int     `json:"diskwrite,omitempty"`
	ID        string  `json:"id"`
	Maxcpu    int     `json:"maxcpu,omitempty"`
	Maxdisk   int64   `json:"maxdisk,omitempty"`
	Maxmem    int     `json:"maxmem,omitempty"`
	Mem       int     `json:"mem,omitempty"`
	Name      string  `json:"name,omitempty"`
	Netin     int     `json:"netin,omitempty"`
	Netout    int     `json:"netout,omitempty"`
	Node      string  `json:"node"`
	Status    string  `json:"status,omitempty"`
	Template  int     `json:"template,omitempty"`
	Type      string  `json:"type"`
	Uptime    int     `json:"uptime,omitempty"`
	Vmid      int     `json:"vmid,omitempty"`
	Level     string  `json:"level,omitempty"`
	Storage   string  `json:"storage,omitempty"`
}

Resource is a VM, container or storage on proxmox

type Resources

type Resources []*Resource

Resources is a list of resources from the Proxmox API

func (Resources) Containers

func (pr Resources) Containers() []*Resource

Containers returns a slice of containers from the Proxmox API

func (Resources) GetNodeFromVMID

func (pr Resources) GetNodeFromVMID(vmid int) (string, error)

GetNodeFromVMID will return a VM's node

func (Resources) Nodes

func (pr Resources) Nodes() []*Resource

Nodes returns a slice of nodes from the Proxmox API

func (Resources) Storages

func (pr Resources) Storages() []*Resource

Storages returns a slice of storages from the Proxmox API

func (Resources) Templates

func (pr Resources) Templates() []*Resource

Templates returns a slice of templates from the Proxmox API

func (Resources) VMs

func (pr Resources) VMs() []*Resource

VMs returns a slice of VMs from the Proxmox API

type ResourcesResponse

type ResourcesResponse struct {
	Data []*Resource `json:"data"`
}

ResourcesResponse is a list of Resources from the Proxmox API

type Service

type Service interface {
	SignIn() error
	VerifyTicket() (bool, error)
	ResourceList() (Resources, error)

	PickNode() (string, error)

	ContainerCreate(*ContainerCreateRequest) error
	ContainerStop(*ContainerVMStatusRequest) error
	ContainerStart(*ContainerVMStatusRequest) error
	ContainerShutdown(*ContainerVMStatusRequest) error
	ContainerResume(*ContainerVMStatusRequest) error
	ContainerDelete(node string, vmid int) error
	ContainerConfig(*ContainerConfigRequest) (*ContainerConfig, error)

	TemplateList(node string) ([]*Template, error)
	ISOList(node string) ([]string, error)

	NextID() (int, error)
}

Service contains the methods that the proxmox client provides

type Template

type Template struct {
	Content string `json:"content"`
	Volid   string `json:"volid"`
	Format  string `json:"format"`
	Size    int    `json:"size"`
}

Template is the values needed to create a container based on a template

type TemplateListResponse

type TemplateListResponse struct {
	Data []*Template `json:"data"`
}

TemplateListResponse is a list of Templates

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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