Exemplo n.º 1
0
//UpdateEndpointGroup updates the endpointgroups
func UpdateEndpointGroup(bandwidth, groupName, tenantName string, Dscp, burst int) error {

	// Get the state driver - get the etcd driver state
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return err
	}

	key := mastercfg.GetEndpointGroupKey(groupName, tenantName)
	if key == "" {
		return errors.New("Error finding endpointGroup key ")
	}

	// Read etcd driver
	epCfg := mastercfg.EndpointGroupState{}
	epCfg.StateDriver = stateDriver

	err = epCfg.Read(key)
	if err != nil {
		log.Errorf("Error finding endpointgroup %s. Err: %v", key, err)
		return err
	}

	//update the epGroup state
	epCfg.DSCP = Dscp
	epCfg.Bandwidth = bandwidth
	epCfg.Burst = burst

	//Write to etcd
	err = epCfg.Write()
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 2
0
func handleEpgEvents(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, recvErr chan error) {

	rsps := make(chan core.WatchState)
	go processStateEvent(netPlugin, opts, rsps)
	cfg := mastercfg.EndpointGroupState{}
	cfg.StateDriver = netPlugin.StateDriver
	recvErr <- cfg.WatchAll(rsps)
	return
}
Exemplo n.º 3
0
// ProcessCurrentState processes current state as read from stateStore
func (ag *Agent) ProcessCurrentState() error {
	opts := ag.pluginConfig.Instance
	readNet := &mastercfg.CfgNetworkState{}
	readNet.StateDriver = ag.netPlugin.StateDriver
	netCfgs, err := readNet.ReadAll()
	if err == nil {
		for idx, netCfg := range netCfgs {
			net := netCfg.(*mastercfg.CfgNetworkState)
			log.Debugf("read net key[%d] %s, populating state \n", idx, net.ID)
			processNetEvent(ag.netPlugin, net, false)
			if net.NwType == "infra" {
				processInfraNwCreate(ag.netPlugin, net, opts)
			}
		}
	}

	readEp := &mastercfg.CfgEndpointState{}
	readEp.StateDriver = ag.netPlugin.StateDriver
	epCfgs, err := readEp.ReadAll()
	if err == nil {
		for idx, epCfg := range epCfgs {
			ep := epCfg.(*mastercfg.CfgEndpointState)
			log.Debugf("read ep key[%d] %s, populating state \n", idx, ep.ID)
			processEpState(ag.netPlugin, opts, ep.ID)
		}
	}

	readBgp := &mastercfg.CfgBgpState{}
	readBgp.StateDriver = ag.netPlugin.StateDriver
	bgpCfgs, err := readBgp.ReadAll()
	if err == nil {
		for idx, bgpCfg := range bgpCfgs {
			bgp := bgpCfg.(*mastercfg.CfgBgpState)
			log.Debugf("read bgp key[%d] %s, populating state \n", idx, bgp.Hostname)
			processBgpEvent(ag.netPlugin, opts, bgp.Hostname, false)
		}
	}

	readEpg := mastercfg.EndpointGroupState{}
	readEpg.StateDriver = ag.netPlugin.StateDriver
	epgCfgs, err := readEpg.ReadAll()
	if err == nil {
		for idx, epgCfg := range epgCfgs {
			epg := epgCfg.(*mastercfg.EndpointGroupState)
			log.Infof("Read epg key[%d] %s, for group %s, populating state \n", idx, epg.GroupName)
			processEpgEvent(ag.netPlugin, opts, epg.ID, false)
		}
	}

	readServiceLb := &mastercfg.CfgServiceLBState{}
	readServiceLb.StateDriver = ag.netPlugin.StateDriver
	serviceLbCfgs, err := readServiceLb.ReadAll()
	if err == nil {
		for idx, serviceLbCfg := range serviceLbCfgs {
			serviceLb := serviceLbCfg.(*mastercfg.CfgServiceLBState)
			log.Debugf("read svc key[%d] %s for tenant %s, populating state \n", idx,
				serviceLb.ServiceName, serviceLb.Tenant)
			processServiceLBEvent(ag.netPlugin, serviceLb, false)
		}
	}

	readSvcProviders := &mastercfg.SvcProvider{}
	readSvcProviders.StateDriver = ag.netPlugin.StateDriver
	svcProviders, err := readSvcProviders.ReadAll()
	if err == nil {
		for idx, providers := range svcProviders {
			svcProvider := providers.(*mastercfg.SvcProvider)
			log.Infof("read svc provider[%d] %s , populating state \n", idx,
				svcProvider.ServiceName)
			processSvcProviderUpdEvent(ag.netPlugin, svcProvider, false)
		}
	}

	return nil
}