datastore

package
Version: v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DemotedUser = "metal"
)

Variables

View Source
var (
	// DefaultVRFPoolRangeMin the default minimum integer to get from the vrf pool
	DefaultVRFPoolRangeMin = uint(1)
	// DefaultVRFPoolRangeMax the default maximum integer to get from the vrf pool
	DefaultVRFPoolRangeMax = uint(131072)
	// DefaultASNPoolRangeMin the default minimum integer to get from the asn pool
	DefaultASNPoolRangeMin = uint(1)
	// DefaultASNPoolRangeMax the default maximum integer to get from the asn pool
	DefaultASNPoolRangeMax = uint(131072)
)

Functions

func MustRegisterMigration added in v0.12.0

func MustRegisterMigration(m Migration)

MustRegisterMigration registers a migration and panics when a problem occurs

Types

type IPSearchQuery

type IPSearchQuery struct {
	IPAddress        *string  `` /* 151-byte string literal not displayed */
	AllocationUUID   *string  `` /* 171-byte string literal not displayed */
	Name             *string  `json:"name" description:"the name of the ip address" optional:"true"`
	ParentPrefixCidr *string  `json:"networkprefix" description:"the prefix of the network this ip address belongs to" optional:"true"`
	NetworkID        *string  `json:"networkid" description:"the network this ip allocate request address belongs to" optional:"true"`
	Tags             []string `json:"tags" description:"the tags that are assigned to this ip address" optional:"true"`
	ProjectID        *string  `json:"projectid" description:"the project this ip address belongs to, empty if not strong coupled" optional:"true"`
	Type             *string  `json:"type" description:"the type of the ip address, ephemeral or static" optional:"true"`
	MachineID        *string  `json:"machineid" description:"the machine an ip address is associated to" optional:"true"`
}

IPSearchQuery can be used to search networks.

type IntegerPool added in v0.9.3

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

IntegerPool manages unique integers

func (*IntegerPool) AcquireRandomUniqueInteger added in v0.9.3

func (ip *IntegerPool) AcquireRandomUniqueInteger() (uint, error)

AcquireRandomUniqueInteger returns a random unique integer from the pool.

func (*IntegerPool) AcquireUniqueInteger added in v0.9.3

func (ip *IntegerPool) AcquireUniqueInteger(value uint) (uint, error)

AcquireUniqueInteger returns a unique integer from the pool.

func (*IntegerPool) ReleaseUniqueInteger added in v0.9.3

func (ip *IntegerPool) ReleaseUniqueInteger(id uint) error

ReleaseUniqueInteger returns a unique integer to the pool.

func (*IntegerPool) String added in v0.12.3

func (ip *IntegerPool) String() string

type IntegerPoolType added in v0.9.3

type IntegerPoolType string

IntegerPoolType defines the name of the IntegerPool

const (
	// VRFIntegerPool defines the name of the pool for VRFs
	// this also defines the name of the tables
	// FIXME, must be renamed to vrfpool later
	VRFIntegerPool IntegerPoolType = "integerpool"
	// ASNIntegerPool defines the name of the pool for ASNs
	ASNIntegerPool IntegerPoolType = "asnpool"
)

func (IntegerPoolType) String added in v0.9.3

func (p IntegerPoolType) String() string

type MachineSearchQuery

