package module
v0.0.0-...-b06a42d Latest Latest

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

Go to latest
Published: Jun 1, 2020 License: BSD-3-Clause Imports: 18 Imported by: 0



PVE-Go is a go library for the Porxmox VE API.

The design is based on the Hetzner Clound API implementation: https://github.com/hetznercloud/hcloud-go




View Source
const (
	TaskTimeout             = 300
	TaskStatusCheckInterval = 2
	TaskExitStatusOK        = "OK"
	TaskStatusRunning       = "running"
	TaskStatusStopped       = "stopped"
View Source
const PVEScheme = "pve"


View Source
var (
	ErrPoolExists    = errors.New("pool already exists")
	ErrPoolNotExists = errors.New("pool does not exist")
View Source
var ErrInvalidPVEURL = errors.New("invalid pve url scheme")
View Source
var ErrServerNotFound = errors.New("server not found")
View Source
var HTTPErr = errors.New("http error")


func MakePoolName

func MakePoolName(namespace, name string) string

func MarshalUserData

func MarshalUserData(u *UserData) ([]byte, error)

func NewURL

func NewURL(node, id string) string

func ParseURL

func ParseURL(s string) (node, id string, err error)


type APTConfig

type APTConfig struct {
	Sources map[string]APTSource

type APTSource

type APTSource struct {
	Arches    string `yaml:"arches,omitempty"`
	Source    string `yaml:"source"`
	Keyserver string `yaml:"keyserver"`
	Keyid     string `yaml:"keyid"`

type Client

type Client struct {

	Server ServerClient
	Task   TaskClient
	Pool   PoolClient
	Node   NodeClient
	// contains filtered or unexported fields

func NewClient

func NewClient(options ...ClientOption) *Client

func (*Client) Auth

func (c *Client) Auth() (err error)

func (*Client) Do

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

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

type ClientOption

type ClientOption func(*Client)

func WithCredentials

func WithCredentials(username, password string) ClientOption

func WithDebugWriter

func WithDebugWriter(debugWriter io.Writer) ClientOption

func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

func WithInsecureClient

func WithInsecureClient(insecure bool) ClientOption

type File

type File struct {
	Content     string `yaml:"content"`
	Path        string `yaml:"path"`
	Owner       string `yaml:"owner,omitempty"`
	Permissions string `yaml:"permissions,omitempty"`

type IPConfig

type IPConfig struct {
	IPv4CIDR    string
	IPv4Gateway string
	IPv6CIDR    string
	IPv6Gateway string
	MTU         string

func (*IPConfig) String

func (c *IPConfig) String() string

type IPConfigs

type IPConfigs []*IPConfig

func (IPConfigs) Get

func (c IPConfigs) Get(index int) *IPConfig

type NTP

type NTP struct {
	Servers []string `yaml:"servers,omitempty"`
	Enabled *bool    `yaml:"enabled,omitempty"`

type Nameserver

type Nameserver []string

func (Nameserver) String

func (n Nameserver) String() string

type NetworkDevice

type NetworkDevice struct {
	Type       string
	MACAddress string
	Bridge     string

func (*NetworkDevice) String

func (n *NetworkDevice) String() string

type NetworkDevices

type NetworkDevices []*NetworkDevice

func (NetworkDevices) Get

func (c NetworkDevices) Get(index int) *NetworkDevice

type Node

type Node struct {
	Name   string     `json:"node"`
	Status NodeStatus `json:"status"`

type NodeClient

type NodeClient struct {
	// contains filtered or unexported fields

func (*NodeClient) FindServer

func (c *NodeClient) FindServer(ctx context.Context, name, id string) (s *Server, err error)

func (*NodeClient) FindServerByID

func (c *NodeClient) FindServerByID(ctx context.Context, id string) (s *Server, err error)

func (*NodeClient) FindServerByName

func (c *NodeClient) FindServerByName(ctx context.Context, name string) (s *Server, err error)

func (*NodeClient) FindServerByURL

func (c *NodeClient) FindServerByURL(ctx context.Context, url string) (s *Server, err error)

func (*NodeClient) List

func (c *NodeClient) List(ctx context.Context) (nl NodeList, err error)

func (*NodeClient) ListServers

func (c *NodeClient) ListServers(ctx context.Context, n *Node) (sl ServerList, err error)

type NodeList

type NodeList []*Node

type NodeStatus

type NodeStatus string
const (
	NodeStatusOnline  NodeStatus = "online"
	NodeStatusOffline NodeStatus = "offline"
	NodeStatusUnknown NodeStatus = "unknown"

type OnTaskChange

type OnTaskChange func(t *Task)

type PoolClient

type PoolClient struct {
	// contains filtered or unexported fields

func (*PoolClient) Create

func (c *PoolClient) Create(ctx context.Context, name string) (err error)

func (*PoolClient) Delete

func (c *PoolClient) Delete(ctx context.Context, name string) (err error)

type Resources

type Resources struct {
	Memory       int64
	Cores        int64
	BootDisk     string
	BootDiskSize string

type Server

type Server struct {
	ID           string `json:"vmid"`
	Name         string `json:"name"`
	Node         string
	Status       ServerStatus `json:"status"`
	Resources    Resources
	NetDevices   NetworkDevices
	IPConfig     IPConfigs
	Nameserver   Nameserver
	SearchDomain string
	UserData     *UserData

func (*Server) InstanceID

func (s *Server) InstanceID() string

func (*Server) String

func (s *Server) String() string

type ServerClient

type ServerClient struct {
	// contains filtered or unexported fields

func (*ServerClient) CreateFromTemplate

func (c *ServerClient) CreateFromTemplate(ctx context.Context, opts ServerTemplateOpts) (t *Task, url string, err error)

func (*ServerClient) Delete

func (c *ServerClient) Delete(ctx context.Context, s *Server, f OnTaskChange) (t *Task, err error)

func (*ServerClient) GetByURL

func (c *ServerClient) GetByURL(ctx context.Context, url string) (s *Server, err error)

func (*ServerClient) GetStatus

func (c *ServerClient) GetStatus(ctx context.Context, s *Server, lock *string) (err error)

func (*ServerClient) NextID

func (c *ServerClient) NextID(ctx context.Context) (id string, err error)

func (*ServerClient) Reboot

func (c *ServerClient) Reboot(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Reset

func (c *ServerClient) Reset(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Resume

func (c *ServerClient) Resume(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Shutdown

func (c *ServerClient) Shutdown(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Start

func (c *ServerClient) Start(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Stop

func (c *ServerClient) Stop(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Suspend

func (c *ServerClient) Suspend(ctx context.Context, s *Server) (t *Task, err error)

func (*ServerClient) Update

func (c *ServerClient) Update(ctx context.Context, s *Server) (err error)

type ServerList

type ServerList []*Server

type ServerStatus

type ServerStatus string
const (
	ServerStatusInitializing ServerStatus = "initializing"
	ServerStatusStarting     ServerStatus = "starting"
	ServerStatusStopping     ServerStatus = "stopping"
	ServerStatusRebooting    ServerStatus = "rebooting"
	ServerStatusRunning      ServerStatus = "running"
	ServerStatusStopped      ServerStatus = "stopped"
	ServerStatusDeleting     ServerStatus = "deleting"
	ServerStatusUnknown      ServerStatus = "unknown"

	ServerStatusBackup      ServerStatus = "backup"
	ServerStatusMigrating   ServerStatus = "migrating"
	ServerStatusSnapshoting ServerStatus = "snapshoting"
	ServerStatusRollback    ServerStatus = "rollback"
	ServerStatusSespending  ServerStatus = "suspending"
	ServerStatusSespended   ServerStatus = "suspended"
	ServerStatusResuming    ServerStatus = "resuming"

func ServerStatusFromLock

func ServerStatusFromLock(status, lock string) ServerStatus

func ServerStatusFromTask

func ServerStatusFromTask(t *Task) ServerStatus

type ServerTemplateOpts

type ServerTemplateOpts struct {
	Name          string
	TemplateURL   string
	Pool          string
	TargetStorage string
	TargetNode    string

func (ServerTemplateOpts) Validate

func (o ServerTemplateOpts) Validate() error

type Task

type Task struct {
	ID         string `json:"upid"`
	Type       string `json:"type"`
	Status     string `json:"status"`
	Exitstatus string `json:"exitstatus"`

type TaskClient

type TaskClient struct {
	// contains filtered or unexported fields

func (*TaskClient) Get

func (c *TaskClient) Get(ctx context.Context, taskid string) (t *Task, err error)

func (*TaskClient) MustGet

func (c *TaskClient) MustGet(ctx context.Context, taskid string) (t *Task)

func (*TaskClient) Wait

func (c *TaskClient) Wait(ctx context.Context, t *Task, f OnTaskChange) error

type User

type User struct {
	Name              string   `yaml:"name"`
	Gecos             *string  `yaml:"gecos,omitempty"`
	Groups            *string  `yaml:"groups,omitempty"`
	HomeDir           *string  `yaml:"homedir,omitempty"`
	Inactive          *bool    `yaml:"inactive,omitempty"`
	Shell             *string  `yaml:"shell,omitempty"`
	Passwd            *string  `yaml:"passwd,omitempty"`
	PrimaryGroup      *string  `yaml:"primary_group,omitempty"`
	LockPassword      *bool    `yaml:"lock_passwd,omitempty"`
	Sudo              *string  `yaml:"sudo,omitempty"`
	SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`

type UserData

type UserData struct {
	Hostname          string     `yaml:"hostname"`
	ManageEtcHosts    bool       `yaml:"manage_etc_hosts,omitempty"`
	SSHAuthorizedKeys []string   `yaml:"ssh_authorized_keys,omitempty"`
	PackageUpdate     bool       `yaml:"package_update,omitempty"`
	PackageUpgrade    bool       `yaml:"package_upgrade,omitempty"`
	APT               APTConfig  `yaml:"apt,omitempty"`
	NTP               NTP        `yaml:"ntp,omitempty"`
	Users             []User     `yaml:"users,omitempty"`
	Packages          [][]string `yaml:"packages,omitempty"`
	Runcmd            []string   `yaml:"runcmd,omitempty"`
	FinalMessage      string     `yaml:"final_message,omitempty"`
	WriteFiles        []File     `yaml:"write_files,omitempty"`

func UnmarshalUserData

func UnmarshalUserData(b []byte) (u *UserData, err error)

func (*UserData) String

func (u *UserData) String() (s string, err error)

Jump to

Keyboard shortcuts

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