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


Golang datastore.NewDataStore函数代码示例

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


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

示例1: initStore

func (d *driver) initStore(option map[string]interface{}) error {
	var err error

	provider, provOk := option[netlabel.LocalKVProvider]
	provURL, urlOk := option[netlabel.LocalKVProviderURL]

	if provOk && urlOk {
		cfg := &datastore.ScopeCfg{
			Client: datastore.ScopeClientCfg{
				Provider: provider.(string),
				Address:  provURL.(string),
			},
		}

		provConfig, confOk := option[netlabel.LocalKVProviderConfig]
		if confOk {
			cfg.Client.Config = provConfig.(*store.Config)
		}

		d.store, err = datastore.NewDataStore(datastore.LocalScope, cfg)
		if err != nil {
			return fmt.Errorf("bridge driver failed to initialize data store: %v", err)
		}

		return d.populateNetworks()
	}

	return nil
}
开发者ID:CtrlZvi,项目名称:public-ipv6-bridge,代码行数:29,代码来源:bridge_store.go

示例2: initLocalStore

func (c *controller) initLocalStore() error {
	c.Lock()
	cfg := c.cfg
	c.Unlock()
	localStore, err := datastore.NewDataStore(c.getLocalStoreConfig(cfg))
	if err != nil {
		return err
	}
	c.Lock()
	c.localStore = localStore
	c.Unlock()

	nws, err := c.getNetworksFromLocalStore()
	if err == nil {
		c.processNetworkUpdate(nws, nil)
	} else if err != datastore.ErrKeyNotFound {
		log.Warnf("failed to read networks from localstore during init : %v", err)
	}
	eps, err := c.getEndpointsFromLocalStore()
	if err == nil {
		c.processEndpointsUpdate(eps, nil)
	} else if err != datastore.ErrKeyNotFound {
		log.Warnf("failed to read endpoints from localstore during init : %v", err)
	}
	return nil
}
开发者ID:wcwxyz,项目名称:libnetwork,代码行数:26,代码来源:store.go

示例3: NewDriver

func NewDriver(version string, externalPort string, provider string, provURL string) (Driver, error) {
	b := NewBridge()
	err := b.setupBridge(externalPort)

	if err != nil {
		return nil, fmt.Errorf("unable to create the bridge: %s", err)
	}

	log.Infof("DataStore provider: %s, provURl: %s", provider, provURL)

	cfg := &datastore.ScopeCfg{
		Client: datastore.ScopeClientCfg{
			Provider: provider,
			Address:  provURL,
		},
	}

	ds, err := datastore.NewDataStore(datastore.GlobalScope, cfg)
	if err != nil {
		log.Fatalf("failed to initialize data store: %v", err)
	}

	d := &driver{
		version:      version,
		externalPort: externalPort,
		store:        ds,
	}
	return d, nil
}
开发者ID:akanto,项目名称:dhcp-plugin,代码行数:29,代码来源:driver.go

示例4: configure

func (d *driver) configure() error {
	var err error

	if len(d.config) == 0 {
		return nil
	}

	d.Do(func() {
		if ifaceName, ok := d.config[netlabel.OverlayBindInterface]; ok {
			d.ifaceName = ifaceName.(string)
		}

		if neighIP, ok := d.config[netlabel.OverlayNeighborIP]; ok {
			d.neighIP = neighIP.(string)
		}

		provider, provOk := d.config[netlabel.KVProvider]
		provURL, urlOk := d.config[netlabel.KVProviderURL]

		if provOk && urlOk {
			cfg := &config.DatastoreCfg{
				Client: config.DatastoreClientCfg{
					Provider: provider.(string),
					Address:  provURL.(string),
				},
			}
			provConfig, confOk := d.config[netlabel.KVProviderConfig]
			if confOk {
				cfg.Client.Config = provConfig.(*store.Config)
			}
			d.store, err = datastore.NewDataStore(cfg)
			if err != nil {
				err = fmt.Errorf("failed to initialize data store: %v", err)
				return
			}
		}

		d.vxlanIdm, err = idm.New(d.store, "vxlan-id", vxlanIDStart, vxlanIDEnd)
		if err != nil {
			err = fmt.Errorf("failed to initialize vxlan id manager: %v", err)
			return
		}

		d.ipAllocator, err = idm.New(d.store, "ipam-id", 1, 0xFFFF-2)
		if err != nil {
			err = fmt.Errorf("failed to initalize ipam id manager: %v", err)
			return
		}

		err = d.serfInit()
		if err != nil {
			err = fmt.Errorf("initializing serf instance failed: %v", err)
		}

	})

	return err
}
开发者ID:neonix888,项目名称:docker,代码行数:58,代码来源:overlay.go

