Documentation ¶
Overview ¶
Package images defines the models representing different image types
Index ¶
- Constants
- type BootSetup
- type DiskCompressionStrategy
- type DiskType
- type FilesystemType
- type ImageFrozen
- type ImageModel
- func (image *ImageModel) AfterDelete(tx *gorm.DB) (ret error)
- func (image *ImageModel) BeforeCreate(tx *gorm.DB) (ret error)
- func (image *ImageModel) CreateImageFile(imageSize uint, baseSize uint) error
- func (image *ImageModel) FormatImage()
- func (image *ImageModel) GenerateChecksum() error
- func (image *ImageModel) OpenImageFile(version uint64) (*os.File, error)
- func (image *ImageModel) UpdateImage(r *io.Reader)
- type ImageSetup
- type ImageUUID
- type MachineImageModel
- type Version
Constants ¶
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" )
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" )
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 )
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
func (DiskType) MarshalJSON ¶
MarshalJSON marshals the enum as a quoted json string
func (*DiskType) UnmarshalJSON ¶
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 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.