model

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package model provides the data model for grendel

Index

Constants

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

Variables

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")
)

Functions

func NewBootToken

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

func NewFirmwareToken

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

func ParseFirmwareToken

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

Types

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"`
}

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) 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) 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) 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) 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

type DataStore

type DataStore interface {
	// 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

	// 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)

	// 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 hosts 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

	// 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 Host

type Host struct {
	ID         ksuid.KSUID     `json:"id,omitempty"`
	Name       string          `json:"name" validate:"required,hostname"`
	Interfaces []*NetInterface `json:"interfaces"`
	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) Interface

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

func (*Host) InterfaceBMC

func (h *Host) InterfaceBMC() *NetInterface

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   net.IP           `json:"ip"`
	FQDN string           `json:"fqdn"`
	BMC  bool             `json:"bmc"`
}

func (*NetInterface) MarshalJSON

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

func (*NetInterface) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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