Documentation ¶
Index ¶
- Constants
- Variables
- func IsValidBmcType(bmcType string) bool
- func IsValidIgnitionID(id string) bool
- func IsValidImageID(id string) bool
- func IsValidImageOS(os string) bool
- func IsValidKernelParams(s string) bool
- func IsValidLabelName(name string) bool
- func IsValidLabelValue(value string) bool
- func IsValidRole(role string) bool
- type Asset
- type AssetHandler
- type AssetModel
- type AssetStatus
- type AuditCategory
- type AuditContextKey
- type AuditLog
- type BMCInfo
- type DHCPConfig
- type DHCPModel
- type HealthModel
- type IPAMConfig
- type IPAMModel
- type IgnitionModel
- type IgnitionTemplate
- type IgnitionVersion
- type Image
- type ImageIndex
- type ImageModel
- type KernelParams
- type KernelParamsModel
- type LeaseRange
- type LogModel
- type Machine
- type MachineBMC
- type MachineInfo
- type MachineModel
- type MachineSpec
- type MachineState
- type MachineStatus
- type Model
- type NICConfig
- type NetworkInfo
- type Query
- func (q Query) BMCType() string
- func (q Query) IPv4() string
- func (q Query) IPv6() string
- func (q Query) IsEmpty() bool
- func (q Query) Labels() []string
- func (q Query) Match(m *Machine) bool
- func (q Query) Rack() string
- func (q Query) Role() string
- func (q Query) Serial() string
- func (q Query) State() string
- type Runner
- type SchemaModel
- type StorageModel
Constants ¶
const ( AuditAssets = AuditCategory("assets") AuditCrypts = AuditCategory("crypts") AuditDHCP = AuditCategory("dhcp") AuditIgnition = AuditCategory("ignition") AuditImage = AuditCategory("image") AuditIPAM = AuditCategory("ipam") AuditIPXE = AuditCategory("ipxe") AuditMachines = AuditCategory("machines") )
Audit categories.
const ( AuditKeyUser = AuditContextKey("user") AuditKeyIP = AuditContextKey("ip") AuditKeyHost = AuditContextKey("host") )
Audit context keys. Values must be string.
const ( Ignition2_2 = IgnitionVersion("2.2") Ignition2_3 = IgnitionVersion("2.3") )
Supported ignition versions
const ( // MaxImages is the maximum number of images that an index can hold. MaxImages = 5 // ImageKernelFilename is a filename appear in TAR archive of an image. ImageKernelFilename = "kernel" // ImageInitrdFilename is a filename appear in TAR archive of an image. ImageInitrdFilename = "initrd.gz" )
const ( StateUninitialized = MachineState("uninitialized") StateHealthy = MachineState("healthy") StateUnhealthy = MachineState("unhealthy") StateUnreachable = MachineState("unreachable") StateUpdating = MachineState("updating") StateRetiring = MachineState("retiring") StateRetired = MachineState("retired") SetStateErrorFormat = "transition from [ %s ] to [ %s ] is forbidden" )
Machine state definitions.
const DefaultLeaseDuration = 60 * time.Minute
DefaultLeaseDuration is 60 minutes.
const SchemaVersion = "3"
SchemaVersion is the schema version
const Version = "2.9.1"
Version is sabakan version
Variables ¶
var ErrBadRequest = errors.New("bad request")
ErrBadRequest is a special err for models. A model should return this when the request is bad
var ErrConflicted = errors.New("key conflicted")
ErrConflicted is a special error for models. A model should return this when it fails to update a resource due to conflicts.
var ErrEncryptionKeyExists = errors.New("encryption key exists")
ErrEncryptionKeyExists is a special err for models. A model should return this when encryption key exists.
var ErrNotFound = errors.New("not found")
ErrNotFound is a special err for models. A model should return this when it cannot find a resource by a specified key.
var ( // StateList is the list of possible machine states StateList = []MachineState{ StateUninitialized, StateHealthy, StateUnhealthy, StateUnreachable, StateUpdating, StateRetiring, StateRetired, } )
Functions ¶
func IsValidBmcType ¶
IsValidBmcType returns true if role is valid as BMC type
func IsValidIgnitionID ¶
IsValidIgnitionID returns true if id is valid as ignition ID
func IsValidImageID ¶
IsValidImageID returns true if id is valid as an image ID.
func IsValidImageOS ¶
IsValidImageOS returns true if id is valid as OS.
func IsValidKernelParams ¶
IsValidKernelParams returns true if s is valid as an kernel params
func IsValidLabelName ¶
IsValidLabelName returns true if label name is valid This is the same as the validation for Kubernetes label names.
func IsValidLabelValue ¶
IsValidLabelValue returns true if label value is valid This is the same as the validation for Kubernetes label values.
func IsValidRole ¶
IsValidRole returns true if role is valid as machine role
Types ¶
type Asset ¶
type Asset struct { Name string `json:"name"` ID int `json:"id,string"` ContentType string `json:"content-type"` Date time.Time `json:"date"` Size int64 `json:"size"` Sha256 string `json:"sha256"` URLs []string `json:"urls"` Exists bool `json:"exists"` Options map[string]string `json:"options"` }
Asset represents an asset.
type AssetHandler ¶
type AssetHandler interface { ServeContent(asset *Asset, content io.ReadSeeker) Redirect(url string) }
AssetHandler is an interface for AssetModel.Get
type AssetModel ¶
type AssetModel interface { GetIndex(ctx context.Context) ([]string, error) GetInfo(ctx context.Context, name string) (*Asset, error) GetInfoAll(ctx context.Context) ([]*Asset, error) Put(ctx context.Context, name, contentType string, csum []byte, options map[string]string, r io.Reader) (*AssetStatus, error) Get(ctx context.Context, name string, h AssetHandler) error Delete(ctx context.Context, name string) error }
AssetModel is an interface to manage assets.
type AssetStatus ¶
AssetStatus is the status of an asset.
type AuditContextKey ¶
type AuditContextKey string
AuditContextKey is the type of context keys for audit.
type AuditLog ¶
type AuditLog struct { Timestamp time.Time `json:"ts"` Revision int64 `json:"rev,string"` User string `json:"user"` IP string `json:"ip"` Host string `json:"host"` Category AuditCategory `json:"category"` Instance string `json:"instance"` Action string `json:"action"` Detail string `json:"detail"` }
AuditLog represents an audit log entry.
func NewAuditLog ¶
func NewAuditLog(ctx context.Context, ts time.Time, rev int64, cat AuditCategory, instance, action, detail string) *AuditLog
NewAuditLog creates an audit log entry and initializes it.
type BMCInfo ¶
type BMCInfo struct {
IPv4 NICConfig `json:"ipv4"`
}
BMCInfo represents BMC NIC configuration information.
type DHCPConfig ¶
type DHCPConfig struct { LeaseMinutes uint `json:"lease-minutes"` DNSServers []string `json:"dns-servers,omitempty"` // obsoleted fields GatewayOffset uint `json:"gateway-offset"` }
DHCPConfig is a set of DHCP configurations.
func (*DHCPConfig) LeaseDuration ¶
func (c *DHCPConfig) LeaseDuration() time.Duration
LeaseDuration returns lease duration for IP addreses.
func (*DHCPConfig) Validate ¶
func (c *DHCPConfig) Validate() error
Validate validates configurations
type DHCPModel ¶
type DHCPModel interface { PutConfig(ctx context.Context, config *DHCPConfig) error GetConfig() (*DHCPConfig, error) Lease(ctx context.Context, ifaddr net.IP, mac net.HardwareAddr) (net.IP, error) Renew(ctx context.Context, ciaddr net.IP, mac net.HardwareAddr) error Release(ctx context.Context, ciaddr net.IP, mac net.HardwareAddr) error Decline(ctx context.Context, ciaddr net.IP, mac net.HardwareAddr) error }
DHCPModel is an interface for DHCPConfig.
type HealthModel ¶
HealthModel is an interface for etcd health status
type IPAMConfig ¶
type IPAMConfig struct { MaxNodesInRack uint `json:"max-nodes-in-rack"` NodeIPv4Pool string `json:"node-ipv4-pool"` NodeIPv4Offset string `json:"node-ipv4-offset,omitempty"` NodeRangeSize uint `json:"node-ipv4-range-size"` NodeRangeMask uint `json:"node-ipv4-range-mask"` NodeIPPerNode uint `json:"node-ip-per-node"` NodeIndexOffset uint `json:"node-index-offset"` NodeGatewayOffset uint `json:"node-gateway-offset"` BMCIPv4Pool string `json:"bmc-ipv4-pool"` BMCIPv4Offset string `json:"bmc-ipv4-offset,omitempty"` BMCRangeSize uint `json:"bmc-ipv4-range-size"` BMCRangeMask uint `json:"bmc-ipv4-range-mask"` BMCGatewayOffset uint `json:"bmc-ipv4-gateway-offset"` }
IPAMConfig is a set of IPAM configurations.
func (*IPAMConfig) GatewayAddress ¶
func (c *IPAMConfig) GatewayAddress(addr *net.IPNet) *net.IPNet
GatewayAddress returns a gateway address for the given node address
func (*IPAMConfig) GenerateIP ¶
func (c *IPAMConfig) GenerateIP(mc *Machine)
GenerateIP generates IP addresses for a machine. Generated IP addresses are stored in mc.
func (*IPAMConfig) LeaseRange ¶
func (c *IPAMConfig) LeaseRange(ifaddr net.IP) *LeaseRange
LeaseRange returns a LeaseRange for the interface that receives DHCP requests. If no range can be assigned, this returns nil.
func (*IPAMConfig) Validate ¶
func (c *IPAMConfig) Validate() error
Validate validates configurations
type IPAMModel ¶
type IPAMModel interface { PutConfig(ctx context.Context, config *IPAMConfig) error GetConfig() (*IPAMConfig, error) }
IPAMModel is an interface for IPAMConfig.
type IgnitionModel ¶
type IgnitionModel interface { PutTemplate(ctx context.Context, role, id string, tmpl *IgnitionTemplate) error GetTemplateIDs(ctx context.Context, role string) ([]string, error) GetTemplate(ctx context.Context, role string, id string) (*IgnitionTemplate, error) DeleteTemplate(ctx context.Context, role string, id string) error }
IgnitionModel is an interface for ignition template.
type IgnitionTemplate ¶
type IgnitionTemplate struct { Version IgnitionVersion `json:"version"` Template json.RawMessage `json:"template"` Metadata map[string]interface{} `json:"meta"` }
IgnitionTemplate represents an ignition template. The exact type of Template is determined by Version.
type IgnitionVersion ¶
type IgnitionVersion string
IgnitionVersion represents the specification version of Ignition.
type Image ¶
type Image struct { ID string `json:"id"` Date time.Time `json:"date"` Size int64 `json:"size"` URLs []string `json:"urls"` Exists bool `json:"exists"` }
Image represents a set of image files for iPXE boot.
type ImageIndex ¶
type ImageIndex []*Image
ImageIndex is a list of *Image.
func (ImageIndex) Append ¶
func (i ImageIndex) Append(img *Image) (ImageIndex, []string)
Append appends a new *Image to the index.
If the index has MaxImages images, the oldest image will be discarded. ID of discarded images are returned in the second return value.
func (ImageIndex) Find ¶
func (i ImageIndex) Find(id string) *Image
Find an image whose ID is id.
If no image can be found, this returns nil.
func (ImageIndex) Remove ¶
func (i ImageIndex) Remove(id string) ImageIndex
Remove removes an image entry from the index.
type ImageModel ¶
type ImageModel interface { // These are for /api/v1/images GetIndex(ctx context.Context, os string) (ImageIndex, error) GetInfoAll(ctx context.Context) ([]*Image, error) Upload(ctx context.Context, os, id string, r io.Reader) error Download(ctx context.Context, os, id string, out io.Writer) error Delete(ctx context.Context, os, id string) error // This is for /api/v1/boot/OS/{kernel,initrd.gz} // Calling f will serve the content to the HTTP client. ServeFile(ctx context.Context, os, filename string, f func(modtime time.Time, content io.ReadSeeker)) error }
ImageModel is an interface to manage boot images.
type KernelParamsModel ¶
type KernelParamsModel interface { PutParams(ctx context.Context, os string, params string) error GetParams(ctx context.Context, os string) (string, error) }
KernelParamsModel is an interface for kernel parameters.
type LeaseRange ¶
LeaseRange is a range of IP addresses for DHCP lease.
type Machine ¶
type Machine struct { Spec MachineSpec `json:"spec"` Status MachineStatus `json:"status"` Info MachineInfo `json:"info"` }
Machine represents a server hardware.
func NewMachine ¶
func NewMachine(spec MachineSpec) *Machine
NewMachine creates a new machine instance.
func (*Machine) DeleteLabel ¶
DeleteLabel deletes label from Machine.
func (*Machine) PutLabel ¶ added in v2.4.3
PutLabel adds a label to Machine if no label with the same name exists, or replaces a label.
func (*Machine) SetState ¶
func (m *Machine) SetState(ms MachineState) error
SetState sets the state of the machine.
type MachineBMC ¶
type MachineBMC struct { IPv4 string `json:"ipv4"` IPv6 string `json:"ipv6"` Type string `json:"type"` }
MachineBMC is a bmc interface struct for Machine
type MachineInfo ¶
type MachineInfo struct { Network NetworkInfo `json:"network"` BMC BMCInfo `json:"bmc"` }
MachineInfo is a set of associated information of a Machine.
type MachineModel ¶
type MachineModel interface { Register(ctx context.Context, machines []*Machine) error Get(ctx context.Context, serial string) (*Machine, error) SetState(ctx context.Context, serial string, state MachineState) error PutLabel(ctx context.Context, serial string, label, value string) error DeleteLabel(ctx context.Context, serial string, label string) error SetRetireDate(ctx context.Context, serial string, date time.Time) error Query(ctx context.Context, query Query) ([]*Machine, error) Delete(ctx context.Context, serial string) error }
MachineModel is an interface for machine database.
type MachineSpec ¶
type MachineSpec struct { Serial string `json:"serial"` Labels map[string]string `json:"labels"` Rack uint `json:"rack"` IndexInRack uint `json:"index-in-rack"` Role string `json:"role"` IPv4 []string `json:"ipv4"` IPv6 []string `json:"ipv6"` RegisterDate time.Time `json:"register-date"` RetireDate time.Time `json:"retire-date"` BMC MachineBMC `json:"bmc"` }
MachineSpec is a set of attributes to define a machine.
type MachineState ¶
type MachineState string
MachineState represents a machine's state.
func (MachineState) GQLEnum ¶ added in v2.4.0
func (ms MachineState) GQLEnum() string
GQLEnum returns graphql defined enum string.
func (MachineState) IsValid ¶
func (ms MachineState) IsValid() bool
IsValid returns true only if the MachineState is pre-defined.
func (MachineState) String ¶
func (ms MachineState) String() string
String implements fmt.Stringer interface.
type MachineStatus ¶
type MachineStatus struct { Timestamp time.Time `json:"timestamp"` Duration float64 `json:"duration"` State MachineState `json:"state"` }
MachineStatus represents the status of a machine.
type Model ¶
type Model struct { Runner Storage StorageModel Machine MachineModel IPAM IPAMModel DHCP DHCPModel Image ImageModel Asset AssetModel Ignition IgnitionModel Log LogModel KernelParams KernelParamsModel Health HealthModel Schema SchemaModel }
Model is a struct that consists of sub-models.
type NICConfig ¶
type NICConfig struct { Address string `json:"address"` Netmask string `json:"netmask"` MaskBits int `json:"maskbits"` Gateway string `json:"gateway"` }
NICConfig represents NIC configuration information.
type NetworkInfo ¶
type NetworkInfo struct {
IPv4 []NICConfig `json:"ipv4"`
}
NetworkInfo represents NIC configurations.
type Query ¶
Query is an URL query
type Runner ¶
Runner is an interface to run the underlying goroutines.
The caller must pass a channel as follows. Receiving a value from the channel effectively guarantees that the driver gets ready.
ch := make(chan struct{}) well.Go(func(ctx context.Context) error { driver.Run(ctx, ch) }) <-ch
type SchemaModel ¶
type SchemaModel interface { Version(ctx context.Context) (string, error) Upgrade(ctx context.Context) error }
SchemaModel is an interface for schema versioning.
type StorageModel ¶
type StorageModel interface { GetEncryptionKey(ctx context.Context, serial string, diskByPath string) ([]byte, error) PutEncryptionKey(ctx context.Context, serial string, diskByPath string, key []byte) error DeleteEncryptionKeys(ctx context.Context, serial string) ([]string, error) }
StorageModel is an interface for disk encryption keys.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package e2e implements end-to-end test for sabakan.
|
Package e2e implements end-to-end test for sabakan. |
models
|
|
etcd
Package etcd implements sabakan model on etcd.
|
Package etcd implements sabakan model on etcd. |
mock
Package mock implements mockup sabakan model for testing.
|
Package mock implements mockup sabakan model for testing. |
mtest
|
|
pkg
|
|