virt_utils

package
v0.0.0-...-ba78406 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusRunning = "Running"
	StatusCreated = "Created"
)
View Source
const (
	KindAll     = "all"
	KindVm      = "vm"
	KindImage   = "image"
	KindNetwork = "network"
)
View Source
const (
	KindImageUrl = "url"
)
View Source
const (
	KindNetworkLocal = "local"
)
View Source
const (
	KindVmQemu = "qemu"
)

Variables

This section is empty.

Functions

func AddIntToIp

func AddIntToIp(ip net.IP, value uint) net.IP

func CompareIp

func CompareIp(ip1 net.IP, ip2 net.IP) int

CompareIp compare ip1, ip2 ip1が大きければ1, ip2が大きければ-1, 同じなら0を返す

func GenerateRandomMac

func GenerateRandomMac() (string, error)

func GenerateUniqueRandomMac

func GenerateUniqueRandomMac(macMap map[string]bool, limit int) (string, error)

func IncrementIp

func IncrementIp(ip net.IP)

func Ip2Int

func Ip2Int(ip net.IP) *big.Int

Types

type GetResult

type GetResult struct {
	Vms      VmResources
	Networks NetworkResources
	Images   ImageResources
}

func (*GetResult) Output

func (self *GetResult) Output(format string)

type Image

type Image struct {
	ImageSpec
	Id        uint       `gorm:"not null;primaryKey;autoIncrement;"`
	DeletedAt *time.Time `gorm:"uniqueIndex:udx_name;"`
	SpecStr   string     `gorm:"not null;column:spec" json:"-"`
}

type ImageDetectSpec

type ImageDetectSpec struct {
	Name string
}

type ImageResource

type ImageResource struct {
	Kind string
	Spec Image
}

type ImageResources

type ImageResources []ImageResource

func (ImageResources) String

func (self ImageResources) String() string

type ImageSpec

type ImageSpec struct {
	Name      string      `gorm:"not null;uniqueIndex:udx_name;" validate:"required"`
	Namespace string      `gorm:"not null;uniqueIndex:udx_name;" validate:"required"`
	Kind      string      `gorm:"not null;" validate:"required,oneof=url"`
	Spec      interface{} `gorm:"-"`
}

type ImageUrlSpec

type ImageUrlSpec struct {
	Url        string `gorm:"not null;" validate:"required"`
	PullPolicy string `gorm:"not null;" validate:"required,oneof=IfNotPresent"`
}

type Network

type Network struct {
	NetworkSpec
	Id        uint       `gorm:"not null;primaryKey;autoIncrement;"`
	DeletedAt *time.Time `gorm:"uniqueIndex:udx_name;"`
	SpecStr   string     `gorm:"not null;column:spec" json:"-"`

	Priority int `gorm:"-" json:"-"`
	// contains filtered or unexported fields
}

type NetworkDetectSpec

type NetworkDetectSpec struct {
	Name                string
	CandidateNetworkIds []uint `json:"-"`
}

type NetworkLocalSpec

type NetworkLocalSpec struct {
	Resolvers []Resolver `gorm:"-"`
	Nat       NetworkNat `gorm:"-"`
}

type NetworkNat

type NetworkNat struct {
	Enable bool
	Ports  string
}

type NetworkPort

type NetworkPort struct {
	NetworkId uint   `gorm:"not null;"`
	VmId      uint   `gorm:"not null;"`
	Ip        string `gorm:"not null;"`
	Mac       string `gorm:"not null;"`
}

type NetworkResource

type NetworkResource struct {
	Kind string
	Spec Network
}

type NetworkResources

type NetworkResources []NetworkResource

func (NetworkResources) String

func (self NetworkResources) String() string

type NetworkSpec

type NetworkSpec struct {
	Name      string      `gorm:"not null;uniqueIndex:udx_name;" validate:"required"`
	Namespace string      `gorm:"not null;uniqueIndex:udx_name;" validate:"required"`
	Kind      string      `gorm:"not null;"`
	Subnet    string      `gorm:"not null;"`
	StartIp   string      `gorm:"not null;"`
	EndIp     string      `gorm:"not null;"`
	Gateway   string      `gorm:"not null;"`
	Spec      interface{} `gorm:"-"`
}

type ParsedNetwork

type ParsedNetwork struct {
	Subnet       *net.IPNet
	Gateway      net.IP
	StartIp      net.IP
	EndIp        net.IP
	AvailableIps uint64
}

func ParseNetwork

func ParseNetwork(spec *NetworkSpec) (network *ParsedNetwork, err error)

type Resolver

type Resolver struct {
	Resolver string
}

type Resource

type Resource struct {
	Kind string `validate:"required"`
	Name string `validate:"required"`
	Spec interface{}
}

type SystemdService

type SystemdService struct {
	Restart string `oneof=always`
}

type VirtController

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

func NewVirtContoller

func NewVirtContoller(conf *VirtControllerConfig) (virtController *VirtController)

func (*VirtController) AssignNetworkPorts

func (self *VirtController) AssignNetworkPorts(tctx *logger.TraceContext, tx *gorm.DB,
	vm *Vm, detectSpecs []NetworkDetectSpec) (assignedPorts []NetworkPort, err error)

