func printAppDetail(a App) { var output []string var outputEnv []string fields := structs.New(a).Fields() fmt.Println("\nApplication Details:") for _, f := range fields { if f.Name() == "Addresses" { output = append(output, fmt.Sprintf("%s:\n", f.Name())) for _, v := range a.Addresses { output = append(output, fmt.Sprintf("……|%s", v)) } } else if f.Name() == "Certificates" { output = append(output, fmt.Sprintf("%s:| Use \"--full\" to see certificates", f.Name())) output = append(output, fmt.Sprintf("– PrivateKey: |%s\n", a.Certificates["private_key"])) } else if f.Name() == "CreatedAt" { output = append(output, fmt.Sprintf("%s: | %s\n", f.Name(), utils.FormatTime(a.CreatedAt+"Z"))) } else if f.Name() == "CurrentDeployments" { output = append(output, fmt.Sprintf("%s:\n", f.Name())) for k, v := range a.CurrentDeployments { output = append(output, fmt.Sprintf("……|%s: %s", k, v)) } } else if f.Name() == "Environment" { outputEnv = append(outputEnv, fmt.Sprintf("%s:\n", f.Name())) for k, v := range a.Environment { outputEnv = append(outputEnv, fmt.Sprintf("%s=%s", k, v)) } } else if f.Name() == "Location" { output = append(output, fmt.Sprintf("%s: |Identifier: %s\t UUID: %s\n", f.Name(), a.Location["identifier"], a.Location["uuid"])) } else if f.Name() == "Metadata" { mdata, _ := json.Marshal(a.Metadata) output = append(output, fmt.Sprintf("%s: |%s\n", f.Name(), mdata)) } else if f.Name() == "Ports" { output = append(output, fmt.Sprintf("%s:\n", f.Name())) for _, v := range a.Ports { output = append(output, fmt.Sprintf("……|%s", v)) } } else if f.Name() == "Rules" { output = append(output, fmt.Sprintf("%s:\n", f.Name())) for k, v := range a.Rules { output = append(output, fmt.Sprintf("……|%s=%v", k, v)) } } else if f.Name() == "SSLPorts" { output = append(output, fmt.Sprintf("%s:\n", f.Name())) for _, v := range a.SSLPorts { output = append(output, fmt.Sprintf("……|%s", v)) } } else if f.Name() == "UpdatedAt" { output = append(output, fmt.Sprintf("%s: | %s\n", f.Name(), utils.FormatTime(a.UpdatedAt+"Z"))) } else { output = append(output, fmt.Sprintf("%s: |%v\n", f.Name(), f.Value())) } } fmt.Println(columnize.SimpleFormat(output)) fmt.Println("\n") fmt.Println(columnize.SimpleFormat(outputEnv)) }
func listRun(cmd *cobra.Command, args []string) { configDir, err := homedir.Expand(globalFlags.config) assert(err) machines, err := vm.List(configDir) assert(err) lines := []string{listHeader} for _, machine := range machines { var hds, nics []string for _, hd := range machine.HDs { hds = append(hds, fmt.Sprintf("%s %s", hd.Device, hd.Size)) } for _, nic := range machine.NICs { nics = append(nics, fmt.Sprintf("%s %s", nic.Bridge, nic.Mac)) } status, _ := machine.Status(listFlags.TMuxSessionName) lines = append(lines, fmt.Sprintf(listScheme, machine.Serial, machine.Image, machine.Memory, strings.Join(hds, ","), strings.Join(nics, ","), status)) } fmt.Println(columnize.SimpleFormat(lines)) }
func (c *AuthCommand) listMethods() int { client, err := c.Client() if err != nil { c.Ui.Error(fmt.Sprintf( "Error initializing client: %s", err)) return 1 } auth, err := client.Sys().ListAuth() if err != nil { c.Ui.Error(fmt.Sprintf( "Error reading auth table: %s", err)) return 1 } paths := make([]string, 0, len(auth)) for path := range auth { paths = append(paths, path) } sort.Strings(paths) columns := []string{"Path | Type | Description"} for _, k := range paths { a := auth[k] columns = append(columns, fmt.Sprintf( "%s | %s | %s", k, a.Type, a.Description)) } c.Ui.Output(columnize.SimpleFormat(columns)) return 0 }
func showInstances(cmd *cobra.Command, args []string) { requireProfile := false loadArgumentsFromCluster(cmd.Flags(), requireProfile) clusterInfoFromArgs(&instancesFlags, args) provider := newProvider() instancesFlags = provider.ClusterDefaults(instancesFlags) if instancesFlags.Name == "" { Exitf("Please specify a name\n") } instances, err := provider.GetInstances(instancesFlags) if err != nil { Exitf("Failed to list instances: %v\n", err) } clusterMembers, err := instances.AsClusterMemberList(log, nil) if err != nil { Exitf("Failed to fetch instance member data: %v\n", err) } lines := []string{"Name | Cluster IP | Public IP | Private IP | Machine ID | Options | Extra"} for _, i := range instances { cm, _ := clusterMembers.Find(i) // ignore errors options := []string{} if cm.EtcdProxy { options = append(options, "etcd-proxy") } lbIP := strings.TrimSpace(i.LoadBalancerIPv4 + " " + i.LoadBalancerIPv6) lines = append(lines, fmt.Sprintf("%s | %s | %s | %s | %s | %s | %s", i.Name, i.ClusterIP, lbIP, i.PrivateIP, cm.MachineID, strings.Join(options, ","), strings.Join(i.Extra, ","))) } result := columnize.SimpleFormat(lines) fmt.Println(result) }
func (p *cfProvider) ShowDomainRecords(domain string) error { id, err := p.zoneID(domain) if err != nil { return maskAny(err) } url := apiUrl + fmt.Sprintf("zones/%s/dns_records", id) res, err := p.get(url, "application/json") if err != nil { return maskAny(err) } records := []CfDnsRecord{} if err := res.UnmarshalResult(&records); err != nil { return maskAny(err) } lines := []string{ "Type | Name | Data", } for _, r := range records { line := fmt.Sprintf("%s | %s | %s", r.Type, trimLength(r.Name, 20), trimLength(r.Content, 60)) lines = append(lines, line) } sort.Strings(lines[1:]) result := columnize.SimpleFormat(lines) fmt.Println(result) return nil }
func (this *doProvider) ShowRegions() error { // Load regions client := NewDOClient(this.token) regions, err := RegionList(client) if err != nil { return err } lines := []string{ "Slug | Name | Features | Size", } for _, r := range regions { if !r.Available { continue } line := fmt.Sprintf("%s | %s | %s | %s", r.Slug, r.Name, strings.Join(r.Features, " "), strings.Join(r.Sizes, " ")) lines = append(lines, line) } sort.Strings(lines[1:]) result := columnize.SimpleFormat(lines) fmt.Println(result) return nil }
func showClusterInfo(cmd *cobra.Command, args []string) { requireProfile := false loadArgumentsFromCluster(cmd.Flags(), requireProfile) clusterInfoFromArgs(&clusterInfoFlags, args) provider := newProvider() clusterInfoFlags = provider.ClusterDefaults(clusterInfoFlags) if clusterInfoFlags.Name == "" { Exitf("Please specify a name\n") } instances, err := provider.GetInstances(clusterInfoFlags) if err != nil { Exitf("Failed to list instances: %v\n", err) } clusterMembers, err := instances.AsClusterMemberList(log, nil) if err != nil { Exitf("Failed to fetch instance member data: %v\n", err) } lines := []string{ fmt.Sprintf("ID | %s", clusterMembers[0].ClusterID), fmt.Sprintf("#Instances | %d", len(instances)), } result := columnize.SimpleFormat(lines) fmt.Println(result) }
func (this *Alias) Run(args []string) (exitCode int) { cmdFlags := flag.NewFlagSet("alias", flag.ContinueOnError) cmdFlags.Usage = func() { this.Ui.Output(this.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 } aliases := ctx.AliasesWithValue() sortedNames := make([]string, 0, len(aliases)) for name, _ := range aliases { sortedNames = append(sortedNames, name) } sort.Strings(sortedNames) lines := make([]string, 0, len(aliases)+1) header := "Alias|Command" lines = append(lines, header) for _, name := range sortedNames { lines = append(lines, fmt.Sprintf("%s|%s", name, aliases[name])) } fmt.Println(columnize.SimpleFormat(lines)) return }
func runInstances(args []string) (exit int) { if len(args) == 0 { return exitError("no Swarm given. Usage: kocho instances <swarm>") } else if len(args) > 1 { return exitError("too many arguments. Usage: kocho instances <swarm>") } swarmName := args[0] s, err := swarmService.Get(swarmName, swarm.AWS) if err != nil { return exitError(fmt.Sprintf("couldn't get instances of swarm: %s", swarmName), err) } instances, err := s.GetInstances() if err != nil { return exitError(fmt.Sprintf("couldn't get instances of swarm: %s", swarmName), err) } lines := []string{instancesHeader} for _, i := range instances { lines = append(lines, fmt.Sprintf(instancesScheme, i.Id, i.Image, i.Type, i.PublicDNSName, i.PrivateDNSName)) } fmt.Println(columnize.SimpleFormat(lines)) return 0 }
// SealStatus shows the seal status of the vault func (s *VaultService) SealStatus() error { m := sync.Mutex{} lines := []string{ "Address | Status | Key Threshold | Key Shares | Unseal Progress", } seal := func(client VaultClient) error { s.log.Debugf("Fetching seal status of vault at %s", client.Address) status, err := client.Client.Sys().SealStatus() var line string if err != nil { line = fmt.Sprintf("%s | error: %s | - | - | -", client.Address, err.Error()) } else { statusText := "unsealed" if status.Sealed { statusText = "sealed" } line = fmt.Sprintf("%s | %s | %d | %d | %d", client.Address, statusText, status.T, status.N, status.Progress) } m.Lock() defer m.Unlock() lines = append(lines, line) return nil } if err := s.asyncForEachClient(seal); err != nil { return maskAny(err) } fmt.Println(columnize.SimpleFormat(lines)) return nil }
func (this *Clusters) printSummary(zkzone *zk.ZkZone, clusterPattern string, port string) { lines := []string{"Zone|Cluster|Brokers|Topics|Partitions|FlatMsg|Cum"} type summary struct { zone, cluster string brokers, topics, partitions int flat, cum int64 } summaries := make([]summary, 0, 10) zkzone.ForSortedClusters(func(zkcluster *zk.ZkCluster) { if !patternMatched(zkcluster.Name(), clusterPattern) { return } brokers, topics, partitions, flat, cum := this.clusterSummary(zkcluster) summaries = append(summaries, summary{zkzone.Name(), zkcluster.Name(), brokers, topics, partitions, flat, cum}) }) sortutil.DescByField(summaries, "cum") var totalFlat, totalCum int64 for _, s := range summaries { lines = append(lines, fmt.Sprintf("%s|%s|%d|%d|%d|%s|%s", s.zone, s.cluster, s.brokers, s.topics, s.partitions, gofmt.Comma(s.flat), gofmt.Comma(s.cum))) totalCum += s.cum totalFlat += s.flat } this.Ui.Output(columnize.SimpleFormat(lines)) this.Ui.Output(fmt.Sprintf("Flat:%s Cum:%s", gofmt.Comma(totalFlat), gofmt.Comma(totalCum))) }
func statusRun(cmd *cobra.Command, args []string) { if len(args) != 1 { fmt.Println("Serial missing") os.Exit(1) } configDir, err := homedir.Expand(globalFlags.config) assert(err) machine, err := vm.Load(configDir, args[0]) assert(err) status, err := machine.Status(statusFlags.TMuxSessionName) assert(err) var hds, nics []string for _, hd := range machine.HDs { hds = append(hds, fmt.Sprintf("%s %s", hd.Device, hd.Size)) } for _, nic := range machine.NICs { nics = append(nics, fmt.Sprintf("%s %s", nic.Bridge, nic.Mac)) } lines := []string{} lines = append(lines, fmt.Sprintf(statusScheme, "Serial:", machine.Serial)) lines = append(lines, fmt.Sprintf(statusScheme, "Status:", status)) lines = append(lines, fmt.Sprintf(statusScheme, "Image:", machine.Image)) lines = append(lines, fmt.Sprintf("%s | %d", "Memory:", machine.Memory)) lines = append(lines, fmt.Sprintf(statusScheme, "HDs:", strings.Join(hds, ","))) lines = append(lines, fmt.Sprintf(statusScheme, "NICs:", strings.Join(nics, ","))) fmt.Println(columnize.SimpleFormat(lines)) }
func printAllocations(mesos *lib.Mesos) int { output := make([]string, 1) output[0] = "Hostname | Cpu % | Cpu Ratio | Mem % | Mem Ratio | Disk % | Disk Ratio" for _, s := range mesos.Cluster.Slaves { ss := s.Stats ln := fmt.Sprintf( "%s | %.0f | %.1f/%d | %.0f | %d/%d | %.0f| %d/%d", s.HostName, ss.CpusPercent*100, ss.CpusUsed, ss.CpusTotal, ss.MemPercent*100, ss.MemUsed, ss.MemTotal, ss.DiskPercent*100, ss.DiskUsed, ss.DiskTotal, ) output = append(output, ln) } result := columnize.SimpleFormat(output) fmt.Println(result) return 0 }
func listRun(cmd *cobra.Command, args []string) { if listFlags.Fields == "" { fmt.Printf("Invalid fields parameter. Please choose valid fields: %s\n", strings.Join(hostToFieldKeys(listFields), ",")) os.Exit(1) } cols := strings.Split(listFlags.Fields, ",") for _, s := range cols { if _, ok := listFields[s]; !ok { fmt.Printf("Invalid field: %q.\n\nUsage: %s\n", s, cmd.Usage()) os.Exit(1) } } hosts, err := mayu.List() assert(err) lines := []string{} for _, host := range hosts { var f []string for _, c := range cols { f = append(f, listFields[c](&host)) } lines = append(lines, strings.Join(f, "|")) } sort.Strings(lines) if !listFlags.NoLegend { lines = append([]string{strings.ToUpper(strings.Join(cols, "|"))}, lines...) } fmt.Println(columnize.SimpleFormat(lines)) }
func AppList(configStore *config.Store, env string) error { envs := []string{env} if env == "" { var err error envs, err = configStore.ListEnvs() if err != nil { return err } } columns := []string{"NAME | ENV | VERSION | IMAGE ID | CONFIG | POOLS "} for _, env := range envs { appList, err := configStore.ListApps(env) if err != nil { return err } pools, err := configStore.ListPools(env) if err != nil { return err } for _, app := range appList { name := app.Name() versionDeployed := app.Version() versionID := app.VersionID() if len(versionID) > 12 { versionID = versionID[:12] } assignments := []string{} for _, pool := range pools { aa, err := configStore.ListAssignments(env, pool) if err != nil { return err } if utils.StringInSlice(app.Name(), aa) { assignments = append(assignments, pool) } } columns = append(columns, strings.Join([]string{ name, env, versionDeployed, versionID, strconv.FormatInt(app.ID(), 10), strings.Join(assignments, ","), }, " | ")) } } output := columnize.SimpleFormat(columns) fmt.Println(output) return nil }
func (c *ServerMembersCommand) Run(args []string) int { var detailed bool flags := c.Meta.FlagSet("server-members", FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } flags.BoolVar(&detailed, "detailed", false, "Show detailed output") if err := flags.Parse(args); err != nil { return 1 } // Check for extra arguments args = flags.Args() if len(args) != 0 { c.Ui.Error(c.Help()) return 1 } // Get the HTTP client client, err := c.Meta.Client() if err != nil { c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) return 1 } // Query the members srvMembers, err := client.Agent().Members() if err != nil { c.Ui.Error(fmt.Sprintf("Error querying servers: %s", err)) return 1 } if srvMembers == nil { c.Ui.Error("Agent doesn't know about server members") return 0 } // Sort the members sort.Sort(api.AgentMembersNameSort(srvMembers.Members)) // Determine the leaders per region. leaders, err := regionLeaders(client, srvMembers.Members) if err != nil { c.Ui.Error(fmt.Sprintf("Error determining leaders: %s", err)) return 1 } // Format the list var out []string if detailed { out = detailedOutput(srvMembers.Members) } else { out = standardOutput(srvMembers.Members, leaders) } // Dump the list c.Ui.Output(columnize.SimpleFormat(out)) return 0 }
func RuntimeList(configStore *config.Store, app, env, pool string) error { envs := []string{env} if env == "" { var err error envs, err = configStore.ListEnvs() if err != nil { return err } } columns := []string{"ENV | NAME | POOL | PS | MEM | VHOSTS | PORT | MAINT"} for _, env := range envs { appList, err := configStore.ListApps(env) if err != nil { return err } for _, appCfg := range appList { if app != "" && appCfg.Name() != app { continue } for _, p := range appCfg.RuntimePools() { if pool != "" && p != pool { continue } name := appCfg.Name() ps := appCfg.GetProcesses(p) mem := appCfg.GetMemory(p) columns = append(columns, strings.Join([]string{ env, name, p, strconv.FormatInt(int64(ps), 10), mem, appCfg.Env()["VIRTUAL_HOST"], appCfg.Env()["GALAXY_PORT"], fmt.Sprint(appCfg.GetMaintenanceMode(p)), }, " | ")) } } } output := columnize.SimpleFormat(columns) fmt.Println(output) return nil }
func (c *MountsCommand) Run(args []string) int { flags := c.Meta.FlagSet("mounts", meta.FlagSetDefault) flags.Usage = func() { c.Ui.Error(c.Help()) } if err := flags.Parse(args); err != nil { return 1 } client, err := c.Client() if err != nil { c.Ui.Error(fmt.Sprintf( "Error initializing client: %s", err)) return 2 } mounts, err := client.Sys().ListMounts() if err != nil { c.Ui.Error(fmt.Sprintf( "Error reading mounts: %s", err)) return 2 } paths := make([]string, 0, len(mounts)) for path := range mounts { paths = append(paths, path) } sort.Strings(paths) columns := []string{"Path | Type | Default TTL | Max TTL | Description"} for _, path := range paths { mount := mounts[path] defTTL := "system" switch { case mount.Type == "system": defTTL = "n/a" case mount.Type == "cubbyhole": defTTL = "n/a" case mount.Config.DefaultLeaseTTL != 0: defTTL = strconv.Itoa(mount.Config.DefaultLeaseTTL) } maxTTL := "system" switch { case mount.Type == "system": maxTTL = "n/a" case mount.Type == "cubbyhole": maxTTL = "n/a" case mount.Config.MaxLeaseTTL != 0: maxTTL = strconv.Itoa(mount.Config.MaxLeaseTTL) } columns = append(columns, fmt.Sprintf( "%s | %s | %s | %s | %s", path, mount.Type, defTTL, maxTTL, mount.Description)) } c.Ui.Output(columnize.SimpleFormat(columns)) return 0 }
//PrintLocationBrief outputs a listing of locations with minimal details func PrintLocationBrief(l []location.Location) { var output []string output = append(output, fmt.Sprintf("Provider | Region")) for i := 0; i < len(l); i++ { output = append(output, fmt.Sprintf("%s | %s", l[i].Provider, l[i].Region)) } fmt.Println(columnize.SimpleFormat(output)) }
func PrintLocationBrief(l []pools.Location) { var output []string output = append(output, fmt.Sprintf("Location | Provider | UUID | Status")) for i := 0; i < len(l); i++ { output = append(output, fmt.Sprintf("%s | %s | %s| %s", l[i].Identifier, l[i].Provider, l[i].Uuid, l[i].Status)) } fmt.Println(columnize.SimpleFormat(output)) }
func HostsList(configStore *config.Store, env, pool string) error { envs := []string{env} if env == "" { var err error envs, err = configStore.ListEnvs() if err != nil { return err } } columns := []string{"ENV | POOL | HOST IP "} for _, env := range envs { var err error pools := []string{pool} if pool == "" { pools, err = configStore.ListPools(env) if err != nil { return err } } for _, pool := range pools { hosts, err := configStore.ListHosts(env, pool) if err != nil { return err } if len(hosts) == 0 { columns = append(columns, strings.Join([]string{ env, pool, "", }, " | ")) continue } for _, p := range hosts { columns = append(columns, strings.Join([]string{ env, pool, p.HostIP, }, " | ")) } } } output, _ := columnize.SimpleFormat(columns) log.Println(output) return nil }
func printSecretBrief(apps []*secrets.Secret) { var output []string output = append(output, fmt.Sprintf("UUID | Created At | Labels")) for i := 0; i < len(apps); i++ { output = append(output, fmt.Sprintf("%s | %s | %s", apps[i].Uuid, utils.FormatTime(apps[i].CreatedAt+"Z"), apps[i].Labels)) } fmt.Println(columnize.SimpleFormat(output)) }
func printDeploymentsBrief(d []deployments.Deployment) { var output []string output = append(output, fmt.Sprintf("UUID | Created At | Image Tag | Image Id")) for i := 0; i < len(d); i++ { output = append(output, fmt.Sprintf("%s | %s | %s | %s", d[i].Uuid, d[i].CreatedAt, d[i].ImageTag, d[i].ImageId)) } fmt.Println(columnize.SimpleFormat(output)) }
func Status(serviceRuntime *runtime.ServiceRuntime, configStore *config.Store, env, pool, hostIP string) error { containers, err := serviceRuntime.ManagedContainers() if err != nil { panic(err) } //FIXME: addresses, port, and expires missing in output columns := []string{ "APP | CONTAINER ID | IMAGE | EXTERNAL | INTERNAL | PORT | CREATED | EXPIRES"} for _, container := range containers { name := serviceRuntime.EnvFor(container)["GALAXY_APP"] registered, err := configStore.GetServiceRegistration( env, pool, hostIP, container) if err != nil { return err } if registered != nil { columns = append(columns, strings.Join([]string{ registered.Name, registered.ContainerID[0:12], registered.Image, registered.ExternalAddr(), registered.InternalAddr(), registered.Port, utils.HumanDuration(time.Now().UTC().Sub(registered.StartedAt)) + " ago", "In " + utils.HumanDuration(registered.Expires.Sub(time.Now().UTC())), }, " | ")) } else { columns = append(columns, strings.Join([]string{ name, container.ID[0:12], container.Image, "", "", "", utils.HumanDuration(time.Now().Sub(container.Created)) + " ago", "", }, " | ")) } } result, _ := columnize.SimpleFormat(columns) log.Println(result) return nil }
func (c *AuditListCommand) Run(args []string) int { flags := c.Meta.FlagSet("audit-list", FlagSetDefault) flags.Usage = func() { c.Ui.Error(c.Help()) } if err := flags.Parse(args); err != nil { return 1 } client, err := c.Client() if err != nil { c.Ui.Error(fmt.Sprintf( "Error initializing client: %s", err)) return 2 } audits, err := client.Sys().ListAudit() if err != nil { c.Ui.Error(fmt.Sprintf( "Error reading audits: %s", err)) return 2 } if len(audits) == 0 { c.Ui.Error(fmt.Sprintf( "No audit backends are enabled. Use `vault audit-enable` to\n" + "enable an audit backend.")) return 1 } paths := make([]string, 0, len(audits)) for path, _ := range audits { paths = append(paths, path) } sort.Strings(paths) columns := []string{"Type | Description | Options"} for _, path := range paths { audit := audits[path] opts := make([]string, 0, len(audit.Options)) for k, v := range audit.Options { opts = append(opts, k+"="+v) } columns = append(columns, fmt.Sprintf( "%s | %s | %s", audit.Type, audit.Description, strings.Join(opts, " "))) } c.Ui.Output(columnize.SimpleFormat(columns)) return 0 }
func (c MemberContainer) String() string { var result []string for _, member := range c.Members { tags := strings.Join(agent.MarshalTags(member.Tags), ",") line := fmt.Sprintf("%s|%s|%s|%s", member.Name, member.Addr, member.Status, tags) if member.detail { line += fmt.Sprintf( "|Protocol Version: %d|Available Protocol Range: [%d, %d]", member.Proto["version"], member.Proto["min"], member.Proto["max"]) } result = append(result, line) } return columnize.SimpleFormat(result) }
func PrintLocationBrief(l []pools.Location, showAll bool) { var output []string output = append(output, fmt.Sprintf("Location | Provider | UUID | Status | Aggregrate Resources")) for i := 0; i < len(l); i++ { if showAll { output = append(output, fmt.Sprintf("%s | %s | %s| %s| %v vCPU, %vGB RAM", l[i].Identifier, l[i].Provider, l[i].Uuid, l[i].Status, l[i].AggregateResources["cpu"], l[i].AggregateResources["ram"])) } else if strings.ToLower(string(l[i].Status)) != "archived" { output = append(output, fmt.Sprintf("%s | %s | %s| %s| %v vCPU, %vGB RAM", l[i].Identifier, l[i].Provider, l[i].Uuid, l[i].Status, l[i].AggregateResources["cpu"], l[i].AggregateResources["ram"])) } } fmt.Println(columnize.SimpleFormat(output)) }
// TODO: shouldn't the command cmd be printing the output, and not the package? // The app, config, host, and runtime sections all do this too. (otherwise we // should just combine the two packages). And why do we print the output here, // but print the error in main??? func ListPools(configStore *config.Store, env string) error { var envs []string var err error if env != "" { envs = []string{env} } else { envs, err = configStore.ListEnvs() if err != nil { return err } } columns := []string{"ENV | POOL | APPS "} for _, env := range envs { pools, err := configStore.ListPools(env) if err != nil { return fmt.Errorf("ERROR: cannot list pools: %s", err) } if len(pools) == 0 { columns = append(columns, strings.Join([]string{ env, "", ""}, " | ")) continue } for _, pool := range pools { assigments, err := configStore.ListAssignments(env, pool) if err != nil { fmt.Printf("ERROR: cannot list pool assignments for %s/%s: %s", env, pool, err) } columns = append(columns, strings.Join([]string{ env, pool, strings.Join(assigments, ",")}, " | ")) } } fmt.Println(columnize.SimpleFormat(columns)) return nil }
func runList(args []string) (exit int) { if len(args) > 0 { return exitError("too many arguments") } swarms, err := swarmService.List() if err != nil { return exitError("couldn't list swarms", err) } lines := []string{swarmListHeader} for _, s := range swarms { lines = append(lines, fmt.Sprintf(swarmListScheme, s.Name, s.Type, s.Created.Format(time.RFC822))) } fmt.Println(columnize.SimpleFormat(lines)) return 0 }
func printAppBrief(a []App, showAll bool) { var output []string output = append(output, fmt.Sprintf("Name | UUID | Status | Location | Ports | SSL Ports | Rules")) for i := 0; i < len(a); i++ { if showAll { output = append(output, fmt.Sprintf("%s | %s | %s | %s | %s | %s | %s", a[i].Name, a[i].UUID, a[i].Status, a[i].Location["identifier"], fmtPorts(a[i].Ports), fmtPorts(a[i].SSLPorts), fmtRules(a[i].Rules))) } else if strings.ToLower(string(a[i].Status)) != "archived" { output = append(output, fmt.Sprintf("%s | %s | %s | %s | %s | %s | %s", a[i].Name, a[i].UUID, a[i].Status, a[i].Location["identifier"], fmtPorts(a[i].Ports), fmtPorts(a[i].SSLPorts), fmtRules(a[i].Rules))) } } fmt.Println(columnize.SimpleFormat(output)) }