예제 #1
0
파일: clc_action.go 프로젝트: grrtrr/clcv1
// Show server details
// @client:    authenticated CLCv1 Client
// @servname:  server name
// @acctAlias: account alias to use (leave blank to use default)
func showServer(client *clcv1.Client, servname, acctAlias string) {
	server, err := client.GetServer(servname, acctAlias)
	if err != nil {
		exit.Fatalf("Failed to list details of server %q: %s", servname, err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(true)

	table.SetHeader([]string{
		"Name", "Power", "Status",
		"OS", "Description",
		"CPU", "Disk",
		"IP", "Last Change",
	})

	/* Also display public IP address(es) if configured. */
	IPs := []string{server.IPAddress}
	for _, ip := range server.IPAddresses {
		if ip.IsPublic() {
			IPs = append([]string{ip.Address}, IPs...)
		}
	}

	modifiedStr := humanize.Time(server.DateModified.Time)
	/* The ModifiedBy field can be an email address, or an API Key (hex string) */
	if _, err := hex.DecodeString(server.ModifiedBy); err == nil {
		modifiedStr += " via API Key"
	} else if len(server.ModifiedBy) > 6 {
		modifiedStr += " by " + server.ModifiedBy[:6]
	} else {
		modifiedStr += " by " + server.ModifiedBy
	}

	table.Append([]string{
		server.Name, server.PowerState, server.Status,
		fmt.Sprint(server.OperatingSystem),
		server.Description,
		fmt.Sprint(server.Cpu), fmt.Sprintf("%dGB", server.TotalDiskSpaceGB),
		strings.Join(IPs, " "),
		modifiedStr,
	})
	table.Render()
}
예제 #2
0
파일: clc_action.go 프로젝트: grrtrr/clcv1
// Show group details
// @client:    authenticated CLCv1 Client
// @uuid:      hardware group UUID to use
// @acctAlias: account alias to use (leave blank to use default)
// @location:  data centre location (needed to resolve @uuid)
func showGroup(client *clcv1.Client, uuid, acctAlias, location string) {
	if location == "" {
		exit.Errorf("Location is required in order to show the group hierarchy starting at %s", uuid)
	}
	root, err := client.GetGroupHierarchy(location, acctAlias, true)
	if err != nil {
		exit.Fatalf("Failed to look up groups at %s: %s", location, err)
	}
	start := root
	if uuid != "" {
		start = clcv1.FindGroupNode(root, func(g *clcv1.GroupNode) bool {
			return g.UUID == uuid
		})
		if start == nil {
			exit.Fatalf("Failed to look up UUID %s at %s", uuid, location)
		}
	}
	clcv1.PrintGroupHierarchy(start, "")
}