Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #308 from albertomurillo/instance_list
Browse files Browse the repository at this point in the history
ciao-cli: reduce the output of ciao-cli instance list
  • Loading branch information
Samuel Ortiz authored Jun 23, 2016
2 parents 21de96b + be73bad commit 58559fb
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions ciao-cli/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"net/http"
"os"
"text/tabwriter"

"github.com/01org/ciao/payloads"
)
Expand Down Expand Up @@ -279,6 +280,7 @@ type instanceListCommand struct {
limit int
cn string
tenant string
detail bool
}

func (cmd *instanceListCommand) usage(...string) {
Expand All @@ -294,6 +296,7 @@ The list flags are:
}

func (cmd *instanceListCommand) parseArgs(args []string) []string {
cmd.Flag.BoolVar(&cmd.detail, "detail", false, "Print detailed information about each instance")
cmd.Flag.StringVar(&cmd.workload, "workload", "", "Workload UUID")
cmd.Flag.StringVar(&cmd.cn, "cn", "", "Computer node to list instances from (default to all nodes when empty)")
cmd.Flag.StringVar(&cmd.marker, "marker", "", "Show instance list starting from the next instance after marker")
Expand Down Expand Up @@ -355,18 +358,40 @@ func (cmd *instanceListCommand) run(args []string) error {
fatalf(err.Error())
}

w := new(tabwriter.Writer)
if !cmd.detail {
w.Init(os.Stdout, 0, 1, 1, ' ', 0)
fmt.Fprintln(w, "#\tUUID\tStatus\tPrivate IP\tSSH IP\tSSH PORT")
}

for i, server := range servers.Servers {
fmt.Printf("Instance #%d\n", i+1)
fmt.Printf("\tUUID: %s\n", server.ID)
fmt.Printf("\tStatus: %s\n", server.Status)
fmt.Printf("\tPrivate IP: %s\n", server.Addresses.Private[0].Addr)
fmt.Printf("\tMAC Address: %s\n", server.Addresses.Private[0].OSEXTIPSMACMacAddr)
fmt.Printf("\tCN UUID: %s\n", server.HostID)
fmt.Printf("\tImage UUID: %s\n", server.Image.ID)
fmt.Printf("\tTenant UUID: %s\n", server.TenantID)
if server.SSHIP != "" {
fmt.Printf("\tSSH IP: %s\n", server.SSHIP)
fmt.Printf("\tSSH Port: %d\n", server.SSHPort)
if !cmd.detail {
fmt.Fprintf(w, "%d", i+1)
fmt.Fprintf(w, "\t%s", server.ID)
fmt.Fprintf(w, "\t%s", server.Status)
fmt.Fprintf(w, "\t%s", server.Addresses.Private[0].Addr)
if server.SSHIP != "" {
fmt.Fprintf(w, "\t%s", server.SSHIP)
fmt.Fprintf(w, "\t%d\n", server.SSHPort)
} else {
fmt.Fprintf(w, "\tN/A")
fmt.Fprintf(w, "\tN/A\n")
}

w.Flush()
} else {
fmt.Printf("Instance #%d\n", i+1)
fmt.Printf("\tUUID: %s\n", server.ID)
fmt.Printf("\tStatus: %s\n", server.Status)
fmt.Printf("\tPrivate IP: %s\n", server.Addresses.Private[0].Addr)
fmt.Printf("\tMAC Address: %s\n", server.Addresses.Private[0].OSEXTIPSMACMacAddr)
fmt.Printf("\tCN UUID: %s\n", server.HostID)
fmt.Printf("\tImage UUID: %s\n", server.Image.ID)
fmt.Printf("\tTenant UUID: %s\n", server.TenantID)
if server.SSHIP != "" {
fmt.Printf("\tSSH IP: %s\n", server.SSHIP)
fmt.Printf("\tSSH Port: %d\n", server.SSHPort)
}
}
}
return nil
Expand Down

0 comments on commit 58559fb

Please sign in to comment.