model

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: GPL-3.0 Imports: 25 Imported by: 1

Documentation

Overview

Package model provides the data model for grendel

Index

Constants

View Source
const (
	HostKeyPrefix      = "host"
	BootImageKeyPrefix = "image"
	UserKeyPrefix      = "user"
)

Variables

View Source
var (
	ProvisionAddr       netip.AddrPort = netip.MustParseAddrPort("0.0.0.0:80")
	ProvisionScheme     string         = "http"
	ProvisionHostname   string         = ""
	Subnets             []Subnet       = []Subnet{}
	DefaultDNS          []net.IP       = []net.IP{}
	DefaultDomainSearch []string       = []string{}
	DefaultMTU          uint16         = 1500
	DefaultGateway      netip.Addr
)
View Source
var (

	// ErrNotFound is returned when a model is not found in the store
	ErrNotFound = errors.New("not found")

	// ErrInvalidData is returned when a model is is missing required data
	ErrInvalidData = errors.New("invalid data")

	// ErrDuplicateEntry is returned when attempting to store a model with the same ID or Name
	ErrDuplicateEntry = errors.New("duplicate entry")
)

Functions

func NewBootToken

func NewBootToken(id, mac string) (string, error)

func NewFirmwareToken

func NewFirmwareToken(mac string, fwtype firmware.Build) (string, error)

func ParseConfigs added in v0.0.8

func ParseConfigs() error

func ParseFirmwareToken

func ParseFirmwareToken(token string) (firmware.Build, error)

Types

type Bond added in v0.0.11

type Bond struct {
	NetInterface
	Peers []string `json:"peers"`
}

func (*Bond) MarshalJSON added in v0.0.11

func (b *Bond) MarshalJSON() ([]byte, error)

func (*Bond) UnmarshalJSON added in v0.0.11

func (b *Bond) UnmarshalJSON(data []byte) error

type BootClaims

type BootClaims struct {
	ID  string `json:"id"`
	MAC string `json:"mac"`
}

func ParseBootToken added in v0.0.2

func ParseBootToken(token string) (*BootClaims, error)

type BootImage

type BootImage struct {
	ID                 ksuid.KSUID       `json:"id"`
	Name               string            `json:"name" validate:"required"`
	KernelPath         string            `json:"kernel" validate:"required"`
	InitrdPaths        []string          `json:"initrd"`
	LiveImage          string            `json:"liveimg"`
	CommandLine        string            `json:"cmdline"`
	Verify             bool              `json:"verify"`
	ProvisionTemplate  string            `json:"provision_template"`
	ProvisionTemplates map[string]string `json:"provision_templates"`
	UserData           string            `json:"user_data"`
	Butane             string            `json:"butane"`
}

func (*BootImage) CheckPathsExist

func (b *BootImage) CheckPathsExist() error

type BootImageList

type BootImageList []*BootImage

func NewBootImageList

func NewBootImageList() BootImageList

type BuntStore

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

BuntStore implements a Grendel Datastore using BuntDB

func NewBuntStore

func NewBuntStore(filename string) (*BuntStore, error)

NewBuntStore returns a new BuntStore using the given database filename. For memory only you can provide `:memory:`

func (*BuntStore) BootImages

func (s *BuntStore) BootImages() (BootImageList, error)

BootImages returns a list of all boot images

func (*BuntStore) Close

func (s *BuntStore) Close() error

Close closes the BuntStore database

func (*BuntStore) DeleteBootImages added in v0.0.6

func (s *BuntStore) DeleteBootImages(names []string) error

DeleteBootImages deletes boot images from the data store.

func (*BuntStore) DeleteHosts added in v0.0.6

func (s *BuntStore) DeleteHosts(ns *nodeset.NodeSet) error

DeleteHosts deletes all hosts in the given nodeset.NodeSet from the data store.

func (*BuntStore) DeleteUser added in v0.0.9

func (s *BuntStore) DeleteUser(username string) error

DeleteUser deletes the given user

func (*BuntStore) FindHosts

func (s *BuntStore) FindHosts(ns *nodeset.NodeSet) (HostList, error)

FindHosts returns a list of all the hosts in the given NodeSet

func (*BuntStore) FindTags added in v0.0.5

func (s *BuntStore) FindTags(tags []string) (*nodeset.NodeSet, error)

FindTags returns a nodeset.NodeSet of all the hosts with the given tags

func (*BuntStore) GetUsers added in v0.0.9

func (s *BuntStore) GetUsers() ([]User, error)

GetUsers returns a list of all the usernames

func (*BuntStore) Hosts

func (s *BuntStore) Hosts() (HostList, error)

