Accept applied/reverted/failed in device status reports
This commit is contained in:
@@ -103,6 +103,48 @@ type Device struct {
|
||||
// ReachablePrefixes is the device's FIB as last reported by its agent
|
||||
// (server-managed). The compiler uses it to scope router enforcement.
|
||||
ReachablePrefixes []string `json:"reachable_prefixes,omitempty"`
|
||||
|
||||
// AgentStatus is the agent's last apply report (server-managed).
|
||||
AgentStatus *AgentStatus `json:"agent_status,omitempty"`
|
||||
}
|
||||
|
||||
// ApplyStatus is the outcome an agent reports for a generation.
|
||||
type ApplyStatus string
|
||||
|
||||
const (
|
||||
StatusApplied ApplyStatus = "applied"
|
||||
StatusReverted ApplyStatus = "reverted"
|
||||
StatusFailed ApplyStatus = "failed"
|
||||
)
|
||||
|
||||
// StatusReport is the agent's POST /devices/{name}/status body. An empty
|
||||
// Status (pre-status agents sending only generation) means applied.
|
||||
type StatusReport struct {
|
||||
Status ApplyStatus `json:"status,omitempty"`
|
||||
Generation int64 `json:"generation"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// Normalize defaults an empty Status to applied and rejects unknown values.
|
||||
func (r *StatusReport) Normalize() error {
|
||||
switch r.Status {
|
||||
case "":
|
||||
r.Status = StatusApplied
|
||||
case StatusApplied, StatusReverted, StatusFailed:
|
||||
default:
|
||||
return fmt.Errorf("invalid status %q: want applied, reverted or failed", r.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AgentStatus is a device's stored apply state. AppliedGeneration only advances
|
||||
// on applied reports; Status/Generation/Error/ReportedAt mirror the last report.
|
||||
type AgentStatus struct {
|
||||
AppliedGeneration int64 `json:"applied_generation"`
|
||||
Status ApplyStatus `json:"status"`
|
||||
Generation int64 `json:"generation"`
|
||||
Error string `json:"error,omitempty"`
|
||||
ReportedAt time.Time `json:"reported_at"`
|
||||
}
|
||||
|
||||
// Binding maps a global zone to one device's local interface(s).
|
||||
|
||||
Reference in New Issue
Block a user