Пример #1
0
func initStateDriver(opts *cliOpts) (core.StateDriver, error) {
	var cfg *core.Config

	switch opts.stateStore {
	case utils.EtcdNameStr:
		url := "http://127.0.0.1:4001"
		if opts.storeURL != "" {
			url = opts.storeURL
		}
		etcdCfg := &state.EtcdStateDriverConfig{}
		etcdCfg.Etcd.Machines = []string{url}
		cfg = &core.Config{V: etcdCfg}
	case utils.ConsulNameStr:
		url := "http://127.0.0.1:8500"
		if opts.storeURL != "" {
			url = opts.storeURL
		}
		consulCfg := &state.ConsulStateDriverConfig{}
		consulCfg.Consul = api.Config{Address: url}
		cfg = &core.Config{V: consulCfg}
	default:
		return nil, core.Errorf("Unsupported state-store %q", opts.stateStore)
	}

	cfgBytes, err := json.Marshal(cfg)
	if err != nil {
		return nil, err
	}

	return utils.NewStateDriver(opts.stateStore, string(cfgBytes))
}
Пример #2
0
func initFakeStateDriver(t *testing.T) {
	instInfo := core.InstanceInfo{}
	d, err := utils.NewStateDriver("fakedriver", &instInfo)
	if err != nil {
		t.Fatalf("failed to init statedriver. Error: %s", err)
	}

	fakeDriver = d.(*state.FakeStateDriver)
}
Пример #3
0
func initFakeStateDriver(t *testing.T) {
	config := &core.Config{V: &state.FakeStateDriverConfig{}}
	cfgBytes, err := json.Marshal(config)
	if err != nil {
		t.Fatalf("marshalling configuration failed. Error: %s", err)
	}

	d, err := utils.NewStateDriver("fakedriver", string(cfgBytes))
	if err != nil {
		t.Fatalf("failed to init statedriver. Error: %s", err)
	}

	fakeDriver = d.(*state.FakeStateDriver)
}
Пример #4
0
// initStateDriver initialize etcd state driver
func initStateDriver() (core.StateDriver, error) {
	var cfg *core.Config

	url := "http://127.0.0.1:4001"
	etcdCfg := &state.EtcdStateDriverConfig{}
	etcdCfg.Etcd.Machines = []string{url}
	cfg = &core.Config{V: etcdCfg}

	cfgBytes, err := json.Marshal(cfg)
	if err != nil {
		return nil, err
	}

	return utils.NewStateDriver(utils.EtcdNameStr, string(cfgBytes))
}
Пример #5
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
}
Пример #6
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
}
Пример #7
0
// initStateDriver creates a state driver based on the cluster store URL
func initStateDriver(clusterStore string) (core.StateDriver, error) {
	// parse the state store URL
	parts := strings.Split(clusterStore, "://")
	if len(parts) < 2 {
		return nil, core.Errorf("Invalid state-store URL %q", clusterStore)
	}
	stateStore := parts[0]

	// Make sure we support the statestore type
	switch stateStore {
	case utils.EtcdNameStr:
	case utils.ConsulNameStr:
	default:
		return nil, core.Errorf("Unsupported state-store %q", stateStore)
	}

	// Setup instance info
	instInfo := core.InstanceInfo{
		DbURL: clusterStore,
	}

	return utils.NewStateDriver(stateStore, &instInfo)
}
Пример #8
0
// initStateDriver initialize etcd state driver
func initStateDriver() (core.StateDriver, error) {
	instInfo := core.InstanceInfo{DbURL: "etcd://127.0.0.1:2379"}

	return utils.NewStateDriver(utils.EtcdNameStr, &instInfo)
}