proxmoxve

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Proxmox Virtual Environment Provisioner

Index

Constants

View Source
const CloneTimeout = 5 * time.Minute
View Source
const DEFAULT_CPU_OVER_COMMITMENT_RATIO = 4
View Source
const DEFAULT_SYSTEM_MEM = 4096

4096MiB = 4GiB

View Source
const DeleteTimeout = 5 * time.Minute
View Source
const PveSpecType models.SpecType = "proxmox-ve"
View Source
const ScheduleTimeout = 5 * time.Minute
View Source
const StartTimeout = 5 * time.Minute

Variables

View Source
var FullError = errors.Errorf("full")

FullError means failed to allocate resources.

View Source
var GlobalScheduler = &Scheduler{}

TODO: 複数のクラスタに対応できない

View Source
var PveCloneSem = semaphore.NewWeighted(1)

TODO 複数のprovisionerが同時にcloneをすると、IDが衝突してしまう。 これを回避するため、同時にclone操作をするのを制限した。

View Source
var PveUpdateSchedulerOnce sync.Once

TODO タスクが動いている最中、特にReserve()とCreate()の間にschedulerStatusが実行されてしまうと、 確保済み扱いのCPUやメモリがカウントされない。このため、リソース開放時にpanicする。 これを回避するために Scheduler.UpdateNodes() の実行は1回限りに制限する。

Functions

This section is empty.

Types

type Node

type Node struct {
	NodeID NodeID

	// Number of physical CPUs.
	PCPU int
	// Information of virtual CPUs.
	VCPU struct {
		// Maximum number of virtual CPUs.
		// If you need disable the maximum limit of virtual CPUs, set Max=0.
		Max int
		// Number of used virtual CPUs by running VMs.
		Used int
		// Number of virtual CPUs by VMs in preparing.
		Reserved int
	}

	// Amount of physical memory size (MiB).
	PMem int
	// Information of virtual memory.
	VMem struct {
		// Amount of memory size (MiB) for system.
		// This memory is used by Proxmox VE system and margin for prevent out-of-memory.
		// Default: DEFAULT_SYSTEM_MEM
		System int
		// Amount of used memory size (MiB) by already running VMs.
		// This value is the total of memory size each running VMs.
		Used int
		// Amount of reserved memory size (MiB).
		// This value is the total of memory size each VMs in preparing.
		Reserved int
	}
}

func (*Node) String added in v0.2.0

func (n *Node) String() string

type PveInfraConfig

type PveInfraConfig struct {
	PveSpec *PveSpec
	VMs     map[string][]VMConfig
	// contains filtered or unexported fields
}

func NewPveInfraConfig

func NewPveInfraConfig(spec *PveSpec) *PveInfraConfig

func (*PveInfraConfig) AddVM

func (c *PveInfraConfig) AddVM(name string, vm VMConfig)

func (*PveInfraConfig) Spec

func (c *PveInfraConfig) Spec() models.Spec

func (*PveInfraConfig) String

func (c *PveInfraConfig) String() string

type PveProvisioner

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

func (*PveProvisioner) Config

func (p *PveProvisioner) Config() models.InfraConfig

func (*PveProvisioner) Create

func (p *PveProvisioner) Create() error

Create starts all VMs of defined by PveSpec.

func (*PveProvisioner) Delete

func (p *PveProvisioner) Delete() error

Delete deletes all resources of defined by PveSpec.

func (*PveProvisioner) Reserve added in v0.2.0

func (p *PveProvisioner) Reserve() error

Reserve() reserves all resources (CPU, memory, storage, etc) of defined by PveSpec.

func (*PveProvisioner) ScriptExecutor

func (p *PveProvisioner) ScriptExecutor(scriptType models.ScriptType) models.ScriptExecutor

func (*PveProvisioner) ScriptSets

func (p *PveProvisioner) ScriptSets() []*models.ScriptSet

func (*PveProvisioner) Spec

func (p *PveProvisioner) Spec() models.Spec

type PveSpec

