Skip to content

Commit

Permalink
fixing the AAG show to print all instances name that attached to it.
Browse files Browse the repository at this point in the history
  • Loading branch information
elkezza committed Nov 11, 2024
1 parent 21f11ca commit 9d03e04
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cmd/anti_affinity_group_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
"strings"
)

type antiAffinityGroupShowOutput struct {
Expand Down Expand Up @@ -52,27 +50,29 @@ func (c *antiAffinityGroupShowCmd) cmdRun(_ *cobra.Command, _ []string) error {

antiAffinityGroupsResp, err := globalstate.EgoscaleV3Client.ListAntiAffinityGroups(ctx)
if err != nil {
return err
return fmt.Errorf("unable to retrieve list of anti-affinity %q: %w", err)

Check failure on line 53 in cmd/anti_affinity_group_show.go

View workflow job for this annotation

GitHub Actions / build

Printf format %w reads arg #2, but call has only 1 args (SA5009)
}

antiAffinityGroup, err := antiAffinityGroupsResp.FindAntiAffinityGroup(c.AntiAffinityGroup)
if err != nil {
return err
return fmt.Errorf("unable to find anti-affinity group %q: %w", c.AntiAffinityGroup, err)
}

out := antiAffinityGroupShowOutput{
ID: antiAffinityGroup.ID,
Name: antiAffinityGroup.Name,
Description: antiAffinityGroup.Description,
}

if antiAffinityGroup.Instances != nil {
out.Instances = make([]string, len(antiAffinityGroup.Instances))
for i, instance := range antiAffinityGroup.Instances {
out.Instances[i] = instance.Name
antiAffinityGroupWithInstanceDetails, err := globalstate.EgoscaleV3Client.GetAntiAffinityGroup(ctx, antiAffinityGroup.ID)
if err != nil {
return fmt.Errorf("unable to retrieve anti-affinity group with instance details %q: %w", c.AntiAffinityGroup, err)
}
if antiAffinityGroupWithInstanceDetails.Instances != nil {
out.Instances = make([]string, len(antiAffinityGroupWithInstanceDetails.Instances))
for i, instance := range antiAffinityGroupWithInstanceDetails.Instances {
out.Instances[i] = instance.ID.String()
}
}

return c.outputFunc(&out, nil)
}

Expand Down

0 comments on commit 9d03e04

Please sign in to comment.