Пример #1
0
func makeDriverConfig(c *controller, ntype string) map[string]interface{} {
	if c.cfg == nil {
		return nil
	}

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

	if c.validateDatastoreConfig() {
		config[netlabel.KVProvider] = c.cfg.Datastore.Client.Provider
		config[netlabel.KVProviderURL] = c.cfg.Datastore.Client.Address
	}

	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 {
		return config
	}

	for k, v := range drvCfg.(map[string]interface{}) {
		config[k] = v
	}

	return config
}
Пример #2
0
// CmdNetworkCreate handles Network Create UI
func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
	cmd := cli.Subcmd(chain, "create", "NETWORK-NAME", "Creates a new network with a name specified by the user", false)
	flDriver := cmd.String([]string{"d", "-driver"}, "", "Driver to manage the Network")
	flID := cmd.String([]string{"-id"}, "", "Network ID string")
	flOpts := cmd.String([]string{"o", "-opt"}, "", "Network options")
	flInternal := cmd.Bool([]string{"-internal"}, false, "Config the network to be internal")
	flIPv6 := cmd.Bool([]string{"-ipv6"}, false, "Enable IPv6 on the network")
	flSubnet := cmd.String([]string{"-subnet"}, "", "Subnet option")
	flRange := cmd.String([]string{"-ip-range"}, "", "Range option")

	cmd.Require(flag.Exact, 1)
	err := cmd.ParseFlags(args, true)
	if err != nil {
		return err
	}
	networkOpts := make(map[string]string)
	if *flInternal {
		networkOpts[netlabel.Internal] = "true"
	}
	if *flIPv6 {
		networkOpts[netlabel.EnableIPv6] = "true"
	}

	driverOpts := make(map[string]string)
	if *flOpts != "" {
		opts := strings.Split(*flOpts, ",")
		for _, opt := range opts {
			driverOpts[netlabel.Key(opt)] = netlabel.Value(opt)
		}
	}

	var icList []ipamConf
	if *flSubnet != "" {
		ic := ipamConf{
			PreferredPool: *flSubnet,
		}

		if *flRange != "" {
			ic.SubPool = *flRange
		}

		icList = append(icList, ic)
	}

	// Construct network create request body
	nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, ID: *flID, IPv4Conf: icList, DriverOpts: driverOpts, NetworkOpts: networkOpts}
	obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
	if err != nil {
		return err
	}
	var replyID string
	err = json.Unmarshal(obj, &replyID)
	if err != nil {
		return err
	}
	fmt.Fprintf(cli.out, "%s\n", replyID)
	return nil
}
Пример #3
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.MakeKVClient(k)] = discoverapi.DatastoreConfigData{
			Scope:    k,
			Provider: v.Client.Provider,
			Address:  v.Client.Address,
			Config:   v.Client.Config,
		}
	}

	return config
}
Пример #4
0
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
	c.Lock()
	if !config.IsValidName(networkType) {
		c.Unlock()
		return ErrInvalidName(networkType)
	}
	if _, ok := c.drivers[networkType]; ok {
		c.Unlock()
		return driverapi.ErrActiveRegistration(networkType)
	}
	c.drivers[networkType] = &driverData{driver, capability}

	if c.cfg == nil {
		c.Unlock()
		return nil
	}

	opt := make(map[string]interface{})
	for _, label := range c.cfg.Daemon.Labels {
		if strings.HasPrefix(label, netlabel.DriverPrefix+"."+networkType) {
			opt[netlabel.Key(label)] = netlabel.Value(label)
		}
	}

	if capability.DataScope == datastore.GlobalScope && c.validateGlobalStoreConfig() {
		opt[netlabel.KVProvider] = c.cfg.GlobalStore.Client.Provider
		opt[netlabel.KVProviderURL] = c.cfg.GlobalStore.Client.Address
	}

	if capability.DataScope == datastore.LocalScope {
		localStoreConfig := c.getLocalStoreConfig(c.cfg)
		opt[netlabel.KVProvider] = localStoreConfig.Client.Provider
		opt[netlabel.KVProviderURL] = localStoreConfig.Client.Address
		opt[netlabel.KVProviderConfig] = localStoreConfig.Client.Config
	}

	c.Unlock()

	if len(opt) != 0 {
		if err := driver.Config(opt); err != nil {
			return err
		}
	}

	return nil
}