Files
virtual-kubelet/vendor/github.com/docker/libnetwork/idm/idm.go
Loc Nguyen 513cebe7b7 VMware vSphere Integrated Containers provider (#206)
* Add Virtual Kubelet provider for VIC

Initial virtual kubelet provider for VMware VIC.  This provider currently
handles creating and starting of a pod VM via the VIC portlayer and persona
server.  Image store handling via the VIC persona server.  This provider
currently requires the feature/wolfpack branch of VIC.

* Added pod stop and delete.  Also added node capacity.

Added the ability to stop and delete pod VMs via VIC.  Also retrieve
node capacity information from the VCH.

* Cleanup and readme file

Some file clean up and added a Readme.md markdown file for the VIC
provider.

* Cleaned up errors, added function comments, moved operation code

1. Cleaned up error handling.  Set standard for creating errors.
2. Added method prototype comments for all interface functions.
3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder.

* Add mocking code and unit tests for podcache, podcreator, and podstarter

Used the unit test framework used in VIC to handle assertions in the provider's
unit test.  Mocking code generated using OSS project mockery, which is compatible
with the testify assertion framework.

* Vendored packages for the VIC provider

Requires feature/wolfpack branch of VIC and a few specific commit sha of
projects used within VIC.

* Implementation of POD Stopper and Deleter unit tests (#4)

* Updated files for initial PR
2018-06-04 15:41:32 -07:00

61 lines
1.5 KiB
Go

// Package idm manages reservation/release of numerical ids from a configured set of contiguous ids
package idm
import (
"fmt"
"github.com/docker/libnetwork/bitseq"
"github.com/docker/libnetwork/datastore"
)
// Idm manages the reservation/release of numerical ids from a contiguos set
type Idm struct {
start uint64
end uint64
handle *bitseq.Handle
}
// New returns an instance of id manager for a set of [start-end] numerical ids
func New(ds datastore.DataStore, id string, start, end uint64) (*Idm, error) {
if id == "" {
return nil, fmt.Errorf("Invalid id")
}
if end <= start {
return nil, fmt.Errorf("Invalid set range: [%d, %d]", start, end)
}
h, err := bitseq.NewHandle("idm", ds, id, 1+end-start)
if err != nil {
return nil, fmt.Errorf("failed to initialize bit sequence handler: %s", err.Error())
}
return &Idm{start: start, end: end, handle: h}, nil
}
// GetID returns the first available id in the set
func (i *Idm) GetID() (uint64, error) {
if i.handle == nil {
return 0, fmt.Errorf("ID set is not initialized")
}
ordinal, err := i.handle.SetAny()
return i.start + ordinal, err
}
// GetSpecificID tries to reserve the specified id
func (i *Idm) GetSpecificID(id uint64) error {
if i.handle == nil {
return fmt.Errorf("ID set is not initialized")
}
if id < i.start || id > i.end {
return fmt.Errorf("Requested id does not belong to the set")
}
return i.handle.Set(id - i.start)
}
// Release releases the specified id
func (i *Idm) Release(id uint64) {
i.handle.Unset(id - i.start)
}