Hosts returns a list of all the hosts

func (*BuntStore) LoadBootImage

func (s *BuntStore) LoadBootImage(name string) (*BootImage, error)

LoadBootImage returns a BootImage with the given name

func (*BuntStore) LoadHostFromID

func (s *BuntStore) LoadHostFromID(id string) (*Host, error)

LoadHostFromID returns the Host with the given ID

func (*BuntStore) LoadHostFromMAC

func (s *BuntStore) LoadHostFromMAC(mac string) (*Host, error)

LoadHostFromMAC returns the Host that has a network interface with the give MAC address

func (*BuntStore) LoadHostFromName

func (s *BuntStore) LoadHostFromName(name string) (*Host, error)

LoadHostFromName returns the Host with the given name

func (*BuntStore) MatchTags added in v0.0.9

func (s *BuntStore) MatchTags(tags []string) (*nodeset.NodeSet, error)

MatchTags returns a nodeset.NodeSet of all the hosts with the all given tags

func (*BuntStore) ProvisionHosts

func (s *BuntStore) ProvisionHosts(ns *nodeset.NodeSet, provision bool) error

ProvisionHosts sets all hosts in the given NodeSet to provision (true) or unprovision (false)

func (*BuntStore) ResolveIPv4

func (s *BuntStore) ResolveIPv4(fqdn string) ([]net.IP, error)

ResolveIPv4 returns the list of IPv4 addresses with the given FQDN

func (*BuntStore) ReverseResolve

func (s *BuntStore) ReverseResolve(ip string) ([]string, error)

ReverseResolve returns the list of FQDNs for the given IP

func (*BuntStore) SetBootImage

func (s *BuntStore) SetBootImage(ns *nodeset.NodeSet, name string) error

SetBootImage sets all hosts to use the BootImage with the given name

func (*BuntStore) StoreBootImage

func (s *BuntStore) StoreBootImage(image *BootImage) error

StoreBootImage stores a boot image in the data store. If the boot image exists it is overwritten

func (*BuntStore) StoreBootImages

func (s *BuntStore) StoreBootImages(images BootImageList) error

StoreBootImages stores a list of boot images in the data store. If the boot image exists it is overwritten

func (*BuntStore) StoreHost

func (s *BuntStore) StoreHost(host *Host) error

StoreHost stores a host in the data store. If the host exists it is overwritten

func (*BuntStore) StoreHosts

func (s *BuntStore) StoreHosts(hosts HostList) error

StoreHosts stores a list of host in the data store. If the host exists it is overwritten

func (*BuntStore) StoreUser added in v0.0.9

func (s *BuntStore) StoreUser(username, password string) (string, error)

StoreUser stores the User in the data store

func (*BuntStore) TagHosts added in v0.0.5

func (s *BuntStore) TagHosts(ns *nodeset.NodeSet, tags []string) error

TagHosts adds tags to all hosts in the given NodeSet

func (*BuntStore) UntagHosts added in v0.0.5

func (s *BuntStore) UntagHosts(ns *nodeset.NodeSet, tags []string) error

UntagHosts removes tags from all hosts in the given NodeSet

func (*BuntStore) UpdateUser added in v0.0.9

func (s *BuntStore) UpdateUser(username, role string) error

UpdateUser updates the role of the given users

func (*BuntStore) VerifyUser added in v0.0.9

func (s *BuntStore) VerifyUser(username, password string) (bool, string, error)

VerifyUser checks if the given username exists in the data store

type DataStore

