本文整理汇总了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))
}
示例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)
}
示例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)
}
示例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))
}
示例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
}
示例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
}
示例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)
}
示例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)
}