本文整理汇总了Golang中github.com/contiv/netplugin/core.ResourceManager.DefineResource方法的典型用法代码示例。如果您正苦于以下问题:Golang ResourceManager.DefineResource方法的具体用法?Golang ResourceManager.DefineResource怎么用?Golang ResourceManager.DefineResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/netplugin/core.ResourceManager
的用法示例。
在下文中一共展示了ResourceManager.DefineResource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Process
// Process validates, implements, and writes the state.
func (gc *Cfg) Process(ra core.ResourceManager) error {
var err error
if gc.Version != VersionBeta1 {
return core.Errorf("unsupported version %s", gc.Version)
}
err = gc.checkErrors()
if err != nil {
return core.Errorf("process failed on error checks %s", err)
}
tenant := gc.Tenant
if tenant == "" {
return core.Errorf("null tenant")
}
subnetRsrcCfg := &resources.AutoSubnetCfgResource{
SubnetPool: net.ParseIP(gc.Auto.SubnetPool),
SubnetPoolLen: gc.Auto.SubnetLen,
AllocSubnetLen: gc.Auto.AllocSubnetLen}
err = ra.DefineResource(tenant, resources.AutoSubnetResource, subnetRsrcCfg)
if err != nil {
return err
}
// Only define a vlan resource if a valid range was specified
if gc.Auto.VLANs != "" {
var vlanRsrcCfg *bitset.BitSet
vlanRsrcCfg, err = gc.initVLANBitset(gc.Auto.VLANs)
if err != nil {
return err
}
err = ra.DefineResource(tenant, resources.AutoVLANResource, vlanRsrcCfg)
if err != nil {
return err
}
}
// Only define a vxlan resource if a valid range was specified
var freeVXLANsStart uint
if gc.Auto.VXLANs != "" {
var vxlanRsrcCfg *resources.AutoVXLANCfgResource
vxlanRsrcCfg, freeVXLANsStart, err = gc.initVXLANBitset(gc.Auto.VXLANs)
if err != nil {
return err
}
err = ra.DefineResource(tenant, resources.AutoVXLANResource, vxlanRsrcCfg)
if err != nil {
return err
}
}
g := &Oper{Tenant: gc.Tenant,
FreeVXLANsStart: freeVXLANsStart}
g.StateDriver = gc.StateDriver
err = g.Write()
if err != nil {
log.Errorf("error '%s' updating goper state %v \n", err, g)
return err
}
log.Debugf("updating the global config to new state %v \n", gc)
return nil
}