type PveSpec struct {
	// Identifier of the spec.
	Name string
	// Proxmox VE account settings..
	Proxmox struct {
		// URL of the Proxmox VE API server.
		// Example: https://pve.local:8006
		Address string
		// Login information.
		Account struct {
			User     string
			Password string
		}
		// Fingerprint of the Proxmox VE API server.
		// If you need the server certificate pinning to make it more secure.
		Fingerprint string
	}
	// Addresses to assign to VMs.
	AddressPools []*struct {
		StartAddress string `yaml:"start_address"`
		EndAddress   string `yaml:"end_address"`
		CIDR         int
		Gateway      string
	} `yaml:"address_pools"`
	// User information.
	// This user will create by cloud-init at VM start-up.
	User struct {
		User string
		// todo: password is not used.
		Password     string
		SSHPublicKey string `yaml:"ssh_public_key"`
	}
	VMs map[string]*PveVM
}

func (*PveSpec) LoadDefault added in v0.3.0

func (s *PveSpec) LoadDefault(defaultSpec models.Spec) error

func (*PveSpec) String

func (s *PveSpec) String() string

func (*PveSpec) Type

func (s *PveSpec) Type() models.SpecType

func (*PveSpec) Validate added in v0.3.0

func (s *PveSpec) Validate() error

func (*PveSpec) ValidateDefault added in v0.3.0

func (s *PveSpec) ValidateDefault() error

type PveVM

type PveVM struct {
	// Template name.
	Template string
	// Pool name to which the VM belongs.
	Pool string
	// Number of VMs.
	Nodes int
	// Number of processors.
	Processors int
	// RAM size (MiB).
	MemorySize int `yaml:"memory_size"`
	// Minimal storage size (GiB).
	// The storage may be large than specified size.
	StorageSize int `yaml:"storage_size"`
	// Define tasks to execute on VMs.
	Scripts *config.ScriptConfigSet
}

type ScheduleTx

type ScheduleTx struct {
	S *Scheduler
	// contains filtered or unexported fields
}

func (*ScheduleTx) Commit

func (tx *ScheduleTx) Commit()

Commit allocates all reserved resources while this transaction.

func (*ScheduleTx) IsFinished

func (tx *ScheduleTx) IsFinished() bool

IsFinished returns true if already committed or reverted. Otherwise, it returns false.

func (*ScheduleTx) Revert

func (tx *ScheduleTx) Revert()

Revert releases all reserved resources while this transaction.

func (*ScheduleTx) Schedule

func (tx *ScheduleTx) Schedule(spec VMSpec) (NodeID, error)

Schedule decides best VM location and reserves it. The reserved resources are allocated or released when calling the Commit() or Revert().

func (*ScheduleTx) ScheduleWait added in v0.2.0

func (tx *ScheduleTx) ScheduleWait(ctx context.Context, spec VMSpec) (NodeID, error)

ScheduleWait waits for allocate resources and reserves it.

type Scheduler

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

func (*Scheduler) Cancel

func (s *Scheduler) Cancel(id NodeID, spec VMSpec)

Cancel releases reserved resources. You should call it when you need drops the reserved resources by Schedule().

func (*Scheduler) Free

func (s *Scheduler) Free(id NodeID, spec VMSpec)

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(spec VMSpec) (NodeID, error)

Schedule decides best VM location and reserves it. You should call the Use() or Cancel() after call it.

func (*Scheduler) Transaction

func (s *Scheduler) Transaction(fn func(tx *ScheduleTx) error) error

Transaction starts an transaction to allocate resources atomically.

func (*Scheduler) UpdateNodes

func (s *Scheduler) UpdateNodes(fn func() ([]*Node, error), updateReserved bool) error

UpdateNodes updates all nodes status. If updateReserved is true, Scheduler.nodes.VCPU.Reserved and Scheduler.nodes.VMem.Reserved parameters are updated.

func (*Scheduler) Use

func (s *Scheduler) Use(id NodeID, spec VMSpec)

Use notifies it to scheduler that specified VM started to running. We regards the reserved resources as in use. You should call Free() when release resources.

type VMConfig

type VMConfig struct {
	ID   NodeVMID
	IP   net.IP
	Spec VMSpec
}

type VMSpec

type VMSpec struct {
	// Number of processors
	Processors int
	// RAM size (MiB)
	Memory int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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