Ejemplo n.º 1
0
// AddNode adds a Seesaw Node to a Seesaw Cluster.
func (c *Cluster) AddNode(node *seesaw.Node) error {
	key := node.Key()
	if _, ok := c.Nodes[key]; ok {
		return fmt.Errorf("Cluster %q already contains Node %q", c.Site, key)
	}
	c.Nodes[key] = node
	return nil
}
Ejemplo n.º 2
0
func showNode(cli *SeesawCLI, args []string) error {
	if len(args) > 1 {
		fmt.Println("show node <node>")
		return nil
	}

	cs, err := cli.seesaw.ClusterStatus()
	if err != nil {
		return fmt.Errorf("Failed to get cluster status: %v", err)
	}
	sort.Sort(seesaw.NodesByIPv4{cs.Nodes})
	if len(args) == 1 {
		nodeName := args[0]
		var node *seesaw.Node
		for _, n := range cs.Nodes {
			// TODO(baptr): Write a shared matcher implementation for show*.
			if n.Hostname == nodeName {
				node = n
				break
			}
		}
		if node == nil {
			return fmt.Errorf("node %q not found", nodeName)
		}
		printHdr("Node")
		printVal("Hostname:", node.Hostname)
		printVal("Site:", cs.Site)
		printVal("IPv4 Address:", node.IPv4Printable())
		printVal("IPv6 Address:", node.IPv6Printable())
		printVal("HA Enabled:", node.State != seesaw.HADisabled)
		printVal("Anycast Enabled:", node.AnycastEnabled)
		printVal("BGP Enabled:", node.BGPEnabled)
		printVal("Vservers Enabled:", node.VserversEnabled)
		return nil
	}
	printHdr("Nodes")
	for i, node := range cs.Nodes {
		enabled := "enabled"
		if node.State == seesaw.HADisabled {
			enabled = "disabled"
		}
		// TODO(baptr): Figure out how to identify/mark local node.
		fmt.Printf("[%d] %s %s\n", i+1, node.Hostname, enabled)
	}
	return nil
}