images

package
v0.0.0-...-278bb9c Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package images defines the models representing different image types

Index

Constants

View Source
const (
	// DiskCompressionStrategyNone does not compress
	DiskCompressionStrategyNone DiskCompressionStrategy = "none"
	// DiskCompressionStrategyZSTD compresses disk images with zstd.
	DiskCompressionStrategyZSTD = "zstd"
	// DiskCompressionStrategyGZip uses the standard GZip compression algorithm for disks.
	DiskCompressionStrategyGZip = "gzip"
)
View Source
const (
	// FileSystemTypeFAT32 defines a disk using the universal FAT32 filesystem
	FileSystemTypeFAT32 FilesystemType = "fat32"
	// FileSystemTypeEXT4 defines a disk using the Linux EXT4 filesystem
	FileSystemTypeEXT4 = "ext4"
	// FileSystemTypeRaw is fully filesystem agnostic
	FileSystemTypeRaw = "raw"
)
View Source
const (
	// SizeMegabyte are the bytes equivalent to one megabyte
	SizeMegabyte uint = 1024 * 1024
	// SizeGigabyte are the bytes equivalent to one gigabyte
	SizeGigabyte = 1024 * 1024 * 1024
)
View Source
const FilePathFmt = "/%s/%d.img"

FilePathFmt is the format string to create the path the image should be written to

Variables

This section is empty.

Functions

This section is empty.

Types

type BootSetup

type BootSetup struct {
	gorm.Model `json:"-"`

	// Store the machine id
	Machine    machine.MachineModel `gorm:"foreignKey:MachineMAC;references:Address;not null;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	MachineMAC string               `gorm:"not null;primaryKey"`

	// Store the setup that should be loaded onto the machine
	Setup     ImageSetup `gorm:"foreignKey:SetupUUID;references:UUID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	SetupUUID ImageUUID  `gorm:"not null;primaryKey"`

	// Should the image changes be uploaded to the server?
	Update bool `gorm:"not null;"`
}

BootSetup stores what the next boot for the machine should look like. It functions somewhat like a queue where it removes the first value from the database.

type DiskCompressionStrategy

type DiskCompressionStrategy string

DiskCompressionStrategy is how the disk is compressed

type DiskType

type DiskType int

DiskType describes the type of disk image, this can also describe the filesystem contained within

const (
	// DiskTypeRaw is the simplest DiskType of which nothing extra is known
	DiskTypeRaw DiskType = iota
	// DiskTypeQCow2 defines an image of the QCow type used by qemu
	DiskTypeQCow2
)

func (DiskType) MarshalJSON