示例5: Config

func (d *driver) Config(option map[string]interface{}) error {
	var onceDone bool
	var err error

	d.Do(func() {
		onceDone = true

		if ifaceName, ok := option[netlabel.OverlayBindInterface]; ok {
			d.ifaceName = ifaceName.(string)
		}

		if neighIP, ok := option[netlabel.OverlayNeighborIP]; ok {
			d.neighIP = neighIP.(string)
		}

		provider, provOk := option[netlabel.KVProvider]
		provURL, urlOk := option[netlabel.KVProviderURL]

		if provOk && urlOk {
			cfg := &config.DatastoreCfg{
				Client: config.DatastoreClientCfg{
					Provider: provider.(string),
					Address:  provURL.(string),
				},
			}
			d.store, err = datastore.NewDataStore(cfg)
			if err != nil {
				err = fmt.Errorf("failed to initialize data store: %v", err)
				return
			}
		}

		d.vxlanIdm, err = idm.New(d.store, "vxlan-id", vxlanIDStart, vxlanIDEnd)
		if err != nil {
			err = fmt.Errorf("failed to initialize vxlan id manager: %v", err)
			return
		}

		d.ipAllocator, err = idm.New(d.store, "ipam-id", 1, 0xFFFF-2)
		if err != nil {
			err = fmt.Errorf("failed to initalize ipam id manager: %v", err)
			return
		}

		err = d.serfInit()
		if err != nil {
			err = fmt.Errorf("initializing serf instance failed: %v", err)
		}

	})

	if !onceDone {
		return fmt.Errorf("config already applied to driver")
	}

	return err
}
开发者ID:hariharan16s,项目名称:libnetwork,代码行数:57,代码来源:overlay.go

示例6: testMain

// enable w/ upper case
func testMain(m *testing.M) {
	var err error
	ds, err = datastore.NewDataStore(&config.DatastoreCfg{Embedded: false, Client: config.DatastoreClientCfg{Provider: "consul", Address: "127.0.0.1:8500"}})
	if err != nil {
		fmt.Println(err)
	}

	os.Exit(m.Run())
}
开发者ID:rajatchopra,项目名称:libnetwork,代码行数:10,代码来源:allocator_test.go

示例7: initScopedStore

func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
	store, err := datastore.NewDataStore(scope, scfg)
	if err != nil {
		return err
	}
	c.Lock()
	c.stores = append(c.stores, store)
	c.Unlock()

	return nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:11,代码来源:store.go

示例8: initLocalStore

func (c *controller) initLocalStore() error {
	c.Lock()
	cfg := c.cfg
	c.Unlock()
	localStore, err := datastore.NewDataStore(c.getLocalStoreConfig(cfg))
	if err != nil {
		return err
	}
	c.Lock()
	c.localStore = localStore
	c.Unlock()
	return nil
}
开发者ID:c0b,项目名称:libnetwork,代码行数:13,代码来源:store.go

示例9: NewIPAMDriver

// This creates a new instance of IPAMDriver
func NewIPAMDriver(Addresses *ipam.AddressSpacesResponse, cfg *datastore.ScopeCfg) (*IPAMDriver, error) {
	var err error
	log.Debugf("Init called")

	if Addresses == nil {
		err = fmt.Errorf("Invalid Addresses")
		log.Error(err)
		return nil, err
	}

	dsg, err := datastore.NewDataStore(Addresses.GlobalDefaultAddressSpace, cfg)

	if err != nil {
		log.Errorf("Error returned from init: %s", err.Error())
		return nil, err
	}

	dsl, err := datastore.NewDataStore(Addresses.LocalDefaultAddressSpace, cfg)

	if err != nil {
		log.Errorf("Error returned from init: %s", err.Error())
		return nil, err
	}

	ipd := &IPAMDriver{Addresses: *Addresses}
	ipd.Alloc, err = NewAllocator(dsl, dsg)

	if err != nil {
		log.Errorf("NewAllocator returned error: %s", err.Error())
		return nil, err
	}

	log.Debug("Init success")
	return ipd, nil

}
开发者ID:myENA,项目名称:kvipamdriver,代码行数:37,代码来源:driver.go

示例10: initDataStore

