Add cloud venue scout: EC2 IMDS tags infer batch/spot/gpu biomes for persona packs and weather.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled

This commit is contained in:
AetherForge
2026-06-07 10:01:47 -07:00
parent 903d180db6
commit bb7bbe6c97
11 changed files with 343 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package api
import ("encoding/json"; "net/http"; "time"; fleetai "crypto-miner-server/internal/ai")
type CloudVenueHandler struct{ hub *WSHub }
func NewCloudVenueHandler(hub *WSHub)*CloudVenueHandler{return &CloudVenueHandler{hub:hub}}
func (h *CloudVenueHandler) GetVenues(w http.ResponseWriter,_ *http.Request){ if h.hub==nil{writeJSON(w,map[string]interface{}{"biomes":[]fleetai.CloudVenueBiome{}});return}; writeJSON(w,map[string]interface{}{"biomes":h.hub.cloudVenueSnapshot(),"generated_at":time.Now().UTC().Format(time.RFC3339)})}
func (h *WSHub) ensureCloudVenues(){ if h.cloudVenues==nil{h.cloudVenues=fleetai.NewCloudVenueRegistry()} }
func (h *WSHub) cloudVenueSnapshot()[]fleetai.CloudVenueBiome{ h.cloudVenueMu.Lock(); defer h.cloudVenueMu.Unlock(); h.ensureCloudVenues(); return h.cloudVenues.Snapshot() }
func (h *WSHub) cloudVenueForAgent(agentID string)*fleetai.CloudVenueBiome{ h.cloudVenueMu.Lock(); defer h.cloudVenueMu.Unlock(); h.ensureCloudVenues(); return h.cloudVenues.ForAgent(agentID) }
func (h *WSHub) ingestCloudVenueReport(agentID string, report fleetai.CloudVenueReport){ h.cloudVenueMu.Lock(); defer h.cloudVenueMu.Unlock(); h.ensureCloudVenues(); report.AgentID=agentID; b,c:=h.cloudVenues.Record(report,time.Now().UTC()); if !c{return}; h.broadcastCloudVenuesLocked(); h.pushCloudVenuePolicyLocked(b) }
func (h *WSHub) broadcastCloudVenuesLocked(){ h.broadcastDashboard(Message{Type:"cloud_venue_biomes",Payload:mustMarshal(map[string]interface{}{"biomes":h.cloudVenues.Snapshot(),"generated_at":time.Now().UTC().Format(time.RFC3339)})}) }
func (h *WSHub) pushCloudVenuePolicyLocked(biome fleetai.CloudVenueBiome){ sp:=fleetai.BuildCloudVenueSpreadPolicy(biome); t:=fleetai.PersonaSpreadTemperament(biome.PersonaPack); pol:=FleetAgentPolicy{SpreadTemperament:&t}; for _,id:=range biome.AgentIDs{ payload:=marshalPolicyUpdatePayload("cloud-venue-"+biome.BiomeKey,pol); var body map[string]interface{}; _=json.Unmarshal(payload,&body); if body==nil{body=map[string]interface{}{}}; body["spread_policy"]=sp; out,_:=json.Marshal(body); _=h.SendToAgent(id,Message{Type:"policy_update",Payload:out}) } }
func (h *WSHub) cloudVenueSpreadPolicyForAuth(agentID string)map[string]interface{}{ c:=h.cloudVenueForAgent(agentID); if c==nil{return nil}; return fleetai.BuildCloudVenueSpreadPolicy(*c) }

View File

@@ -0,0 +1,3 @@
package api
import ("testing"; fleetai "crypto-miner-server/internal/ai"; "crypto-miner-server/internal/db")
func TestCloudVenueIngest(t *testing.T){ dbi,e:=db.New(t.TempDir()); if e!=nil{t.Fatal(e)}; t.Cleanup(func(){_=dbi.Close()}); h:=NewWSHub(dbi); h.ingestCloudVenueReport("a",fleetai.CloudVenueReport{InstanceType:"g4dn.xlarge",OrganizationalUnit:"ou/gpu"}); if len(h.cloudVenueSnapshot())!=1{t.Fatal()} }