當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。