Пример #1
0
func (lb *dummyLBInterface) DeleteVLAN(vlan *seesaw.VLAN) error {
	if _, ok := lb.vlans[vlan.Key()]; !ok {
		return fmt.Errorf("deleting non-existent VLAN: %v", vlan)
	}
	delete(lb.vlans, vlan.Key())
	return nil
}
Пример #2
0
// AddVLAN adds a VLAN to a Seesaw Cluster.
func (c *Cluster) AddVLAN(vlan *seesaw.VLAN) error {
	key := vlan.Key()
	if _, ok := c.VLANs[key]; ok {
		return fmt.Errorf("Cluster %q already contains VLAN %q", c.Site, key)
	}
	c.VLANs[key] = vlan
	return nil
}
Пример #3
0
func (lb *dummyLBInterface) AddVLAN(vlan *seesaw.VLAN) error {
	lb.vlans[vlan.Key()] = true
	return nil
}
Пример #4
0
func showVLANs(cli *SeesawCLI, args []string) error {
	if len(args) > 1 {
		fmt.Println("show vlans [<id>|<ip>]")
		return nil
	}

	vlans, err := cli.seesaw.VLANs()
	if err != nil {
		return fmt.Errorf("failed to get VLANs: %v", err)
	}

	if len(args) == 0 {
		// Display all VLANs.
		sort.Sort(vlans)
		printHdr("VLANs")
		for i, v := range vlans.VLANs {
			fmt.Printf("[%3d] VLAN ID %d - %s\n", i+1, v.ID, v.Hostname)
		}
		return nil
	}

	// Display details for a single VLAN (by ID or IP address).
	var vlan *seesaw.VLAN
	if id, err := strconv.ParseUint(args[0], 10, 16); err == nil {
		// By ID
		for _, v := range vlans.VLANs {
			if uint(v.ID) == uint(id) {
				vlan = v
				break
			}
		}
		if vlan == nil {
			return fmt.Errorf("VLAN ID %d not found", id)
		}
	} else if ip := net.ParseIP(args[0]); ip != nil {
		// By IP
		for _, v := range vlans.VLANs {
			if v.IPv4Net().Contains(ip) || v.IPv6Net().Contains(ip) {
				vlan = v
				break
			}
		}
		if vlan == nil {
			return fmt.Errorf("VLAN not found for IP address %v", ip)
		}
	} else {
		return fmt.Errorf("unknown value %q - must be a VLAN ID or IP address", args[0])
	}

	printHdr("VLAN")
	printVal("ID:", vlan.ID)
	printVal("Hostname:", vlan.Hostname)
	printFmt("IPv4 Address:", vlan.IPv4Printable())
	printFmt("IPv6 Address:", vlan.IPv6Printable())
	printVal("IPv4 Backend Count:", vlan.BackendCount[seesaw.IPv4])
	printVal("IPv6 Backend Count:", vlan.BackendCount[seesaw.IPv6])
	printVal("IPv4 VIP Count:", vlan.VIPCount[seesaw.IPv4])
	printVal("IPv6 VIP Count:", vlan.VIPCount[seesaw.IPv6])

	return nil
}