Exemplo n.º 1
0
// Init initializes the NetPlugin instance via the configuration string passed.
func (p *NetPlugin) Init(pluginConfig Config) error {
	var err error
	if pluginConfig.Instance.HostLabel == "" {
		return core.Errorf("empty host-label passed")
	}

	// initialize state driver
	p.StateDriver, err = utils.GetStateDriver()
	if err != nil {
		p.StateDriver, err = utils.NewStateDriver(pluginConfig.Drivers.State, &pluginConfig.Instance)
		if err != nil {
			return err
		}
	}
	defer func() {
		if err != nil {
			utils.ReleaseStateDriver()
		}
	}()

	// set state driver in instance info
	pluginConfig.Instance.StateDriver = p.StateDriver

	fwdMode := GetFwdMode(p.StateDriver)
	if fwdMode == "" {
		fwdMode = "bridge"
	}
	pluginConfig.Instance.FwdMode = fwdMode

	// initialize network driver
	p.NetworkDriver, err = utils.NewNetworkDriver(pluginConfig.Drivers.Network, &pluginConfig.Instance)
	if err != nil {
		return err
	}

	defer func() {
		if err != nil {
			p.NetworkDriver.Deinit()
		}
	}()

	return nil
}
Exemplo n.º 2
0
// Init initializes the NetPlugin instance via the configuration string passed.
func (p *NetPlugin) Init(pluginConfig Config, configStr string) error {
	var err error
	if pluginConfig.Instance.HostLabel == "" {
		return core.Errorf("empty host-label passed")
	}

	// initialize state driver
	p.StateDriver, err = utils.NewStateDriver(pluginConfig.Drivers.State, configStr)
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			utils.ReleaseStateDriver()
		}
	}()

	instanceInfo := &core.InstanceInfo{
		HostLabel:   pluginConfig.Instance.HostLabel,
		VtepIP:      pluginConfig.Instance.VtepIP,
		VlanIntf:    pluginConfig.Instance.VlanIntf,
		RouterIP:    pluginConfig.Instance.RouterIP,
		FwdMode:     pluginConfig.Instance.FwdMode,
		StateDriver: p.StateDriver,
	}

	// initialize network driver
	p.NetworkDriver, err = utils.NewNetworkDriver(pluginConfig.Drivers.Network,
		configStr, instanceInfo)
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			p.NetworkDriver.Deinit()
		}
	}()

	return nil
}
Exemplo n.º 3
0
//GlobalFwdModeUpdate update the global config
func (p *NetPlugin) GlobalFwdModeUpdate(cfg Config) {
	var err error

	if p.NetworkDriver != nil {
		p.NetworkDriver.Deinit()
		p.NetworkDriver = nil
	}

	cfg.Instance.StateDriver, _ = utils.GetStateDriver()
	p.NetworkDriver, err = utils.NewNetworkDriver(cfg.Drivers.Network, &cfg.Instance)

	if err != nil {
		logrus.Errorf("Error updating global forwarding mode %v", err)
		return
	}

	defer func() {
		if err != nil {
			p.NetworkDriver.Deinit()
		}
	}()

	return
}