func (*VirtController) BootstrapImage

func (self *VirtController) BootstrapImage(tctx *logger.TraceContext) (err error)

func (*VirtController) BootstrapNetwork

func (self *VirtController) BootstrapNetwork(tctx *logger.TraceContext) (err error)

func (*VirtController) BootstrapVm

func (self *VirtController) BootstrapVm(tctx *logger.TraceContext) (err error)

func (*VirtController) Create

func (self *VirtController) Create(tctx *logger.TraceContext, resourcesBytes [][]byte) (err error)

func (*VirtController) CreateOrUpdateImage

func (self *VirtController) CreateOrUpdateImage(tctx *logger.TraceContext, spec *ImageSpec) (err error)

func (*VirtController) CreateOrUpdateNetwork

func (self *VirtController) CreateOrUpdateNetwork(tctx *logger.TraceContext, spec *NetworkSpec) (err error)

func (*VirtController) CreateOrUpdateVm

func (self *VirtController) CreateOrUpdateVm(tctx *logger.TraceContext, spec *VmSpec) (err error)

func (*VirtController) DetectImage

func (self *VirtController) DetectImage(tctx *logger.TraceContext, tx *gorm.DB,
	detectSpec *ImageDetectSpec) (image *Image, err error)

func (*VirtController) Get

func (self *VirtController) Get(tctx *logger.TraceContext, kind string, args []string) (result *GetResult, err error)

func (*VirtController) GetImage

func (self *VirtController) GetImage(name string) (image *Image, err error)

func (*VirtController) GetImageResources

func (self *VirtController) GetImageResources(tctx *logger.TraceContext, names []string) (imageResources ImageResources, err error)

func (*VirtController) GetNetwork

func (self *VirtController) GetNetwork(name string) (network *Network, err error)

func (*VirtController) GetNetworkResources

func (self *VirtController) GetNetworkResources(tctx *logger.TraceContext, names []string) (networkResources NetworkResources, err error)

func (*VirtController) GetVm

func (self *VirtController) GetVm(name string) (vm *Vm, err error)

func (*VirtController) GetVmResources

func (self *VirtController) GetVmResources(tctx *logger.TraceContext, names []string) (vmResources VmResources, err error)

func (*VirtController) MustBootstrap

func (self *VirtController) MustBootstrap()

func (*VirtController) MustInit

func (self *VirtController) MustInit()

func (*VirtController) PrepareImages

func (self *VirtController) PrepareImages(tctx *logger.TraceContext, vmResources VmResources) (err error)

func (*VirtController) PrepareNetworks

func (self *VirtController) PrepareNetworks(tctx *logger.TraceContext, vmResources VmResources) (err error)

func (*VirtController) Start

func (self *VirtController) Start(tctx *logger.TraceContext, kind string, args []string) (result *GetResult, err error)

func (*VirtController) StartVmResources

func (self *VirtController) StartVmResources(tctx *logger.TraceContext, names []string) (vmResources VmResources, err error)

type VirtControllerConfig

type VirtControllerConfig struct {
	VarDir   string
	Database db_utils.Config
}

type Vm

type Vm struct {
	VmSpec
	VmImage
	Id           uint            `gorm:"not null;primaryKey;autoIncrement;"`
	DeletedAt    *time.Time      `gorm:"uniqueIndex:udx_name;"`
	ImageId      uint            `gorm:"not null;`
	SpecStr      string          `gorm:"not null;column:spec" json:"-"`
	Status       string          `gorm:"not null;"`
	NetworkPorts []VmNetworkPort `gorm:"-"`
}

type VmImage

type VmImage struct {
	ImageId        uint   `gorm:"-" json:"-"`
	ImageName      string `gorm:"-" json:"-"`
	ImageNamespace string `gorm:"-" json:"-"`
	ImageKind      string `gorm:"-" json:"-"`
	ImageSpecStr   string `gorm:"-" json:"-"`
	// contains filtered or unexported fields
}

type VmNetwork

type VmNetwork struct {
	Network
	// contains filtered or unexported fields
}

type VmNetworkPort

type VmNetworkPort struct {
	*VmNetwork
	NetworkPort
}

type VmQemuSpec

type VmQemuSpec struct {
	Service SystemdService `gorm:"-"`
}

type VmResource

type VmResource struct {
	Kind string
	Spec Vm
}

type VmResources

type VmResources []VmResource

func (VmResources) String

func (self VmResources) String() string

type VmSpec

type VmSpec struct {
	Name      string              `gorm:"not null;uniqueIndex:udx_name;" validate:"required"`
	Namespace string              `gorm:"not null;uniqueIndex:udx_name;" validate:"required"`
	Kind      string              `gorm:"not null;" validate:"required"`
	Vcpus     uint                `gorm:"not null;" validate:"required"`
	MemoryMb  uint                `gorm:"not null;" validate:"required"`
	DiskGb    uint                `gorm:"not null;" validate:"required"`
	Image     ImageDetectSpec     `gorm:"-"`
	Networks  []NetworkDetectSpec `gorm:"-"`
	Spec      interface{}         `gorm:"-"`
}

Jump to

Keyboard shortcuts

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