type MachineSearchQuery struct {
	ID          *string  `json:"id" optional:"true"`
	Name        *string  `json:"name" optional:"true"`
	PartitionID *string  `json:"partition_id" optional:"true"`
	SizeID      *string  `json:"sizeid" optional:"true"`
	RackID      *string  `json:"rackid" optional:"true"`
	Tags        []string `json:"tags" optional:"true"`

	// allocation
	AllocationName      *string     `json:"allocation_name" optional:"true"`
	AllocationProject   *string     `json:"allocation_project" optional:"true"`
	AllocationImageID   *string     `json:"allocation_image_id" optional:"true"`
	AllocationHostname  *string     `json:"allocation_hostname" optional:"true"`
	AllocationRole      *metal.Role `json:"allocation_role" optional:"true"`
	AllocationSucceeded *bool       `json:"allocation_succeeded" optional:"true"`

	// network
	NetworkIDs                 []string `json:"network_ids" optional:"true"`
	NetworkPrefixes            []string `json:"network_prefixes" optional:"true"`
	NetworkIPs                 []string `json:"network_ips" optional:"true"`
	NetworkDestinationPrefixes []string `json:"network_destination_prefixes" optional:"true"`
	NetworkVrfs                []int64  `json:"network_vrfs" optional:"true"`
	NetworkPrivate             *bool    `json:"network_private" optional:"true"`
	NetworkASNs                []int64  `json:"network_asns" optional:"true"`
	NetworkNat                 *bool    `json:"network_nat" optional:"true"`
	NetworkUnderlay            *bool    `json:"network_underlay" optional:"true"`

	// hardware
	HardwareMemory   *int64 `json:"hardware_memory" optional:"true"`
	HardwareCPUCores *int64 `json:"hardware_cpu_cores" optional:"true"`

	// nics
	NicsMacAddresses         []string `json:"nics_mac_addresses" optional:"true"`
	NicsNames                []string `json:"nics_names" optional:"true"`
	NicsVrfs                 []string `json:"nics_vrfs" optional:"true"`
	NicsNeighborMacAddresses []string `json:"nics_neighbor_mac_addresses" optional:"true"`
	NicsNeighborNames        []string `json:"nics_neighbor_names" optional:"true"`
	NicsNeighborVrfs         []string `json:"nics_neighbor_vrfs" optional:"true"`

	// disks
	DiskNames []string `json:"disk_names" optional:"true"`
	DiskSizes []int64  `json:"disk_sizes" optional:"true"`

	// state
	StateValue *string `json:"state_value" optional:"true"`

	// ipmi
	IpmiAddress    *string `json:"ipmi_address" optional:"true"`
	IpmiMacAddress *string `json:"ipmi_mac_address" optional:"true"`
	IpmiUser       *string `json:"ipmi_user" optional:"true"`
	IpmiInterface  *string `json:"ipmi_interface" optional:"true"`

	// fru
	FruChassisPartNumber   *string `json:"fru_chassis_part_number" optional:"true"`
	FruChassisPartSerial   *string `json:"fru_chassis_part_serial" optional:"true"`
	FruBoardMfg            *string `json:"fru_board_mfg" optional:"true"`
	FruBoardMfgSerial      *string `json:"fru_board_mfg_serial" optional:"true"`
	FruBoardPartNumber     *string `json:"fru_board_part_number" optional:"true"`
	FruProductManufacturer *string `json:"fru_product_manufacturer" optional:"true"`
	FruProductPartNumber   *string `json:"fru_product_part_number" optional:"true"`
	FruProductSerial       *string `json:"fru_product_serial" optional:"true"`
}

MachineSearchQuery can be used to search machines.

type MigrateFunc added in v0.12.0

type MigrateFunc func(db *r.Term, session r.QueryExecutor, rs *RethinkStore) error

MigrateFunc is a function that contains database migration logic

type Migration added in v0.12.0

type Migration struct {
	Name    string
	Version int
	Up      MigrateFunc
}

Migration defines a database migration

type MigrationVersionEntry added in v0.12.0

type MigrationVersionEntry struct {
	Version int    `rethinkdb:"id"`
	Name    string `rethinkdb:"name"`
}

MigrationVersionEntry is a version entry in the migration database

type Migrations added in v0.12.0

type Migrations []Migration

Migrations is a list of migrations

func (Migrations) Between added in v0.12.0

func (ms Migrations) Between(current int, target *int) (Migrations, error)

Between returns a sorted slice of migrations that are between the given current version and target version (target version contained). If target version is nil all newer versions than current are contained in the slice.

type NetworkSearchQuery

type NetworkSearchQuery struct {
	ID                  *string           `json:"id" optional:"true"`
	Name                *string           `json:"name" optional:"true"`
	PartitionID         *string           `json:"partitionid" optional:"true"`
	ProjectID           *string           `json:"projectid" optional:"true"`
	Prefixes            []string          `json:"prefixes" optional:"true"`
	DestinationPrefixes []string          `json:"destinationprefixes" optional:"true"`
	Nat                 *bool             `json:"nat" optional:"true"`
	PrivateSuper        *bool             `json:"privatesuper" optional:"true"`
	Underlay            *bool             `json:"underlay" optional:"true"`
	Vrf                 *int64            `json:"vrf" optional:"true"`
	ParentNetworkID     *string           `json:"parentnetworkid" optional:"true"`
	Labels              map[string]string `json:"labels" optional:"true"`
}

