本文整理汇总了Golang中github.com/contiv/netplugin/netmaster/resources.GetStateResourceManager函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStateResourceManager函数的具体用法?Golang GetStateResourceManager怎么用?Golang GetStateResourceManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetStateResourceManager函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AllocVXLAN
// AllocVXLAN allocates a new vxlan; ids for both the vxlan and vlan are returned.
func (gc *Cfg) AllocVXLAN(reqVxlan uint) (vxlan uint, localVLAN uint, err error) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return 0, 0, err
}
ra := core.ResourceManager(tempRm)
g := &Oper{}
g.StateDriver = gc.StateDriver
err = g.Read("")
if err != nil {
return 0, 0, err
}
if reqVxlan != 0 && reqVxlan <= g.FreeVXLANsStart {
return 0, 0, errors.New("Requested vxlan is out of range")
}
if (reqVxlan != 0) && (reqVxlan >= g.FreeVXLANsStart) {
reqVxlan = reqVxlan - g.FreeVXLANsStart
}
pair, err1 := ra.AllocateResourceVal("global", resources.AutoVXLANResource, reqVxlan)
if err1 != nil {
return 0, 0, err1
}
vxlan = pair.(resources.VXLANVLANPair).VXLAN + g.FreeVXLANsStart
localVLAN = pair.(resources.VXLANVLANPair).VLAN
return
}
示例2: FreeVLAN
// FreeVLAN releases a VLAN for a given ID.
func (gc *Cfg) FreeVLAN(vlan uint) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
return ra.DeallocateResourceVal("global", resources.AutoVLANResource, vlan)
}
示例3: Process
// Process validates, implements, and writes the state.
func (gc *Cfg) Process(res string) error {
var err error
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
err = gc.checkErrors(res)
if err != nil {
return core.Errorf("process failed on error checks %s", err)
}
// Only define a vlan resource if a valid range was specified
if res == "vlan" {
if gc.Auto.VLANs != "" {
var vlanRsrcCfg *bitset.BitSet
vlanRsrcCfg, err = gc.initVLANBitset(gc.Auto.VLANs)
if err != nil {
return err
}
err = ra.DefineResource("global", resources.AutoVLANResource, vlanRsrcCfg)
if err != nil {
return err
}
}
}
// Only define a vxlan resource if a valid range was specified
var freeVXLANsStart uint
if res == "vxlan" {
if gc.Auto.VXLANs != "" {
var vxlanRsrcCfg *resources.AutoVXLANCfgResource
vxlanRsrcCfg, freeVXLANsStart, err = gc.initVXLANBitset(gc.Auto.VXLANs)
if err != nil {
return err
}
err = ra.DefineResource("global", resources.AutoVXLANResource, vxlanRsrcCfg)
if err != nil {
return err
}
}
g := &Oper{FreeVXLANsStart: freeVXLANsStart}
g.StateDriver = gc.StateDriver
err = g.Write()
if err != nil {
log.Errorf("error '%s' updating global oper state %v \n", err, g)
return err
}
}
log.Debugf("updating the global config to new state %v \n", gc)
return nil
}
示例4: GetVlansInUse
// GetVlansInUse gets the vlans that are currently in use
func (gc *Cfg) GetVlansInUse() (uint, string) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
log.Errorf("error getting resource manager: %s", err)
return 0, ""
}
ra := core.ResourceManager(tempRm)
return ra.GetResourceList("global", resources.AutoVLANResource)
}
示例5: AllocVLAN
// AllocVLAN allocates a new VLAN resource. Returns an ID.
func (gc *Cfg) AllocVLAN(reqVlan uint) (uint, error) {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return 0, err
}
ra := core.ResourceManager(tempRm)
vlan, err := ra.AllocateResourceVal("global", resources.AutoVLANResource, reqVlan)
if err != nil {
log.Errorf("alloc vlan failed: %q", err)
return 0, err
}
return vlan.(uint), err
}
示例6: UpdateResources
// UpdateResources deletes associated resources
func (gc *Cfg) UpdateResources(res string) error {
log.Infof("Received update resource for res %s", res)
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
err = gc.checkErrors(res)
if err != nil {
return core.Errorf("process failed on error checks %s", err)
}
if res == "vlan" {
var vlanRsrcCfg *bitset.BitSet
vlanRsrcCfg, err = gc.initVLANBitset(gc.Auto.VLANs)
if err != nil {
return err
}
err = ra.RedefineResource("global", resources.AutoVLANResource, vlanRsrcCfg)
if err != nil {
log.Errorf("Error deleting vlan resource. Err: %v", err)
}
} else if res == "vxlan" {
var vxlanRsrcCfg *resources.AutoVXLANCfgResource
vxlanRsrcCfg, err = gc.initVXLANBitset(gc.Auto.VXLANs)
if err != nil {
return err
}
err = ra.RedefineResource("global", resources.AutoVXLANResource, vxlanRsrcCfg)
if err != nil {
log.Errorf("Error deleting vxlan resource. Err: %v", err)
}
g := &Oper{FreeVXLANsStart: vxlanRsrcCfg.FreeVXLANsStart}
g.StateDriver = gc.StateDriver
err = g.Write()
if err != nil {
log.Errorf("error '%s' updating global oper state %v \n", err, g)
return err
}
}
return err
}
示例7: FreeVXLAN
// FreeVXLAN returns a VXLAN id to the pool.
func (gc *Cfg) FreeVXLAN(vxlan uint, localVLAN uint) error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
g := &Oper{}
g.StateDriver = gc.StateDriver
err = g.Read("")
if err != nil {
return nil
}
return ra.DeallocateResourceVal("global", resources.AutoVXLANResource,
resources.VXLANVLANPair{
VXLAN: vxlan - g.FreeVXLANsStart,
VLAN: localVLAN})
}
示例8: DeleteResources
// DeleteResources deletes associated resources
func (gc *Cfg) DeleteResources() error {
tempRm, err := resources.GetStateResourceManager()
if err != nil {
return err
}
ra := core.ResourceManager(tempRm)
err = ra.UndefineResource("global", resources.AutoVLANResource)
if err != nil {
log.Errorf("Error deleting vlan resource. Err: %v", err)
}
err = ra.UndefineResource("global", resources.AutoVXLANResource)
if err != nil {
log.Errorf("Error deleting vxlan resource. Err: %v", err)
}
return err
}