mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
strip one proto layer in ListMachines method
This commit is contained in:
+3
-3
@@ -225,12 +225,12 @@ func (cli *CLI) AddMachine(ctx context.Context, remoteMachine RemoteMachine, clu
|
||||
}
|
||||
|
||||
// List other machines in the cluster to include them in the join request.
|
||||
listResp, err := c.ListMachines(ctx, &emptypb.Empty{})
|
||||
machines, err := c.ListMachines(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("list cluster machines: %w", err)
|
||||
}
|
||||
otherMachines := make([]*pb.MachineInfo, 0, len(listResp.Machines)-1)
|
||||
for _, m := range listResp.Machines {
|
||||
otherMachines := make([]*pb.MachineInfo, 0, len(machines)-1)
|
||||
for _, m := range machines {
|
||||
if m.Machine.Id != addResp.Machine.Id {
|
||||
otherMachines = append(otherMachines, m.Machine)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"uncloud/internal/machine/api/pb"
|
||||
)
|
||||
|
||||
func (cli *Client) ListMachines(ctx context.Context) ([]*pb.MachineMember, error) {
|
||||
resp, err := cli.ClusterClient.ListMachines(ctx, &emptypb.Empty{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Machines, nil
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"slices"
|
||||
"strings"
|
||||
"uncloud/internal/machine/api/pb"
|
||||
@@ -52,7 +51,7 @@ func (cli *Client) RunService(ctx context.Context, opts *ServiceOptions) (RunSer
|
||||
}
|
||||
|
||||
// Find a machine to run the service on.
|
||||
listResp, err := cli.ListMachines(ctx, &emptypb.Empty{})
|
||||
machines, err := cli.ListMachines(ctx)
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("list machines: %w", err)
|
||||
}
|
||||
@@ -60,7 +59,7 @@ func (cli *Client) RunService(ctx context.Context, opts *ServiceOptions) (RunSer
|
||||
var machine *pb.MachineMember
|
||||
if opts.Machine != "" {
|
||||
// Check if the machine ID or name exists if it's explicitly specified.
|
||||
for _, m := range listResp.Machines {
|
||||
for _, m := range machines {
|
||||
if m.Machine.Name == opts.Machine || m.Machine.Id == opts.Machine {
|
||||
machine = m
|
||||
break
|
||||
@@ -70,7 +69,7 @@ func (cli *Client) RunService(ctx context.Context, opts *ServiceOptions) (RunSer
|
||||
return resp, fmt.Errorf("machine %q not found", opts.Machine)
|
||||
}
|
||||
} else {
|
||||
machine, err = firstAvailableMachine(listResp.Machines)
|
||||
machine, err = firstAvailableMachine(machines)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user