当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.NewStateDriver函数代码示例

本文整理汇总了Golang中github.com/contiv/netplugin/utils.NewStateDriver函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStateDriver函数的具体用法?Golang NewStateDriver怎么用?Golang NewStateDriver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewStateDriver函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: initStateDriver

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))
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:31,代码来源:main.go

示例2: initFakeStateDriver

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)
}
开发者ID:jojimt,项目名称:netplugin,代码行数:9,代码来源:netmaster_test.go

示例3: initFakeStateDriver

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)
}
开发者ID:syeduguri,项目名称:netplugin,代码行数:14,代码来源:netmaster_test.go

示例4: initStateDriver

// 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))
}
开发者ID:vvb,项目名称:netplugin,代码行数:16,代码来源:docknet_test.go

示例5: Init

// 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
}
开发者ID:jojimt,项目名称:netplugin,代码行数:44,代码来源:netplugin.go

示例6: Init

// 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
}
开发者ID:vvb,项目名称:netplugin,代码行数:41,代码来源:netplugin.go

示例7: initStateDriver

// 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)
}
开发者ID:jojimt,项目名称:netplugin,代码行数:24,代码来源:cfgtool.go

示例8: initStateDriver

// 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)
}
开发者ID:jojimt,项目名称:netplugin,代码行数:6,代码来源:docknet_test.go


注:本文中的github.com/contiv/netplugin/utils.NewStateDriver函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。