type DataStore interface {
	// StoreUser stores the User in the data store
	StoreUser(username, password string) (string, error)

	// VerifyUser checks if the given username exists in the data store
	VerifyUser(username, password string) (bool, string, error)

	// GetUsers returns a list of all the usernames
	GetUsers() ([]User, error)

	// UpdateUser updates the role of the given users
	UpdateUser(username, role string) error

	// DeleteUser deletes the given user
	DeleteUser(username string) error

	// BootImages returns a list of all boot images
	BootImages() (BootImageList, error)

	// LoadBootImage returns a BootImage with the given name
	LoadBootImage(name string) (*BootImage, error)

	// StoreBootImage stores the BootImage in the data store
	StoreBootImage(image *BootImage) error

	// StoreBootImages stores a list of BootImages in the data store
	StoreBootImages(images BootImageList) error

	// DeleteBootImages delete BootImages from the data store
	DeleteBootImages(names []string) error

	// SetBootImage sets all hosts to use the BootImage with the given name
	SetBootImage(ns *nodeset.NodeSet, name string) error

	// Hosts returns a list of all the hosts
	Hosts() (HostList, error)

	// FindHosts returns a list of all the hosts in the given NodeSet
	FindHosts(ns *nodeset.NodeSet) (HostList, error)

	// FindTags returns a nodeset.NodeSet of all the hosts with the given tags
	FindTags(tags []string) (*nodeset.NodeSet, error)

	// MatchTags returns a nodeset.NodeSet of all the hosts with the all given tags
	MatchTags(tags []string) (*nodeset.NodeSet, error)

	// ProvisionHosts sets all hosts in the given NodeSet to provision (true) or unprovision (false)
	ProvisionHosts(ns *nodeset.NodeSet, provision bool) error

	// TagHosts adds tags to all hosts in the given NodeSet
	TagHosts(ns *nodeset.NodeSet, tags []string) error

	// UntagHosts removes tags from all hosts in the given NodeSet
	UntagHosts(ns *nodeset.NodeSet, tags []string) error

	// StoreHosts stores a host in the data store. If the host exists it is overwritten
	StoreHost(host *Host) error

	// StoreHosts stores a list of hosts in the data store. If the host exists it is overwritten
	StoreHosts(hosts HostList) error

	// DeleteHosts deletes all hosts in the given nodeset.NodeSet from the data store.
	DeleteHosts(ns *nodeset.NodeSet) error

	// LoadHostFromID returns the Host with the given ID
	LoadHostFromID(id string) (*Host, error)

	// LoadHostFromName returns the Host with the given name
	LoadHostFromName(name string) (*Host, error)

	// LoadHostFromMAC returns the Host that has a network interface with the give MAC address
	LoadHostFromMAC(mac string) (*Host, error)

	// ResolveIPv4 returns the list of IPv4 addresses with the given FQDN
	ResolveIPv4(fqdn string) ([]net.IP, error)

	// ReverseResolve returns the list of FQDNs for the given IP
	ReverseResolve(ip string) ([]string, error)

	// Close data store
	Close() error
}

DataStore

func NewDataStore

func NewDataStore(path string) (DataStore, error)

type Endpoints added in v0.0.8

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

func NewEndpoints added in v0.0.8

func NewEndpoints(host, token string) *Endpoints

func (*Endpoints) BaseURL added in v0.0.8

func (e *Endpoints) BaseURL() string

func (*Endpoints) BootFileURL added in v0.0.8

func (e *Endpoints) BootFileURL() string

func (*Endpoints) CloudInitURL added in v0.0.8

func (e *Endpoints) CloudInitURL() string

func (*Endpoints) CompleteURL added in v0.0.8

func (e *Endpoints) CompleteURL() string

func (*Endpoints) IgnitionURL added in v0.0.8

func (e *Endpoints) IgnitionURL() string

func (*Endpoints) InitrdURL added in v0.0.8

func (e *Endpoints) InitrdURL(index int) string

func (*Endpoints) IpxeURL added in v0.0.8

func (e *Endpoints) IpxeURL() string

func (*Endpoints) KernelURL added in v0.0.8

func (e *Endpoints) KernelURL() string

func (*Endpoints) KickstartURL added in v0.0.8

func (e *Endpoints) KickstartURL() string

func (*Endpoints) KickstartURLParts added in v0.0.9

func (e *Endpoints) KickstartURLParts() (string, string)

func (*Endpoints) LiveImageURL added in v0.0.8

func (e *Endpoints) LiveImageURL() string

func (*Endpoints) MetaDataURL added in v0.0.8

func (e *Endpoints) MetaDataURL() string

func (*Endpoints) ProvisionURL added in v0.0.8

func (e *Endpoints) ProvisionURL(name string) string

func (*Endpoints) ProxmoxURL added in v0.0.12

func (e *Endpoints) ProxmoxURL() string

func (*Endpoints) RepoURL added in v0.0.8

func (e *Endpoints) RepoURL() string

func (*Endpoints) RootFSURL added in v0.0.8

func (e *Endpoints) RootFSURL() string

func (*Endpoints) UserDataURL added in v0.0.8

func (e *Endpoints) UserDataURL() string

func (*Endpoints) VendorDataURL added in v0.0.8

func (e *Endpoints) VendorDataURL() string

type Host

type Host struct {
	ID         ksuid.KSUID     `json:"id,omitempty"`
	Name       string          `json:"name" validate:"required,hostname"`
	Interfaces []*NetInterface `json:"interfaces"`
	Bonds      []*Bond         `json:"bonds"`
	Provision  bool            `json:"provision"`
	Firmware   firmware.Build  `json:"firmware"`
	BootImage  string          `json:"boot_image"`
	Tags       []string        `json:"tags"`
}

