Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anti-affinity group: fix a bug in the "show" command to list all attached instances from different zones #649

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- Storage: handle errors in batch objects delete action #627
- Instance: Fix instance protection flag update zone context #648
- Anti-affinity group: fix show command to print all the attached instances from different zones #649

## 1.80.0

Expand Down
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 groups: %w", err)
}

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
6 changes: 3 additions & 3 deletions cmd/iam_api_key_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
)

type iamAPIKeyShowOutput struct {
Name string `json:"name"`
Key string `json:"key"`
Secret string `json:"secret"`
Name string `json:"name"`
Key string `json:"key"`
Secret string `json:"secret"`
Role v3.UUID `json:"role-id"`
}

Expand Down
Loading