Skip to content

Commit

Permalink
affinitygroup: enrich show and list (#107)
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
greut authored and pierre-emmanuelJ committed Mar 1, 2019
1 parent 18f172e commit c11a123
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.9
-----

- feature: affinitygroup show
- fix: no panics when the config is made via env variables only

1.0.8
-----

Expand Down
10 changes: 8 additions & 2 deletions cmd/affinitygroup_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"strconv"

"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
Expand All @@ -28,10 +29,15 @@ func displayAffinitygroup() error {
affinityGroups := resp.(*egoscale.ListAffinityGroupsResponse).AffinityGroup

table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Name", "Description", "ID"})
table.SetHeader([]string{"Name", "Description", "Size", "ID"})

for _, affinitygroup := range affinityGroups {
table.Append([]string{affinitygroup.Name, affinitygroup.Description, affinitygroup.ID.String()})
table.Append([]string{
affinitygroup.Name,
affinitygroup.Description,
strconv.Itoa(len(affinitygroup.VirtualMachineIDs)),
affinitygroup.ID.String(),
})
}

table.Render()
Expand Down
16 changes: 15 additions & 1 deletion cmd/affinitygroup_show.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"fmt"
"os"
"text/tabwriter"

"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
Expand All @@ -27,17 +29,29 @@ func showAffinityGroup(name string) error {
return err
}

w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)

fmt.Fprintf(w, "Affinity Group:\t%s\n", ag.Name) // nolint: errcheck
fmt.Fprintf(w, "ID:\t%s\n", ag.ID) // nolint: errcheck
fmt.Fprintf(w, "Description:\t%s\n", ag.Description) // nolint: errcheck
fmt.Fprintf(w, "Type:\t%s\n", ag.Type) // nolint: errcheck

if len(ag.VirtualMachineIDs) == 0 {
fmt.Fprintf(w, "VirtualMachines:\tn/a\n") // nolint: errcheck
w.Flush()
return nil
}

fmt.Fprintf(w, "VirtualMachines:\n") // nolint: errcheck
w.Flush()

resp, err := cs.ListWithContext(gContext, &egoscale.ListVirtualMachines{IDs: ag.VirtualMachineIDs})
if err != nil {
return err
}

table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Instance Display Name", "Instance ID"})
table.SetHeader([]string{"Name", "ID"})

for _, r := range resp {
vm := r.(*egoscale.VirtualMachine)
Expand Down

0 comments on commit c11a123

Please sign in to comment.