func (*Host) BootInterface added in v0.0.5

func (h *Host) BootInterface() *NetInterface

func (*Host) FromJSON

func (h *Host) FromJSON(hostJSON string)

func (*Host) HasAnyTags added in v0.0.8

func (h *Host) HasAnyTags(tags ...string) bool

func (*Host) HasTags added in v0.0.8

func (h *Host) HasTags(tags ...string) bool

func (*Host) HostType added in v0.0.9

func (h *Host) HostType() string

func (*Host) Interface

func (h *Host) Interface(mac net.HardwareAddr) *NetInterface

func (*Host) InterfaceBMC

func (h *Host) InterfaceBMC() *NetInterface

func (*Host) InterfaceBonded added in v0.0.11

func (h *Host) InterfaceBonded(peer string) bool

func (*Host) MarshalJSON

func (h *Host) MarshalJSON() ([]byte, error)

func (*Host) ToJSON

func (h *Host) ToJSON() string

func (*Host) UnmarshalJSON

func (h *Host) UnmarshalJSON(data []byte) error

type HostList

type HostList []*Host

func NewHostList

func NewHostList() HostList

func (HostList) FilterPrefix

func (hl HostList) FilterPrefix(prefix string) HostList

func (HostList) ToNodeSet added in v0.0.5

func (hl HostList) ToNodeSet() (*nodeset.NodeSet, error)

type HostMap

type HostMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHostMap

func NewHostMap() *HostMap

func (*HostMap) Delete

func (hm *HostMap) Delete(key string)

func (*HostMap) Load

func (hm *HostMap) Load(key string) (*Host, bool)

func (*HostMap) Store

func (hm *HostMap) Store(key string, value *Host)

type NetInterface

type NetInterface struct {
	MAC  net.HardwareAddr `json:"mac" validate:"required"`
	Name string           `json:"ifname"`
	IP   netip.Prefix     `json:"ip"`
	FQDN string           `json:"fqdn"`
	BMC  bool             `json:"bmc"`
	VLAN string           `json:"vlan"`
	MTU  uint16           `json:"mtu,omitempty"`
}

func (*NetInterface) Addr added in v0.0.8

func (n *NetInterface) Addr() netip.Addr

func (*NetInterface) AddrString added in v0.0.8

func (n *NetInterface) AddrString() string

func (*NetInterface) CIDR added in v0.0.8

func (n *NetInterface) CIDR() string

func (*NetInterface) DNS added in v0.0.8

func (n *NetInterface) DNS() []net.IP

func (*NetInterface) DNSList added in v0.0.8

func (n *NetInterface) DNSList() []string

func (*NetInterface) Domain added in v0.0.9

func (n *NetInterface) Domain() string

func (*NetInterface) DomainSearch added in v0.0.8

func (n *NetInterface) DomainSearch() []string

func (*NetInterface) Gateway added in v0.0.8

func (n *NetInterface) Gateway() netip.Addr

func (*NetInterface) HostName added in v0.0.9

func (n *NetInterface) HostName() string

func (*NetInterface) HostNameIndex added in v0.0.11

func (n *NetInterface) HostNameIndex(idx int) string

func (*NetInterface) InterfaceMTU added in v0.0.8

func (n *NetInterface) InterfaceMTU() uint16

func (*NetInterface) MarshalJSON

func (n *NetInterface) MarshalJSON() ([]byte, error)

func (*NetInterface) Netmask added in v0.0.8

func (n *NetInterface) Netmask() net.IPMask

func (*NetInterface) NetmaskString added in v0.0.8

func (n *NetInterface) NetmaskString() string

func (*NetInterface) ShortName added in v0.0.9

func (n *NetInterface) ShortName() string

func (*NetInterface) ToStdAddr added in v0.0.8

func (n *NetInterface) ToStdAddr() net.IP

func (*NetInterface) UnmarshalJSON

func (n *NetInterface) UnmarshalJSON(data []byte) error

type Subnet added in v0.0.8

type Subnet struct {
	Gateway      netip.Prefix
	DNS          []net.IP
	DomainSearch []string
	MTU          uint16
}

type User added in v0.0.9

type User struct {
	Username   string
	Role       string
	CreatedAt  time.Time
	ModifiedAt time.Time
}

type UserValue added in v0.0.9

type UserValue struct {
	Hash       []byte    `json:"hash"`
	Role       string    `json:"role"`
	CreatedAt  time.Time `json:"created_at"`
	ModifiedAt time.Time `json:"modified_at"`
}

Jump to

Keyboard shortcuts

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