Example #1
0
// Print group hierarchy starting at @g, using initial indentation @indent.
func printGroupIPs(client *clcv2.CLIClient, root *clcv2.Group) {
	var serverPrinter = func(g *clcv2.Group, arg interface{}) interface{} {
		var indent = arg.(string)

		if g.Type == "default" {
			fmt.Printf("%s%s/\n", indent, g.Name)
		} else {
			fmt.Printf("%s[%s]/\n", indent, g.Name)
		}

		for _, l := range g.Links {
			if l.Rel == "server" {
				ips, err := client.GetServerIPs(l.Id)
				if err != nil {
					exit.Fatalf("failed to get IPs of %q in %s: %s", l.Id, g.Name, err)
				}

				servLine := fmt.Sprintf("%s%s", indent+"    ", l.Id)
				fmt.Printf("%-50s %s\n", servLine, strings.Join(ips, ", "))
			}
		}
		return indent + "    "
	}
	clcv2.VisitGroupHierarchy(root, serverPrinter, "")
}
Example #2
0
// Show nested group details
// @client: authenticated CLCv2 Client
// @root:   root group node to start at
func showGroup(client *clcv2.CLIClient, root *clcv2.Group) {
	var groupPrinter = func(g *clcv2.Group, arg interface{}) interface{} {
		var indent = arg.(string)
		var groupLine string

		if g.Type == "default" {
			groupLine = fmt.Sprintf("%s%s/", indent, g.Name)
		} else {
			groupLine = fmt.Sprintf("%s[%s]/", indent, g.Name)
		}
		fmt.Printf("%-70s %s\n", groupLine, g.Id)

		/* Nested entries: */
		for _, l := range g.Links {
			if l.Rel == "server" {
				fmt.Printf("%s", indent+"    ")
				fmt.Printf("%s\n", l.Id)
			}
		}
		return indent + "    "
	}
	clcv2.VisitGroupHierarchy(root, groupPrinter, "")
}