feat: add volume, images and networks

This commit is contained in:
2026-05-18 19:30:33 +02:00
parent 4f53aefb6e
commit bd3121d688
10 changed files with 1221 additions and 208 deletions

View File

@ -178,6 +178,91 @@ func (h *Handler) ContainerAction(w http.ResponseWriter, r *http.Request) {
jsonOK(w, map[string]string{"command_id": cmdID})
}
// ── Images ────────────────────────────────────────────────────────────────────
func (h *Handler) ListImages(w http.ResponseWriter, r *http.Request) {
type imageDTO struct {
AgentID string `json:"agent_id"`
Hostname string `json:"hostname"`
Alias string `json:"alias"`
ID string `json:"id"`
Tags []string `json:"tags"`
Size int64 `json:"size"`
CreatedAt int64 `json:"created_at"`
}
var out []imageDTO
for _, agent := range h.registry.List() {
for _, img := range agent.Images {
out = append(out, imageDTO{
AgentID: agent.ID,
Hostname: agent.Hostname,
Alias: agent.Alias,
ID: img.GetId(),
Tags: img.GetTags(),
Size: img.GetSize(),
CreatedAt: img.GetCreatedAt(),
})
}
}
jsonOK(w, out)
}
// ── Volumes ───────────────────────────────────────────────────────────────────
func (h *Handler) ListVolumes(w http.ResponseWriter, r *http.Request) {
type volumeDTO struct {
AgentID string `json:"agent_id"`
Hostname string `json:"hostname"`
Alias string `json:"alias"`
Name string `json:"name"`
Driver string `json:"driver"`
Mountpoint string `json:"mountpoint"`
}
var out []volumeDTO
for _, agent := range h.registry.List() {
for _, vol := range agent.Volumes {
out = append(out, volumeDTO{
AgentID: agent.ID,
Hostname: agent.Hostname,
Alias: agent.Alias,
Name: vol.GetName(),
Driver: vol.GetDriver(),
Mountpoint: vol.GetMountpoint(),
})
}
}
jsonOK(w, out)
}
// ── Networks ──────────────────────────────────────────────────────────────────
func (h *Handler) ListNetworks(w http.ResponseWriter, r *http.Request) {
type networkDTO struct {
AgentID string `json:"agent_id"`
Hostname string `json:"hostname"`
Alias string `json:"alias"`
ID string `json:"id"`
Name string `json:"name"`
Driver string `json:"driver"`
Scope string `json:"scope"`
}
var out []networkDTO
for _, agent := range h.registry.List() {
for _, net := range agent.Networks {
out = append(out, networkDTO{
AgentID: agent.ID,
Hostname: agent.Hostname,
Alias: agent.Alias,
ID: net.GetId(),
Name: net.GetName(),
Driver: net.GetDriver(),
Scope: net.GetScope(),
})
}
}
jsonOK(w, out)
}
// ── Agent token provisioning ──────────────────────────────────────────────────
func (h *Handler) CreateAgentToken(w http.ResponseWriter, r *http.Request) {