NetworkSearchQuery can be used to search networks.

type RethinkStore

type RethinkStore struct {

	// TODO: should not be public
	VRFPoolRangeMin uint
	VRFPoolRangeMax uint
	ASNPoolRangeMin uint
	ASNPoolRangeMax uint
	// contains filtered or unexported fields
}

A RethinkStore is the database access layer for rethinkdb.

func InitMockDB

func InitMockDB(t *testing.T) (*RethinkStore, *r.Mock)

InitMockDB ...

Description: This Function initializes the Mocked rethink DB. It is recommended to execute metal.InitMockDBData() to fill it with mocks

Return Values: - RethinkStore // The Database - Mock // The Mock endpoint (Used for mocks)

func New

func New(log *zap.SugaredLogger, dbhost string, dbname string, dbuser string, dbpass string) *RethinkStore

New creates a new rethink store.

func (*RethinkStore) Check added in v0.16.2

func (rs *RethinkStore) Check(ctx context.Context) (rest.HealthStatus, error)

Check implements the health interface and tests if the database is healthy.

func (*RethinkStore) Close

func (rs *RethinkStore) Close() error

Close closes the database session.

func (*RethinkStore) Connect

func (rs *RethinkStore) Connect() error

Connect connects to the database. If there is an error, it will run until there is a connection.

func (*RethinkStore) ConnectMachineWithSwitches added in v0.18.0

func (rs *RethinkStore) ConnectMachineWithSwitches(m *metal.Machine) error

func (*RethinkStore) CreateFilesystemLayout added in v0.15.0

func (rs *RethinkStore) CreateFilesystemLayout(fl *metal.FilesystemLayout) error

CreateFilesystemLayout creates a new filesystemlayout.

func (*RethinkStore) CreateIP

func (rs *RethinkStore) CreateIP(ip *metal.IP) error

CreateIP creates a new ip.

func (*RethinkStore) CreateImage

func (rs *RethinkStore) CreateImage(i *metal.Image) error

CreateImage creates a new image.

func (*RethinkStore) CreateMachine

func (rs *RethinkStore) CreateMachine(m *metal.Machine) error

CreateMachine creates a new machine in the database as "unallocated new machines". If the given machine has an allocation, the function returns an error because allocated machines cannot be created. If there is already a machine with the given ID in the database it will be replaced the the given machine. CreateNetwork creates a new network.

func (*RethinkStore) CreateNetwork

func (rs *RethinkStore) CreateNetwork(nw *metal.Network) error

CreateNetwork creates a new network.

func (*RethinkStore) CreatePartition

func (rs *RethinkStore) CreatePartition(p *metal.Partition) error

CreatePartition creates a new partition.

func (*RethinkStore) CreateProvisioningEventContainer

func (rs *RethinkStore) CreateProvisioningEventContainer(ec *metal.ProvisioningEventContainer) error

CreateProvisioningEventContainer creates a new provisioning event container.

func (*RethinkStore) CreateSize

func (rs *RethinkStore) CreateSize(size *metal.Size) error

CreateSize creates a new size.

func (*RethinkStore) CreateSizeImageConstraint added in v0.16.3

func (rs *RethinkStore) CreateSizeImageConstraint(ic *metal.SizeImageConstraint) error

CreateSizeImageConstraint creates a new SizeImageConstraint.

func (*RethinkStore) CreateSwitch

func (rs *RethinkStore) CreateSwitch(s *metal.Switch) error

CreateSwitch creates a new switch.

func (*RethinkStore) DeleteFilesystemLayout added in v0.15.0

func (rs *RethinkStore) DeleteFilesystemLayout(fl *metal.FilesystemLayout) error

DeleteFilesystemLayout deletes a filesystemlayout.

func (*RethinkStore) DeleteIP

func (rs *RethinkStore) DeleteIP(ip *metal.IP) error

DeleteIP deletes an ip.

func (*RethinkStore) DeleteImage

