Пример #1
0
func main() {
	kingpin.Parse()
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	dc := &driverCallback{}
	driverOptions := options.Generic{
		"EnableIPTables":     *iptables,
		"EnableIPForwarding": *ipForward,
	}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = driverOptions
	for k, v := range datastore.DefaultScopes("") {
		if !v.IsValid() {
			continue
		}

		genericOption[netlabel.MakeKVProvider(k)] = v.Client.Provider
		genericOption[netlabel.MakeKVProviderURL(k)] = v.Client.Address
		genericOption[netlabel.MakeKVProviderConfig(k)] = v.Client.Config
	}

	err := bridge.Init(dc, genericOption)
	if err != nil {
		logrus.Fatalf("Failed to initialize the bridge: %v", err)
	}

	h := network.NewHandler(dc.driver)
	h.ServeUnix("", pluginName)
}
Пример #2
0
func makeDriverConfig(c *controller, ntype string) map[string]interface{} {
	if c.cfg == nil {
		return nil
	}

	config := make(map[string]interface{})

	for _, label := range c.cfg.Daemon.Labels {
		if !strings.HasPrefix(netlabel.Key(label), netlabel.DriverPrefix+"."+ntype) {
			continue
		}

		config[netlabel.Key(label)] = netlabel.Value(label)
	}

	drvCfg, ok := c.cfg.Daemon.DriverCfg[ntype]
	if ok {
		for k, v := range drvCfg.(map[string]interface{}) {
			config[k] = v
		}
	}

	// We don't send datastore configs to external plugins
	if ntype == "remote" {
		return config
	}

	for k, v := range c.cfg.Scopes {
		if !v.IsValid() {
			continue
		}

		config[netlabel.MakeKVProvider(k)] = v.Client.Provider
		config[netlabel.MakeKVProviderURL(k)] = v.Client.Address
		config[netlabel.MakeKVProviderConfig(k)] = v.Client.Config
	}

	return config
}