예제 #1
0
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
}
예제 #2
0
파일: store.go 프로젝트: wcwxyz/libnetwork
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
}
예제 #3
0
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
}
예제 #4
0
파일: overlay.go 프로젝트: neonix888/docker
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
}
예제 #5
0
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
}
예제 #6
0
// 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())
}
예제 #7
0
파일: store.go 프로젝트: jak-atx/vic
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
}
예제 #8
0
파일: store.go 프로젝트: c0b/libnetwork
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
}
예제 #9
0
// 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

}
예제 #10
0
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
}
예제 #11
0
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()
}
예제 #12
0
파일: overlay.go 프로젝트: c0b/libnetwork
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
}
예제 #13
0
// 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,
			},
		},
	})
}
예제 #14
0
파일: store.go 프로젝트: Ketouem/docker
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
}
예제 #15
0
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()
}