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

Beautify output for dhcpserver commands #592

Merged
merged 1 commit into from
Apr 23, 2024
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
18 changes: 14 additions & 4 deletions cmd/dhcpserver/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package dhcpserver
import (
"fmt"

"github.com/davecgh/go-spew/spew"
"github.com/spf13/cobra"
"k8s.io/klog/v2"

"github.com/ppc64le-cloud/pvsadm/pkg"
"github.com/ppc64le-cloud/pvsadm/pkg/client"
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
)

var (
Expand All @@ -47,12 +47,22 @@ var getCmd = &cobra.Command{
return err
}

servers, err := pvmclient.DHCPClient.Get(id)
server, err := pvmclient.DHCPClient.Get(id)
if err != nil {
return fmt.Errorf("failed to get a dhcpserver, err: %v", err)
}

spew.Dump(servers)
if server.Network.Name == nil {
klog.Infof("DHCP client reports status: %s, please retry in sometime.", *server.Status)
return nil
}
var IPandMAC string
for _, lease := range server.Leases {
IPandMAC += fmt.Sprintf("%s-%s\n", *lease.InstanceIP, *lease.InstanceMacAddress)
}
table := utils.NewTable()
table.SetHeader([]string{"Network Name", "IP - MAC", "Status"})
table.Append([]string{*server.Network.Name, IPandMAC, *server.Status})
table.Table.Render()
return nil
},
}
Expand Down
18 changes: 17 additions & 1 deletion cmd/dhcpserver/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,24 @@ var listCmd = &cobra.Command{
return fmt.Errorf("failed to get the networks, err: %v", err)
}

if len(dhcpservers) == 0 {
klog.Info("There are no DHCP servers associated with the instance id provided.")
return nil
}

table := utils.NewTable()
table.Render(dhcpservers, nil)
table.SetHeader([]string{"ID", "Network ID", "Network Name", "Status"})
for _, dhcpserver := range dhcpservers {
if dhcpserver.Network.ID == nil || dhcpserver.Network.Name == nil {
// just in case, if the network is not ready, and the DHCP status reports as BUILD.
// printing the available information must suffice.
table.Append([]string{*dhcpserver.ID, "", "", *dhcpserver.Status})
continue
}
table.Append([]string{*dhcpserver.ID, *dhcpserver.Network.ID, *dhcpserver.Network.Name, *dhcpserver.Status})
}
table.Table.Render()
return nil

},
}
Loading