當前位置: 首頁>>代碼示例>>Golang>>正文


Golang resources.GetStateResourceManager函數代碼示例

本文整理匯總了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
}
開發者ID:vvb,項目名稱:netplugin,代碼行數:34,代碼來源:gstate.go

示例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)
}
開發者ID:vvb,項目名稱:netplugin,代碼行數:10,代碼來源:gstate.go

示例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
}
開發者ID:abhinandanpb,項目名稱:netplugin,代碼行數:58,代碼來源:gstate.go

示例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)
}
開發者ID:jojimt,項目名稱:netplugin,代碼行數:11,代碼來源:gstate.go

示例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
}
開發者ID:vvb,項目名稱:netplugin,代碼行數:16,代碼來源:gstate.go

示例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
}
開發者ID:jojimt,項目名稱:netplugin,代碼行數:46,代碼來源:gstate.go

示例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})
}
開發者ID:vvb,項目名稱:netplugin,代碼行數:20,代碼來源:gstate.go

示例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
}
開發者ID:vvb,項目名稱:netplugin,代碼行數:21,代碼來源:gstate.go


注:本文中的github.com/contiv/netplugin/netmaster/resources.GetStateResourceManager函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。