Beispiel #1
0
func (n VipMngr) Sync(state state.State) error {
	log.Debug("[vip] Syncing")
	currentVips, err := n.getCurrentVips()
	if err != nil {
		return err
	}

	stateVips := n.getStateVips(state)

	vipsToAdd := stateVips.Difference(currentVips)
	vipsToRemove := currentVips.Difference(stateVips)

	for v := range vipsToAdd.Iter() {
		vip := v.(string)
		err := net.AddIp(vip+"/32", n.iface)
		if err != nil {
			return fmt.Errorf("[vip] Error adding ip %s: %s", vip, err)
		}
		log.Debugf("[vip] Added: %s/32 to interface: %s", vip, n.iface)
	}

	for v := range vipsToRemove.Iter() {
		vip := v.(string)
		err := net.DelIp(vip+"/32", n.iface)
		if err != nil {
			return fmt.Errorf("[vip] Error deleting ip %s: %s", vip, err)
		}
		log.Debugf("[vip] Removed: %s/32 from interface: %s", vip, n.iface)
	}

	return nil
}
Beispiel #2
0
func (s *NetSuite) TestDelIp(c *C) {
	err := net.AddIp("192.168.0.1/32", "lo")
	c.Assert(err, IsNil)

	err = net.DelIp("192.168.0.1/32", "lo")
	c.Assert(err, IsNil)

	addrs, err := net.GetVips(s.iface)
	c.Assert(err, IsNil)

	deleted := true
	for _, a := range addrs {
		if a.IPNet.String() == "192.168.0.1/32" {
			deleted = false
		}
	}

	c.Assert(deleted, Equals, true)
}