Skip to content

Commit 5de9dd8

Browse files
committed
cmd: show resource type instead of NAME
1 parent 3c8285a commit 5de9dd8

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export PGSSLMODE=disable
259259

260260
* CLI: Rolling updates
261261
* CLI: Support resource update via YAML file
262+
* CLI: Support CloudStack projects
262263
* CLI: Multi-zone deployments
263264
* CLI: Security group improvements
264265
* CLI/Controller: Support reconciling resources

pkg/handlers/print.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"text/tabwriter"
9+
"time"
910

1011
v1 "cloudstackctl/apis/v1"
1112

@@ -31,7 +32,7 @@ func PrintCloudStackResource(kind string, obj any) error {
3132
case "VirtualMachine":
3233
if resp, ok := obj.(*cs.ListVirtualMachinesResponse); ok {
3334
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
34-
fmt.Fprintln(w, "NAME\tID\tTEMPLATE\tSERVICE OFFERING\tSTATUS")
35+
fmt.Fprintln(w, "VIRTUAL MACHINE\tID\tTEMPLATE\tSERVICE OFFERING\tSTATUS")
3536
for _, v := range resp.VirtualMachines {
3637
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", v.Name, v.Id, v.Templatename, v.Serviceofferingname, v.State)
3738
}
@@ -41,7 +42,7 @@ func PrintCloudStackResource(kind string, obj any) error {
4142
case "Template":
4243
if resp, ok := obj.(*cs.ListTemplatesResponse); ok {
4344
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
44-
fmt.Fprintln(w, "NAME\tID\tOS\tFEATURED")
45+
fmt.Fprintln(w, "TEMPLATE\tID\tOS\tFEATURED")
4546
for _, t := range resp.Templates {
4647
fmt.Fprintf(w, "%s\t%s\t%s\t%t\n", t.Name, t.Id, t.Ostypename, t.Isfeatured)
4748
}
@@ -51,7 +52,7 @@ func PrintCloudStackResource(kind string, obj any) error {
5152
case "SSHKey":
5253
if resp, ok := obj.(*cs.ListSSHKeyPairsResponse); ok {
5354
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
54-
fmt.Fprintln(w, "NAME\tFINGERPRINT")
55+
fmt.Fprintln(w, "SSH KEY\tFINGERPRINT")
5556
for _, k := range resp.SSHKeyPairs {
5657
fmt.Fprintf(w, "%s\t%s\n", k.Name, k.Fingerprint)
5758
}
@@ -61,7 +62,7 @@ func PrintCloudStackResource(kind string, obj any) error {
6162
case "SecurityGroup":
6263
if resp, ok := obj.(*cs.ListSecurityGroupsResponse); ok {
6364
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
64-
fmt.Fprintln(w, "NAME\tID\tDESCRIPTION")
65+
fmt.Fprintln(w, "SECURITY GROUP\tID\tDESCRIPTION")
6566
for _, sg := range resp.SecurityGroups {
6667
fmt.Fprintf(w, "%s\t%s\t%s\n", sg.Name, sg.Id, sg.Description)
6768
}
@@ -71,7 +72,7 @@ func PrintCloudStackResource(kind string, obj any) error {
7172
case "AffinityGroup":
7273
if resp, ok := obj.(*cs.ListAffinityGroupsResponse); ok {
7374
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
74-
fmt.Fprintln(w, "NAME\tID\tDESCRIPTION")
75+
fmt.Fprintln(w, "AFFINITY GROUP\tID\tDESCRIPTION")
7576
for _, a := range resp.AffinityGroups {
7677
fmt.Fprintf(w, "%s\t%s\t%s\n", a.Name, a.Id, a.Description)
7778
}
@@ -81,9 +82,9 @@ func PrintCloudStackResource(kind string, obj any) error {
8182
case "UserData":
8283
if resp, ok := obj.(*cs.ListUserDataResponse); ok {
8384
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
84-
fmt.Fprintln(w, "NAME\tID\tPROJECT\tACCOUNT")
85+
fmt.Fprintln(w, "USERDATA\tID\tACCOUNT")
8586
for _, u := range resp.UserData {
86-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", u.Name, u.Id, u.Project, u.Account)
87+
fmt.Fprintf(w, "%s\t%s\t%s\n", u.Name, u.Id, u.Account)
8788
}
8889
w.Flush()
8990
return nil
@@ -99,7 +100,7 @@ func PrintCloudStackResource(kind string, obj any) error {
99100
// PrintVolumes prints a table of volumes.
100101
func PrintVolumes(vols []*cs.Volume) {
101102
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
102-
fmt.Fprintln(w, "NAME\tID\tVM\tTYPE\tSTATUS")
103+
fmt.Fprintln(w, "VOLUME\tID\tVIRTUAL MACHINE\tTYPE\tSTATUS")
103104
for _, v := range vols {
104105
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", v.Name, v.Id, v.Vmname, v.Type, v.State)
105106
}
@@ -109,7 +110,7 @@ func PrintVolumes(vols []*cs.Volume) {
109110
// PrintNetworks prints a table of networks.
110111
func PrintNetworks(nets []*cs.Network) {
111112
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
112-
fmt.Fprintln(w, "NAME\tID\tZONE\tVLAN\tDISPLAY TEXT\tTYPE\tSTATE")
113+
fmt.Fprintln(w, "NETWORK\tID\tZONE\tVLAN\tDISPLAY TEXT\tTYPE\tSTATE")
113114
client, _ := cloudstack.NewClient()
114115

115116
for _, n := range nets {
@@ -148,7 +149,7 @@ func PrintNetworks(nets []*cs.Network) {
148149
// PrintVMsFromController prints VMs returned by the controller query.
149150
func PrintVMsFromController(vms []v1.VirtualMachine) {
150151
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
151-
fmt.Fprintln(w, "NAME\tAPPLICATION\tCOMPONENT\tID\tTEMPLATE\tSERVICE OFFERING\tSTATUS\tREADY\tDRIFT")
152+
fmt.Fprintln(w, "VIRTUAL MACHINE\tAPPLICATION\tCOMPONENT\tID\tTEMPLATE\tSERVICE OFFERING\tSTATUS\tREADY\tDRIFT")
152153
for _, vm := range vms {
153154
id := vm.CloudStackID
154155
tmpl := vm.Spec.Template
@@ -177,23 +178,27 @@ func PrintVMsFromController(vms []v1.VirtualMachine) {
177178
// PrintComponents prints components returned by the controller DB query.
178179
func PrintComponents(comps []v1.Component) {
179180
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
180-
fmt.Fprintln(w, "NAME\tAPPLICATION\tREPLICAS\tVM SPEC\tSTATE\tOBSERVED REPLICAS")
181+
fmt.Fprintln(w, "COMPONENT\tAPPLICATION\tREPLICAS\tVM SPEC\tSTATE\tOBSERVED REPLICAS\tLAST CHECKED")
181182

182183
for _, c := range comps {
183184
replicas := c.Spec.Replicas
184185
vmSpec := c.Spec.VirtualMachineSpec
185186
observed := c.ObservedReplicas
186187
state := c.Status.ObservedState
187188
appNames := c.Application
188-
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%d\n", c.Metadata.Name, appNames, replicas, vmSpec, state, observed)
189+
last := ""
190+
if !c.Status.LastChecked.IsZero() {
191+
last = c.Status.LastChecked.Format(time.RFC3339)
192+
}
193+
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%d\t%s\n", c.Metadata.Name, appNames, replicas, vmSpec, state, observed, last)
189194
}
190195
w.Flush()
191196
}
192197

193198
// PrintVMSpecs prints VirtualMachineSpecResource entries in a compact table.
194199
func PrintVMSpecs(specs []v1.VirtualMachineSpecResource) {
195200
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
196-
fmt.Fprintln(w, "NAME\tTEMPLATE\tSERVICE OFFERING\tNETWORKS\tVOLUMES")
201+
fmt.Fprintln(w, "VM SPEC\tTEMPLATE\tSERVICE OFFERING\tNETWORKS\tVOLUMES")
197202
for _, s := range specs {
198203
tmpl := s.Spec.Template
199204
so := s.Spec.ServiceOffering
@@ -220,7 +225,7 @@ func PrintVMSpecs(specs []v1.VirtualMachineSpecResource) {
220225
// PrintApplications prints applications returned by the controller DB query.
221226
func PrintApplications(apps []v1.Application) {
222227
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
223-
fmt.Fprintln(w, "NAME\tCOMPONENTS\tPROJECT\tSTATE\tREADY")
228+
fmt.Fprintln(w, "APPLICATION\tCOMPONENTS\tSTATE\tREADY\tLAST CHECKED")
224229
for _, a := range apps {
225230
compNames := ""
226231
if len(a.Spec.Components) > 0 {
@@ -229,8 +234,11 @@ func PrintApplications(apps []v1.Application) {
229234
compNames += "," + a.Spec.Components[i].Name
230235
}
231236
}
232-
project := a.Spec.Project
233-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%t\n", a.Metadata.Name, compNames, project, a.Status.ObservedState, a.Status.Ready)
237+
last := ""
238+
if !a.Status.LastChecked.IsZero() {
239+
last = a.Status.LastChecked.Format(time.RFC3339)
240+
}
241+
fmt.Fprintf(w, "%s\t%s\t%s\t%t\t%s\n", a.Metadata.Name, compNames, a.Status.ObservedState, a.Status.Ready, last)
234242
}
235243
w.Flush()
236244
}

0 commit comments

Comments
 (0)