Initial implementation: host lifecycle + PXE + admin dashboard
Go service for Proxmox homelab cluster provisioning. Handles PXE boot, Proxmox autoinstall (answer file generation), cluster join via SSH, and Infrastructure API registration. - Host state machine (registered → pxe_ready → installing → ready) - dnsmasq supervisor with MAC-based allowlist - iPXE script and Proxmox answer file generation - First-boot phone-home → cluster join → infra registration - Operation locking with expiry (409 on conflict) - SSE event hub for real-time dashboard updates - Admin dashboard (host grid, detail, registration form) - Config-driven server types with hot-reload - Docker deployment (multi-stage fat image) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package orchestrator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"provisioning/internal/events"
|
||||
"provisioning/internal/model"
|
||||
"provisioning/internal/statemachine"
|
||||
"provisioning/internal/store"
|
||||
)
|
||||
|
||||
type Runner struct {
|
||||
Hosts *store.Hosts
|
||||
Ops *store.Operations
|
||||
Locks *store.Locks
|
||||
Hub *events.Hub
|
||||
}
|
||||
|
||||
func (r *Runner) Transition(ctx context.Context, hostID int64, trigger statemachine.Trigger) (model.HostState, error) {
|
||||
host, err := r.Hosts.Get(ctx, hostID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("transition: get host: %w", err)
|
||||
}
|
||||
next, err := statemachine.Next(host.State, trigger)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("transition: %w", err)
|
||||
}
|
||||
if err := r.Hosts.UpdateState(ctx, hostID, next); err != nil {
|
||||
return "", fmt.Errorf("transition: update state: %w", err)
|
||||
}
|
||||
log.Printf("host %d (%s): %s -> %s [%s]", hostID, host.Hostname, host.State, next, trigger)
|
||||
r.Hub.Publish(events.Event{
|
||||
Name: "host.state_changed",
|
||||
Payload: fmt.Sprintf(`{"host_id":%d,"old_state":"%s","new_state":"%s"}`, hostID, host.State, next),
|
||||
})
|
||||
return next, nil
|
||||
}
|
||||
|
||||
func (r *Runner) FailHost(ctx context.Context, hostID int64, reason string) {
|
||||
if _, err := r.Transition(ctx, hostID, statemachine.TriggerFailed); err != nil {
|
||||
log.Printf("host %d: failed to transition to failed state: %v", hostID, err)
|
||||
return
|
||||
}
|
||||
op, err := r.Ops.GetActive(ctx, hostID)
|
||||
if err == nil {
|
||||
_ = r.Ops.Fail(ctx, op.ID, reason)
|
||||
}
|
||||
_ = r.Locks.Release(ctx, hostID)
|
||||
}
|
||||
Reference in New Issue
Block a user