本文整理匯總了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
}