当前位置: 首页>>代码示例>>Golang>>正文


Golang core.ResourceManager类代码示例

本文整理汇总了Golang中github.com/contiv/netplugin/core.ResourceManager的典型用法代码示例。如果您正苦于以下问题:Golang ResourceManager类的具体用法?Golang ResourceManager怎么用?Golang ResourceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ResourceManager类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AllocSubnet

// AllocSubnet allocates a new subnet. Returns a CIDR.
func (gc *Cfg) AllocSubnet(ra core.ResourceManager) (string, error) {
	pair, err := ra.AllocateResourceVal(gc.Tenant, resources.AutoSubnetResource)
	if err != nil {
		return "", err
	}

	return pair.(resources.SubnetIPLenPair).IP.String(), err
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:9,代码来源:gstate.go

示例2: AllocVLAN

// AllocVLAN allocates a new VLAN resource. Returns an ID.
func (gc *Cfg) AllocVLAN(ra core.ResourceManager) (uint, error) {
	vlan, err := ra.AllocateResourceVal(gc.Tenant, resources.AutoVLANResource)
	if err != nil {
		log.Errorf("alloc vlan failed: %q", err)
		return 0, err
	}

	return vlan.(uint), err
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:10,代码来源:gstate.go

示例3: FreeVXLAN

// FreeVXLAN returns a VXLAN id to the pool.
func (gc *Cfg) FreeVXLAN(ra core.ResourceManager, vxlan uint, localVLAN uint) error {
	g := &Oper{}
	g.StateDriver = gc.StateDriver
	err := g.Read(gc.Tenant)
	if err != nil {
		return nil
	}

	return ra.DeallocateResourceVal(gc.Tenant, resources.AutoVXLANResource,
		resources.VXLANVLANPair{
			VXLAN: vxlan - g.FreeVXLANsStart,
			VLAN:  localVLAN})
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:14,代码来源:gstate.go

示例4: AllocVXLAN

// AllocVXLAN allocates a new vxlan; ids for both the vxlan and vlan are returned.
func (gc *Cfg) AllocVXLAN(ra core.ResourceManager) (vxlan uint,
	localVLAN uint, err error) {

	pair, err1 := ra.AllocateResourceVal(gc.Tenant, resources.AutoVXLANResource)
	if err1 != nil {
		return 0, 0, err1
	}

	g := &Oper{}
	g.StateDriver = gc.StateDriver
	err = g.Read(gc.Tenant)
	if err != nil {
		return 0, 0, err
	}

	vxlan = pair.(resources.VXLANVLANPair).VXLAN + g.FreeVXLANsStart
	localVLAN = pair.(resources.VXLANVLANPair).VLAN

	return
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:21,代码来源:gstate.go

示例5: DeleteResources

// DeleteResources deletes associated resources
func (gc *Cfg) DeleteResources(ra core.ResourceManager) error {
	tenant := gc.Tenant
	if tenant == "" {
		return core.Errorf("null tenant")
	}

	err := ra.UndefineResource(tenant, resources.AutoSubnetResource)
	if err != nil {
		log.Errorf("Error deleting subnet resource. Err: %v", err)
	}

	err = ra.UndefineResource(tenant, resources.AutoVLANResource)
	if err != nil {
		log.Errorf("Error deleting vlan resource. Err: %v", err)
	}

	err = ra.UndefineResource(tenant, resources.AutoVXLANResource)
	if err != nil {
		log.Errorf("Error deleting vxlan resource. Err: %v", err)
	}

	return err
}
开发者ID:rtrentin73,项目名称:netplugin,代码行数:24,代码来源:gstate.go

示例6: 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
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:66,代码来源:gstate.go

示例7: FreeSubnet

// FreeSubnet releases a subnet derived from it's CIDR.
func (gc *Cfg) FreeSubnet(ra core.ResourceManager, subnetIP string) error {
	return ra.DeallocateResourceVal(gc.Tenant, resources.AutoSubnetResource,
		resources.SubnetIPLenPair{
			IP:  net.ParseIP(subnetIP),
			Len: gc.Auto.AllocSubnetLen})
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:7,代码来源:gstate.go

示例8: FreeVLAN

// FreeVLAN releases a VLAN for a given ID.
func (gc *Cfg) FreeVLAN(ra core.ResourceManager, vlan uint) error {
	return ra.DeallocateResourceVal(gc.Tenant, resources.AutoVLANResource, vlan)
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:4,代码来源:gstate.go


注:本文中的github.com/contiv/netplugin/core.ResourceManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。