mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-28 02:19:35 +00:00
* Use YAML group config to match machine labels to groups of zero or more machines sharing a Specification * Discontinue using machine.json resources representations which are repetitive, don't support groups, and don't allow label matching * Previous "default" special case now handled by a Group with an empty matcher
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Spec is a named group of configs.
|
|
type Spec struct {
|
|
// spec identifier
|
|
ID string `json:"id"`
|
|
// boot kernel, initrd, and kernel options
|
|
BootConfig *BootConfig `json:"boot"`
|
|
// cloud config id
|
|
CloudConfig string `json:"cloud_id"`
|
|
// ignition config id
|
|
IgnitionConfig string `json:"ignition_id"`
|
|
}
|
|
|
|
// specResource serves Spec resources by id.
|
|
type specResource struct {
|
|
store Store
|
|
}
|
|
|
|
func newSpecResource(mux *http.ServeMux, pattern string, store Store) {
|
|
gr := &specResource{
|
|
store: store,
|
|
}
|
|
mux.Handle(pattern, logRequests(requireGET(gr)))
|
|
}
|
|
|
|
func (r *specResource) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
id := filepath.Base(req.URL.Path)
|
|
spec, err := r.store.Spec(id)
|
|
if err != nil {
|
|
http.NotFound(w, req)
|
|
return
|
|
}
|
|
renderJSON(w, spec)
|
|
}
|
|
|
|
// getMatchingSpec returns the Spec matching the given attributes. Attributes
|
|
// are matched in priority order (UUID, MAC, default).
|
|
func getMatchingSpec(store Store, labels Labels) (*Spec, error) {
|
|
groups := newGroupsResource(store)
|
|
group, err := groups.findMatch(labels)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return store.Spec(group.Spec)
|
|
}
|