func (rs *RethinkStore) DeleteImage(i *metal.Image) error

DeleteImage deletes an image.

func (*RethinkStore) DeleteMachine

func (rs *RethinkStore) DeleteMachine(m *metal.Machine) error

DeleteMachine removes a machine from the database.

func (*RethinkStore) DeleteNetwork

func (rs *RethinkStore) DeleteNetwork(nw *metal.Network) error

DeleteNetwork deletes an network.

func (*RethinkStore) DeleteOrphanImages added in v0.7.0

func (rs *RethinkStore) DeleteOrphanImages(images metal.Images, machines metal.Machines) (metal.Images, error)

DeleteOrphanImages deletes Images which are no longer allocated by a machine and older than allowed. Always at least one image per OS is kept even if no longer valid and not allocated. This ensures to have always at least a usable image left.

func (*RethinkStore) DeletePartition

func (rs *RethinkStore) DeletePartition(p *metal.Partition) error

DeletePartition delets a partition.

func (*RethinkStore) DeleteSize

func (rs *RethinkStore) DeleteSize(size *metal.Size) error

DeleteSize deletes a size.

func (*RethinkStore) DeleteSizeImageConstraint added in v0.16.3

func (rs *RethinkStore) DeleteSizeImageConstraint(ic *metal.SizeImageConstraint) error

DeleteSizeImageConstraint deletes a SizeImageConstraint.

func (*RethinkStore) DeleteSwitch

func (rs *RethinkStore) DeleteSwitch(s *metal.Switch) error

DeleteSwitch deletes a switch.

func (*RethinkStore) Demote added in v0.12.0

func (rs *RethinkStore) Demote() error

Demote connects to the database with the demoted metal runtime user. this enables putting the database in read-only mode during database migrations

func (*RethinkStore) FindFilesystemLayout added in v0.15.0

func (rs *RethinkStore) FindFilesystemLayout(id string) (*metal.FilesystemLayout, error)

FindFilesystemLayout return a filesystemlayout for a given id.

func (*RethinkStore) FindIPByID

func (rs *RethinkStore) FindIPByID(id string) (*metal.IP, error)

FindIPByID returns an ip of a given id.

func (*RethinkStore) FindImage

func (rs *RethinkStore) FindImage(id string) (*metal.Image, error)

FindImage returns an image for the given image id.

func (*RethinkStore) FindImages added in v0.15.3

func (rs *RethinkStore) FindImages(id string) ([]metal.Image, error)

FindImages returns all images for the given image id.

func (*RethinkStore) FindMachine

func (rs *RethinkStore) FindMachine(q *MachineSearchQuery, ms *metal.Machine) error

FindMachine returns a machine by the given query, fails if there is no record or multiple records found.

func (*RethinkStore) FindMachineByID

func (rs *RethinkStore) FindMachineByID(id string) (*metal.Machine, error)

FindMachineByID returns a machine for a given id.

func (*RethinkStore) FindNetwork

func (rs *RethinkStore) FindNetwork(q *NetworkSearchQuery, n *metal.Network) error

FindNetwork returns a machine by the given query, fails if there is no record or multiple records found.

func (*RethinkStore) FindNetworkByID

func (rs *RethinkStore) FindNetworkByID(id string) (*metal.Network, error)

FindNetworkByID returns an network of a given id.

func (*RethinkStore) FindPartition

func (rs *RethinkStore) FindPartition(id string) (*metal.Partition, error)

FindPartition return a partition for the given id.

func (*RethinkStore) FindProvisioningEventContainer

func (rs *RethinkStore) FindProvisioningEventContainer(id string) (*metal.ProvisioningEventContainer, error)

FindProvisioningEventContainer finds a provisioning event container to a given machine id.

func (*RethinkStore) FindSize

func (rs *RethinkStore) FindSize(id string) (*metal.Size, error)

FindSize return a size for a given id.

func (*RethinkStore) FindSizeImageConstraint added in v0.16.3

func (rs *RethinkStore) FindSizeImageConstraint(sizeID string) (*metal.SizeImageConstraint, error)

FindSizeImageConstraint return a SizeImageConstraint for a given size.

func (*RethinkStore) FindSwitch

