feat: alive UI wave, galaxy presence, spread and fleet enhancements
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Dashboard ambient layer, comrade presence, Mission Deck and War Room, Emberwake supply chain, spread/docs publishing, fleet policy and modules API, CI docker mining, and refreshed USB pack.
This commit is contained in:
59
server/internal/api/fleet_agent_policy.go
Normal file
59
server/internal/api/fleet_agent_policy.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FleetAgentPolicy is runtime mining/policy pushed to agents without re-forge.
|
||||
type FleetAgentPolicy struct {
|
||||
MiningMode string `json:"mining_mode,omitempty"`
|
||||
ScheduleStart string `json:"schedule_start,omitempty"`
|
||||
ScheduleEnd string `json:"schedule_end,omitempty"`
|
||||
MaxCPUUsagePct int `json:"max_cpu_usage_pct,omitempty"`
|
||||
PoolHost string `json:"pool_host,omitempty"`
|
||||
PoolPort int `json:"pool_port,omitempty"`
|
||||
PoolTLS *bool `json:"pool_tls,omitempty"`
|
||||
PoolPass string `json:"pool_pass,omitempty"`
|
||||
}
|
||||
|
||||
func (p FleetAgentPolicy) IsEmpty() bool {
|
||||
var zero FleetAgentPolicy
|
||||
return p == zero
|
||||
}
|
||||
|
||||
func normalizeFleetAgentPolicy(p FleetAgentPolicy) FleetAgentPolicy {
|
||||
p.MiningMode = strings.TrimSpace(strings.ToLower(p.MiningMode))
|
||||
p.ScheduleStart = strings.TrimSpace(p.ScheduleStart)
|
||||
p.ScheduleEnd = strings.TrimSpace(p.ScheduleEnd)
|
||||
p.PoolHost = strings.TrimSpace(p.PoolHost)
|
||||
p.PoolPass = strings.TrimSpace(p.PoolPass)
|
||||
if p.MaxCPUUsagePct < 0 {
|
||||
p.MaxCPUUsagePct = 0
|
||||
}
|
||||
if p.MaxCPUUsagePct > 100 {
|
||||
p.MaxCPUUsagePct = 100
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func marshalFleetPolicyPayload(p FleetAgentPolicy) json.RawMessage {
|
||||
return mustMarshal(normalizeFleetAgentPolicy(p))
|
||||
}
|
||||
|
||||
// marshalPolicyUpdatePayload attaches push_id so dashboards can correlate agent acks.
|
||||
func marshalPolicyUpdatePayload(pushID string, p FleetAgentPolicy) json.RawMessage {
|
||||
norm := normalizeFleetAgentPolicy(p)
|
||||
if pushID == "" {
|
||||
return mustMarshal(norm)
|
||||
}
|
||||
body, _ := json.Marshal(norm)
|
||||
var flat map[string]interface{}
|
||||
_ = json.Unmarshal(body, &flat)
|
||||
if flat == nil {
|
||||
flat = map[string]interface{}{}
|
||||
}
|
||||
flat["push_id"] = pushID
|
||||
out, _ := json.Marshal(flat)
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user