當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。