func (rs *RethinkStore) FindSwitch(id string) (*metal.Switch, error)

FindSwitch returns a switch for a given id.

func (*RethinkStore) FindWaitingMachine added in v0.8.1

func (rs *RethinkStore) FindWaitingMachine(partitionid, sizeid string) (*metal.Machine, error)

FindWaitingMachine returns an available, not allocated, waiting and alive machine of given size within the given partition. TODO: the algorithm can be optimized / shortened by using a rethinkdb join command and then using .Sample(1) but current implementation should have a slightly better readability.

func (*RethinkStore) FromHardware

func (rs *RethinkStore) FromHardware(hw metal.MachineHardware) (*metal.Size, []*metal.SizeMatchingLog, error)

FromHardware tries to find a size which matches the given hardware specs.

func (*RethinkStore) GetASNPool added in v0.12.3

func (rs *RethinkStore) GetASNPool() *IntegerPool

func (*RethinkStore) GetImage added in v0.7.0

func (rs *RethinkStore) GetImage(id string) (*metal.Image, error)

GetImage return a image for a given id without semver matching.

func (*RethinkStore) GetVRFPool added in v0.12.3

func (rs *RethinkStore) GetVRFPool() *IntegerPool

func (*RethinkStore) Initialize added in v0.12.0

func (rs *RethinkStore) Initialize() error

Initialize initializes the database, it should be called before serving the metal-api in order to ensure that tables, pools, permissions are properly initialized

func (*RethinkStore) ListFilesystemLayouts added in v0.15.0

func (rs *RethinkStore) ListFilesystemLayouts() (metal.FilesystemLayouts, error)

ListFilesystemLayouts returns all filesystemlayouts.

func (*RethinkStore) ListIPs

func (rs *RethinkStore) ListIPs() (metal.IPs, error)

ListIPs returns all ips.

func (*RethinkStore) ListImages

func (rs *RethinkStore) ListImages() (metal.Images, error)

ListImages returns all images.

func (*RethinkStore) ListMachines

func (rs *RethinkStore) ListMachines() (metal.Machines, error)

ListMachines returns all machines.

func (*RethinkStore) ListNetworks

func (rs *RethinkStore) ListNetworks() (metal.Networks, error)

ListNetworks returns all networks.

func (*RethinkStore) ListPartitions

func (rs *RethinkStore) ListPartitions() (metal.Partitions, error)

ListPartitions returns all partition.

func (*RethinkStore) ListProvisioningEventContainers

func (rs *RethinkStore) ListProvisioningEventContainers() (metal.ProvisioningEventContainers, error)

ListProvisioningEventContainers returns all machine provisioning event containers.

func (*RethinkStore) ListSizeImageConstraints added in v0.16.3

func (rs *RethinkStore) ListSizeImageConstraints() (metal.SizeImageConstraints, error)

ListSizeImageConstraints returns all SizeImageConstraints.

func (*RethinkStore) ListSizes

func (rs *RethinkStore) ListSizes() (metal.Sizes, error)

ListSizes returns all sizes.

func (*RethinkStore) ListSwitches

func (rs *RethinkStore) ListSwitches() ([]metal.Switch, error)

ListSwitches returns all known switches.

func (*RethinkStore) Migrate added in v0.12.0

func (rs *RethinkStore) Migrate(targetVersion *int, dry bool) error

Migrate runs database migrations and puts the database into read only mode for demoted runtime users.

func (*RethinkStore) Mock

func (rs *RethinkStore) Mock() *r.Mock

Mock return the mock from the rethinkdb driver and sets the session to this mock. This MUST NOT be called in productive code.

func (*RethinkStore) ProvisioningEventForMachine added in v0.17.0

func (rs *RethinkStore) ProvisioningEventForMachine(log *zap.SugaredLogger, event *metal.ProvisioningEvent, machineID string) (*metal.ProvisioningEventContainer, error)

func (*RethinkStore) SearchIPs

func (rs *RethinkStore) SearchIPs(q *IPSearchQuery, ips *metal.IPs) error

SearchIPs returns the result of the ips search request query.

func (*RethinkStore) SearchMachines

func (rs *RethinkStore) SearchMachines(q *MachineSearchQuery, ms *metal.Machines) error

SearchMachines returns the result of the machines search request query.

