From cbdfaf8dace500655c75dc2fbee8fca7da46c926 Mon Sep 17 00:00:00 2001 From: "Alexander J. Maidak" Date: Fri, 2 Aug 2024 16:20:06 -0500 Subject: [PATCH] table columns for IPv4/v6 public/private addresses --- internal/devices/retrieve.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/devices/retrieve.go b/internal/devices/retrieve.go index 1d22425f..f0d7a70a 100644 --- a/internal/devices/retrieve.go +++ b/internal/devices/retrieve.go @@ -24,7 +24,6 @@ import ( "context" "fmt" "strconv" - "strings" "github.com/equinix/equinix-sdk-go/services/metalv1" "github.com/spf13/cobra" @@ -98,15 +97,17 @@ func (c *Client) Retrieve() *cobra.Command { data := make([][]string, len(devices)) for i, dc := range devices { - ips := make([]string, 0) + ipAddresses := make(map[string]string) for _, ip := range dc.GetIpAddresses() { if ip.Address != nil { - ips = append(ips, *ip.Address) + key := fmt.Sprintf("ipv%d_%s", ip.GetAddressFamily(), + map[bool]string{true: "public", false: "private"}[ip.GetPublic()]) + ipAddresses[key] = ip.GetAddress() } } - data[i] = []string{dc.GetId(), dc.GetHostname(), strings.Join(ips, ","), dc.OperatingSystem.GetName(), fmt.Sprintf("%v", dc.GetState()), dc.GetCreatedAt().String()} + data[i] = []string{dc.GetId(), dc.GetHostname(), ipAddresses["ipv4_public"], ipAddresses["ipv6_public"], ipAddresses["ipv4_private"], dc.OperatingSystem.GetName(), fmt.Sprintf("%v", dc.GetState()), dc.GetCreatedAt().String()} } - header := []string{"ID", "Hostname", "IPs", "OS", "State", "Created"} + header := []string{"ID", "Hostname", "IPv4 Public", "IPv6 Public", "IPv4 Private", "OS", "State", "Created"} return c.Out.Output(devices, header, &data) },