mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
feat(images): 'uc image ls' and 'uc images' (alias) commands to list images on machines
This commit is contained in:
+20
-7
@@ -3,7 +3,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
@@ -70,15 +70,28 @@ func ProxyMachinesContext(
|
||||
}
|
||||
|
||||
var proxiedMachines MachineMembersList
|
||||
md := metadata.New(nil)
|
||||
for _, m := range machines {
|
||||
if len(namesOrIDs) == 0 ||
|
||||
slices.Contains(namesOrIDs, m.Machine.Name) || slices.Contains(namesOrIDs, m.Machine.Id) {
|
||||
var notFound []string
|
||||
for _, nameOrID := range namesOrIDs {
|
||||
if m := machines.FindByNameOrID(nameOrID); m != nil {
|
||||
proxiedMachines = append(proxiedMachines, m)
|
||||
machineIP, _ := m.Machine.Network.ManagementIp.ToAddr()
|
||||
md.Append("machines", machineIP.String())
|
||||
} else {
|
||||
notFound = append(notFound, nameOrID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(notFound) > 0 {
|
||||
return nil, nil, fmt.Errorf("machines not found: %s", strings.Join(notFound, ", "))
|
||||
}
|
||||
|
||||
if len(namesOrIDs) == 0 {
|
||||
proxiedMachines = machines
|
||||
}
|
||||
|
||||
md := metadata.New(nil)
|
||||
for _, m := range proxiedMachines {
|
||||
machineIP, _ := m.Machine.Network.ManagementIp.ToAddr()
|
||||
md.Append("machines", machineIP.String())
|
||||
}
|
||||
|
||||
return metadata.NewOutgoingContext(ctx, md), proxiedMachines, nil
|
||||
}
|
||||
|
||||
+8
-1
@@ -65,7 +65,13 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
|
||||
machineImages := make([]api.MachineImages, len(resp.Messages))
|
||||
for i, msg := range resp.Messages {
|
||||
machineImages[i].Metadata = msg.Metadata
|
||||
if msg.Metadata != nil {
|
||||
// TODO: handle this in the grpc-proxy router and always provide Metadata if possible.
|
||||
if msg.Metadata == nil {
|
||||
// Metadata can be nil if the request was broadcasted to only one machine.
|
||||
machineImages[i].Metadata = &pb.Metadata{
|
||||
Machine: machines[0].Machine.Id,
|
||||
}
|
||||
} else {
|
||||
// Replace management IP with machine ID for friendlier error messages.
|
||||
// TODO: migrate Metadata.Machine to use machine ID instead of IP in the grpc-proxy router.
|
||||
if m := machines.FindByManagementIP(msg.Metadata.Machine); m != nil {
|
||||
@@ -81,6 +87,7 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
|
||||
return nil, fmt.Errorf("unmarshal images: %w", err)
|
||||
}
|
||||
}
|
||||
machineImages[i].ContainerdStore = msg.ContainerdStore
|
||||
}
|
||||
|
||||
return machineImages, nil
|
||||
|
||||
Reference in New Issue
Block a user