func (c *controller) initDataStore() error {
	if c.cfg == nil {
		return fmt.Errorf("datastore initialization requires a valid configuration")
	}

	store, err := datastore.NewDataStore(&c.cfg.Datastore)
	if err != nil {
		return err
	}
	c.Lock()
	c.store = store
	c.Unlock()
	go c.watchNewNetworks()

	return nil
}
开发者ID:AlphaStaxLLC,项目名称:libnetwork,代码行数:16,代码来源:controller.go

示例11: initDataStore

func (c *controller) initDataStore() error {
	c.Lock()
	cfg := c.cfg
	c.Unlock()
	if !c.validateDatastoreConfig() {
		return fmt.Errorf("datastore initialization requires a valid configuration")
	}

	store, err := datastore.NewDataStore(&cfg.Datastore)
	if err != nil {
		return err
	}
	c.Lock()
	c.store = store
	c.Unlock()
	return c.watchStore()
}
开发者ID:MathewAniyan,项目名称:docker,代码行数:17,代码来源:store.go

示例12: configure

func (d *driver) configure() error {
	var err error

	if len(d.config) == 0 {
		return nil
	}

	d.once.Do(func() {
		provider, provOk := d.config[netlabel.KVProvider]
		provURL, urlOk := d.config[netlabel.KVProviderURL]

		if provOk && urlOk {
			cfg := &config.DatastoreCfg{
				Client: config.DatastoreClientCfg{
					Provider: provider.(string),
					Address:  provURL.(string),
				},
			}
			provConfig, confOk := d.config[netlabel.KVProviderConfig]
			if confOk {
				cfg.Client.Config = provConfig.(*store.Config)
			}
			d.store, err = datastore.NewDataStore(cfg)
			if err != nil {
				err = fmt.Errorf("failed to initialize data store: %v", err)
				return
			}
		}

		d.vxlanIdm, err = idm.New(d.store, "vxlan-id", vxlanIDStart, vxlanIDEnd)
		if err != nil {
			err = fmt.Errorf("failed to initialize vxlan id manager: %v", err)
			return
		}

		d.ipAllocator, err = idm.New(d.store, "ipam-id", 1, 0xFFFF-2)
		if err != nil {
			err = fmt.Errorf("failed to initalize ipam id manager: %v", err)
			return
		}
	})

	return err
}
开发者ID:c0b,项目名称:libnetwork,代码行数:44,代码来源:overlay.go

示例13: randomLocalStore

// OptionBoltdbWithRandomDBFile function returns a random dir for local store backend
func randomLocalStore() (datastore.DataStore, error) {
	tmp, err := ioutil.TempFile("", "libnetwork-")
	if err != nil {
		return nil, fmt.Errorf("Error creating temp file: %v", err)
	}
	if err := tmp.Close(); err != nil {
		return nil, fmt.Errorf("Error closing temp file: %v", err)
	}
	return datastore.NewDataStore(datastore.LocalScope, &datastore.ScopeCfg{
		Client: datastore.ScopeClientCfg{
			Provider: "boltdb",
			Address:  defaultPrefix + tmp.Name(),
			Config: &store.Config{
				Bucket:            "libnetwork",
				ConnectionTimeout: 3 * time.Second,
			},
		},
	})
}
开发者ID:JMesser81,项目名称:libnetwork,代码行数:20,代码来源:allocator_test.go

示例14: initStores

func (c *controller) initStores() error {
	c.Lock()
	if c.cfg == nil {
		c.Unlock()
		return nil
	}
	scopeConfigs := c.cfg.Scopes
	c.Unlock()

	for scope, scfg := range scopeConfigs {
		store, err := datastore.NewDataStore(scope, scfg)
		if err != nil {
			return err
		}
		c.Lock()
		c.stores = append(c.stores, store)
		c.Unlock()
	}

	c.startWatch()
	return nil
}
开发者ID:Ketouem,项目名称:docker,代码行数:22,代码来源:store.go

示例15: initDataStore

func (c *controller) initDataStore() error {
	c.Lock()
	cfg := c.cfg
	c.Unlock()
	if !c.validateDatastoreConfig() {
		return fmt.Errorf("datastore initialization requires a valid configuration")
	}

	store, err := datastore.NewDataStore(&cfg.Datastore)
	if err != nil {
		return err
	}
	c.Lock()
	c.store = store
	c.Unlock()

	nws, err := c.getNetworksFromStore()
	if err == nil {
		c.processNetworkUpdate(nws, nil)
	} else if err != datastore.ErrKeyNotFound {
		log.Warnf("failed to read networks from datastore during init : %v", err)
	}
	return c.watchNetworks()
}
开发者ID:souravbh,项目名称:lattice-release,代码行数:24,代码来源:store.go


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