// NewTopLevelConfig creates a TopLevelConfig struct which can drive communication // with the configuration store. func NewTopLevelConfig(prefix string, etcdHosts []string) *TopLevelConfig { config := &TopLevelConfig{ prefix: prefix, etcdClient: etcd.NewClient(etcdHosts), } config.etcdClient.SetDir(config.prefix, 0) for _, path := range defaultPaths { config.etcdClient.SetDir(config.prefixed(path), 0) } return config }
// Init the driver with a core.Config. func (d *EtcdStateDriver) Init(config *core.Config) error { if config == nil { return core.Errorf("Invalid arguments. cfg: %v", config) } cfg, ok := config.V.(*EtcdStateDriverConfig) if !ok { return core.Errorf("Invalid config type passed!") } d.Client = etcd.NewClient(cfg.Etcd.Machines) return nil }
// Initialize the etcd client func (self *EtcdPlugin) Init(machines []string) error { self.mutex.Lock() defer self.mutex.Unlock() // Create a new client self.client = etcd.NewClient(machines) if self.client == nil { log.Fatal("Error creating etcd client.") return errors.New("Error creating etcd client") } // Set strong consistency self.client.SetConsistency(etcd.STRONG_CONSISTENCY) // Initialize service DB self.serviceDb = make(map[string]*serviceState) return nil }
// Init the driver with a core.Config. func (d *EtcdStateDriver) Init(config *core.Config) error { if config == nil { return core.Errorf("Invalid arguments. cfg: %v", config) } cfg, ok := config.V.(*EtcdStateDriverConfig) if !ok { return core.Errorf("Invalid config type passed!") } d.Client = etcd.NewClient(cfg.Etcd.Machines) // Set strong consistency d.Client.SetConsistency(etcd.STRONG_CONSISTENCY) return nil }