Skip to content

Commit b4f856b

Browse files
committed
Beautify output for dhcpserver commands
1 parent 0ecc6a6 commit b4f856b

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

cmd/dhcpserver/get.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ package dhcpserver
1717
import (
1818
"fmt"
1919

20-
"github.com/davecgh/go-spew/spew"
2120
"github.com/spf13/cobra"
2221
"k8s.io/klog/v2"
2322

2423
"github.com/ppc64le-cloud/pvsadm/pkg"
2524
"github.com/ppc64le-cloud/pvsadm/pkg/client"
25+
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
2626
)
2727

2828
var (
@@ -47,12 +47,18 @@ var getCmd = &cobra.Command{
4747
return err
4848
}
4949

50-
servers, err := pvmclient.DHCPClient.Get(id)
50+
server, err := pvmclient.DHCPClient.Get(id)
5151
if err != nil {
5252
return fmt.Errorf("failed to get a dhcpserver, err: %v", err)
5353
}
54-
55-
spew.Dump(servers)
54+
var IPandMAC string
55+
for _, lease := range server.Leases {
56+
IPandMAC += fmt.Sprintf("%s - %s ", *lease.InstanceIP, *lease.InstanceMacAddress)
57+
}
58+
table := utils.NewTable()
59+
table.SetHeader([]string{"ID", "IP - MAC", "Network Name", "Status"})
60+
table.Append([]string{*server.ID, IPandMAC, *server.Network.Name, *server.Status})
61+
table.Table.Render()
5662
return nil
5763
},
5864
}

cmd/dhcpserver/list.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@ var listCmd = &cobra.Command{
4949
}
5050

5151
table := utils.NewTable()
52-
table.Render(dhcpservers, nil)
52+
table.SetHeader([]string{"ID", "Network ID", "Network Name", "Status"})
53+
if len(dhcpservers) != 0 {
54+
for _, dhcpserver := range dhcpservers {
55+
if dhcpserver.Network.ID == nil || dhcpserver.Network.Name == nil {
56+
// just in case, if the network is not ready, and the DHCP status reports as BUILD.
57+
// printing the available information must suffice.
58+
table.Append([]string{*dhcpserver.ID, "", "", *dhcpserver.Status})
59+
continue
60+
}
61+
table.Append([]string{*dhcpserver.ID, *dhcpserver.Network.ID, *dhcpserver.Network.Name, *dhcpserver.Status})
62+
}
63+
table.Table.Render()
64+
return nil
65+
}
66+
klog.Info("There are no DHCP servers associated with the instance id provided.")
5367
return nil
5468
},
5569
}

0 commit comments

Comments
 (0)