goproxmox

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2017 License: MIT Imports: 13 Imported by: 1

README

goproxmox

golang library for interaction with proxmox

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// Control panel username
	Username string

	// Control panel password
	Password string

	// Services used for communicating with the API
	Nodes NodesService
	VMs   QemuService
	// contains filtered or unexported fields
}

Client manages communication with proxmox API.

func NewClient

func NewClient(host, username, password string) *Client

NewClient returns a new proxmox API client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the API request completion callback

type ErrorResponse

type ErrorResponse struct {
	Success bool

	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"ResultMessage"`

	// ResultCode returned from the API
	ResultCode int `json:"ResultCode"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Node

type Node struct {
	Id      string  `json:"id"`
	Node    string  `json:"node"`
	Type    string  `json:"type"`
	Cpu     float64 `json:"cpu"`
	Mem     uint64  `json:"mem"`
	Disk    uint64  `json:"disk"`
	Maxcpu  int     `json:"maxcpu"`
	Maxmem  uint64  `json:"maxmem"`
	Maxdisk uint64  `json:"maxdisk"`
	Uptime  uint    `json:"uptime"`
	Level   string  `json:"level"`
}

type NodesService

type NodesService interface {
	GetNodes() ([]Node, error)
}

type NodesServiceOp

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

func (*NodesServiceOp) GetNodes

func (s *NodesServiceOp) GetNodes() ([]Node, error)

type QemuService

type QemuService interface {
	GetVMs(node string) ([]VM, error)
	GetVMCurrentStatus(node string, vmID string) (*VMStatus, error)
	StartVM(node string, vmID string) error
	StopVM(node string, vmID string) error
	ShutdownVM(node string, vmID string) error
	ResetVM(node string, vmID string) error
	SuspendVM(node string, vmID string) error
	ResumeVM(node string, vmID string) error
	CreateVM(node string, vmID string, options *VMCreateOptions) error
	DeleteVM(node string, vmID string) error
}

type QemuServiceOp

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

func (*QemuServiceOp) CreateVM

func (s *QemuServiceOp) CreateVM(node string, vmID string, options *VMCreateOptions) error

Create virtual machine.

func (*QemuServiceOp) DeleteVM

func (s *QemuServiceOp) DeleteVM(node string, vmID string) error

Create virtual machine.

func (*QemuServiceOp) GetVMCurrentStatus

func (s *QemuServiceOp) GetVMCurrentStatus(node string, vmID string) (*VMStatus, error)

Get virtual machine status.

func (*QemuServiceOp) GetVMs

func (s *QemuServiceOp) GetVMs(node string) ([]VM, error)

Virtual machine index (per node).

func (*QemuServiceOp) ResetVM

func (s *QemuServiceOp) ResetVM(node string, vmID string) error

Reset virtual machine.

func (*QemuServiceOp) ResumeVM

func (s *QemuServiceOp) ResumeVM(node string, vmID string) error

Resume virtual machine.

func (*QemuServiceOp) ShutdownVM

func (s *QemuServiceOp) ShutdownVM(node string, vmID string) error

Shutdown virtual machine. This is similar to pressing the power button on a physical machine. This will send an ACPI event for the guest OS, which should then proceed to a clean shutdown.

func (*QemuServiceOp) StartVM

func (s *QemuServiceOp) StartVM(node string, vmID string) error

Start virtual machine.

func (*QemuServiceOp) StopVM

func (s *QemuServiceOp) StopVM(node string, vmID string) error

Stop virtual machine. The qemu process will exit immediately. This is akin to pulling the power plug of a running computer and may damage the VM data.

func (*QemuServiceOp) SuspendVM

func (s *QemuServiceOp) SuspendVM(node string, vmID string) error

Suspend virtual machine.

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

type VM

type VM struct {
	VMID      int     `json:"vmid"`
	Name      string  `json:"name"`
	Status    string  `json:"status"`
	Pid       string  `json:"pid"`
	Template  string  `json:"template"`
	Cpu       float64 `json:"cpu"`
	Mem       int     `json:"mem"`
	Maxmem    int     `json:"maxmem"`
	Cpus      int     `json:"cpus"`
	Disk      int     `json:"disk"`
	Maxdisk   int     `json:"maxdisk"`
	Diskread  int     `json:"diskread"`
	Diskwrite int     `json:"diskwrite"`
	Uptime    int     `json:"uptime"`
	Netout    int     `json:"netout"`
	Netin     int     `json:"netin"`
}

type VMCreateOptions

type VMCreateOptions struct {
	VMID string `structs:"vmid"`
	Name string `structs:"name,omitempty"`
}

type VMStatus

type VMStatus struct {
	Name      string      `json:"name"`
	Status    string      `json:"status"`
	Qmpstatus string      `json:"qmpstatus"`
	Template  string      `json:"template"`
	Cpus      int         `json:"cpus"`
	Diskread  int         `json:"diskread"`
	Cpu       int         `json:"cpu"`
	Netin     int         `json:"netin"`
	Netout    int         `json:"netout"`
	Disk      int         `json:"disk"`
	Diskwrite int         `json:"diskwrite"`
	Maxdisk   int         `json:"maxdisk"`
	Maxmem    int         `json:"maxmem"`
	Ha        interface{} `json:"ha"`
	Uptime    int         `json:"uptime"`
	Pid       int         `json:"pid"`
	Mem       int         `json:"mem"`
}

Directories

Path Synopsis
internal
Package internal contains support packages for oauth2 package.
Package internal contains support packages for oauth2 package.

Jump to

Keyboard shortcuts

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