Merge pull request #1547 from mavenugo/vxidm

IDM need not be bound by default vxlan-id start index
This commit is contained in:
Alessandro Boch 2016-11-09 15:22:06 -08:00 committed by GitHub
commit 96f001e6ed
2 changed files with 15 additions and 2 deletions

View file

@ -57,7 +57,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
config: config,
}
d.vxlanIdm, err = idm.New(nil, "vxlan-id", vxlanIDStart, vxlanIDEnd)
d.vxlanIdm, err = idm.New(nil, "vxlan-id", 1, vxlanIDEnd)
if err != nil {
return fmt.Errorf("failed to initialize vxlan id manager: %v", err)
}
@ -164,7 +164,7 @@ func (n *network) obtainVxlanID(s *subnet) error {
n.Unlock()
if vni == 0 {
vni, err = n.driver.vxlanIdm.GetID()
vni, err = n.driver.vxlanIdm.GetIDInRange(vxlanIDStart, vxlanIDEnd)
if err != nil {
return err
}

View file

@ -54,6 +54,19 @@ func (i *Idm) GetSpecificID(id uint64) error {
return i.handle.Set(id - i.start)
}
// GetIDInRange returns the first available id in the set within a range
func (i *Idm) GetIDInRange(start, end uint64) (uint64, error) {
if i.handle == nil {
return 0, fmt.Errorf("ID set is not initialized")
}
if start < i.start || end > i.end {
return 0, fmt.Errorf("Requested range does not belong to the set")
}
return i.handle.SetAnyInRange(start, end-start)
}
// Release releases the specified id
func (i *Idm) Release(id uint64) {
i.handle.Unset(id - i.start)