func (s DiskType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the enum as a quoted json string

func (DiskType) String

func (s DiskType) String() string

String returns a string associated with a DiskType

func (*DiskType) UnmarshalJSON

func (s *DiskType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type FilesystemType

type FilesystemType string

FilesystemType is the type of filesystem that is used by the image

type ImageFrozen

type ImageFrozen struct {
	gorm.Model `json:"-"`
	Image      ImageModel `gorm:"foreignKey:UUIDImage;references:UUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	UUIDImage  ImageUUID  `gorm:"not null;" json:"-"`
	Version    Version    `gorm:"foreignKey:VersionID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	VersionID  uint64     `gorm:"not null" json:"-"`

	// ImageSetup     ImageSetup `json:"-" gorm:"foreignKey:UUID;referencesImageSetupUUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	ImageSetupUUID ImageUUID `json:"-"`
	Update         bool      `gorm:"not null;default:false"`
}

ImageFrozen defines a collection of Images where are pegged to a specific version.

type ImageModel

type ImageModel struct {

	// Human identifiable name of this image
	Name string `gorm:"not null"`

	// Versions are all possible versions of this image, represented as unix
	// timestamps of their creation. A new version is created whenever a reprovisioning
	// takes place, and this image is replaced.
	Versions []Version `gorm:"foreignKey:ImageModelUUID;not null;references:UUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`

	// ImageUUID is a universally unique identifier for images
	UUID ImageUUID `gorm:"uniqueIndex;primaryKey;unique"`

	// Foreign key for gorm
	Username string `gorm:"foreignKey:Username;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`

	// Compression algorithm used for this image
	DiskCompressionStrategy DiskCompressionStrategy `gorm:"not null;"`

	// The Image Filetype
	ImageFileType DiskType `gorm:"not null;"`

	// The image type
	Type string `gorm:"not null;"`

	// Checksum for this image as alternative for versioning
	Checksum string

	// ImagePath is where the system has stored this image
	ImagePath string `json:"-" gorm:"not null"`

	Filesystem FilesystemType
}

ImageModel defines the database structure for storing the metadata about images

func (*ImageModel) AfterDelete

func (image *ImageModel) AfterDelete(tx *gorm.DB) (ret error)

AfterDelete removes the image directory

func (*ImageModel) BeforeCreate

func (image *ImageModel) BeforeCreate(tx *gorm.DB) (ret error)

BeforeCreate adds the image path and creates the first version of the image.

func (*ImageModel) CreateImageFile

func (image *ImageModel) CreateImageFile(imageSize uint, baseSize uint) error

CreateImageFile creates the actual image on disk with a given size.

func (*ImageModel) FormatImage

func (image *ImageModel) FormatImage()

FormatImage formats the image to the filesystem defined in the metadata. Warning: this will delete all the currently existing data of the image.

func (*ImageModel) GenerateChecksum

func (image *ImageModel) GenerateChecksum() error

GenerateChecksum generates the checksum of the image

func (*ImageModel) OpenImageFile

func (image *ImageModel) OpenImageFile(version uint64) (*os.File, error)

OpenImageFile opens an image file so it can be read by the system

func (*ImageModel) UpdateImage

func (image *ImageModel) UpdateImage(r *io.Reader)

UpdateImage updates the image

type ImageSetup

type ImageSetup struct {
	gorm.Model `json:"-"`
	Name       string        `gorm:"not null"`
	Images     []ImageFrozen `gorm:"foreignKey:ImageSetupUUID;references:UUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	Username   string        `gorm:"foreignKey:Username;not null;"`
	UUID       ImageUUID     `gorm:"uniqueIndex;primaryKey;unique;not null;"`
}

ImageSetup defines a collection of Images

func CreateImageSetup

func CreateImageSetup(name string) ImageSetup

CreateImageSetup creates an ImageSetup of a specified name.

func (*ImageSetup) AddFrozenImages

func (setup *ImageSetup) AddFrozenImages(images ...ImageFrozen)

AddFrozenImages adds all the given ImageFrozen to the ImageSetup

func (*ImageSetup) AddImage

func (setup *ImageSetup) AddImage(image *ImageModel, version Version, update bool)

AddImage takes an Image and a Version to adds both to Image list in ImageSetup

func (*ImageSetup) GetImageFromSetup

func (setup *ImageSetup) GetImageFromSetup(name string) (*ImageModel, *Version)

GetImageFromSetup queries the Image list to find aspecified ImageModel

type ImageUUID

type ImageUUID string

ImageUUID is a UUID distinguishing each disk image

type MachineImageModel

type MachineImageModel struct {
	ImageModel
	// Store the machine id
	Machine    model.MachineModel `gorm:"foreignKey:MachineMAC;references:Address;not null;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	MachineMAC string             `gorm:"not null;primaryKey"`

	Size uint // filesize in MiB
}

MachineImageModel is the model defining the image which holds data about the specific machine

func CreateMachineImageModel

func CreateMachineImageModel(mac util.MacAddress) (*MachineImageModel, error)

CreateMachineImageModel creates a simple machine image for the designated machine

func (*MachineImageModel) AfterDelete

func (machineImage *MachineImageModel) AfterDelete(tx *gorm.DB) (ret error)

AfterDelete removes all the data associated with the machine.

func (*MachineImageModel) BeforeCreate

func (machineImage *MachineImageModel) BeforeCreate(tx *gorm.DB) (ret error)

BeforeCreate creates the machine image model directory and image file.

type Version

type Version struct {
	gorm.Model     `json:"-"`
	Version        uint64    `gorm:"not null;default:0"`
	ImageModelUUID ImageUUID `gorm:"not null;"`
}

Version stores the version of an ImageModel using an UNIX timestamp

Jump to

Keyboard shortcuts

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