func (*RethinkStore) SearchNetworks

func (rs *RethinkStore) SearchNetworks(q *NetworkSearchQuery, ns *metal.Networks) error

SearchNetworks returns the networks that match the given properties

func (*RethinkStore) SearchSwitches

func (rs *RethinkStore) SearchSwitches(rackid string, macs []string) ([]metal.Switch, error)

SearchSwitches searches for switches by the given parameters.

func (*RethinkStore) SearchSwitchesByPartition added in v0.18.0

func (rs *RethinkStore) SearchSwitchesByPartition(partitionID string) ([]metal.Switch, error)

SearchSwitchesByPartition searches for switches by the given partition.

func (*RethinkStore) SearchSwitchesConnectedToMachine

func (rs *RethinkStore) SearchSwitchesConnectedToMachine(m *metal.Machine) ([]metal.Switch, error)

SearchSwitchesConnectedToMachine searches switches that are connected to the given machine.

func (*RethinkStore) ServiceName added in v0.16.2

func (rs *RethinkStore) ServiceName() string

func (*RethinkStore) SetVrfAtSwitches added in v0.18.0

func (rs *RethinkStore) SetVrfAtSwitches(m *metal.Machine, vrf string) ([]metal.Switch, error)

SetVrfAtSwitches finds the switches connected to the given machine and puts the switch ports into the given vrf. Returns the updated switches.

func (*RethinkStore) UpdateFilesystemLayout added in v0.15.0

func (rs *RethinkStore) UpdateFilesystemLayout(oldFilesystemLayout *metal.FilesystemLayout, newFilesystemLayout *metal.FilesystemLayout) error

UpdateFilesystemLayout updates a filesystemlayout.

func (*RethinkStore) UpdateIP

func (rs *RethinkStore) UpdateIP(oldIP *metal.IP, newIP *metal.IP) error

UpdateIP updates an ip.

func (*RethinkStore) UpdateImage

func (rs *RethinkStore) UpdateImage(oldImage *metal.Image, newImage *metal.Image) error

UpdateImage updates an image.

func (*RethinkStore) UpdateMachine

func (rs *RethinkStore) UpdateMachine(oldMachine *metal.Machine, newMachine *metal.Machine) error

UpdateMachine replaces a machine in the database if the 'changed' field of the old value equals the 'changed' field of the recorded in the database.

func (*RethinkStore) UpdateNetwork

func (rs *RethinkStore) UpdateNetwork(oldNetwork *metal.Network, newNetwork *metal.Network) error

UpdateNetwork updates an network.

func (*RethinkStore) UpdatePartition

func (rs *RethinkStore) UpdatePartition(oldPartition *metal.Partition, newPartition *metal.Partition) error

UpdatePartition updates a partition.

func (*RethinkStore) UpdateProvisioningEventContainer

func (rs *RethinkStore) UpdateProvisioningEventContainer(old *metal.ProvisioningEventContainer, new *metal.ProvisioningEventContainer) error

UpdateProvisioningEventContainer updates a provisioning event container.

func (*RethinkStore) UpdateSize

func (rs *RethinkStore) UpdateSize(oldSize *metal.Size, newSize *metal.Size) error

UpdateSize updates a size.

func (*RethinkStore) UpdateSizeImageConstraint added in v0.16.3

func (rs *RethinkStore) UpdateSizeImageConstraint(oldSizeImageConstraint *metal.SizeImageConstraint, newSizeImageConstraint *metal.SizeImageConstraint) error

UpdateSizeImageConstraint updates a SizeImageConstraint.

func (*RethinkStore) UpdateSwitch

func (rs *RethinkStore) UpdateSwitch(oldSwitch *metal.Switch, newSwitch *metal.Switch) error

UpdateSwitch updates a switch.

func (*RethinkStore) UpsertProvisioningEventContainer

func (rs *RethinkStore) UpsertProvisioningEventContainer(ec *metal.ProvisioningEventContainer) error

UpsertProvisioningEventContainer inserts a machine's event container.

Directories

Path Synopsis
Package migrations contains migration functions for migrating the RethinkDB.
Package migrations contains migration functions for migrating the RethinkDB.

Jump to

Keyboard shortcuts

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