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


Golang config.OptionDriverConfig函数代码示例

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


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

示例1: driverOptions

func driverOptions(config *Config) []nwconfig.Option {
	bridgeConfig := options.Generic{
		"EnableIPForwarding":  config.Bridge.EnableIPForward,
		"EnableIPTables":      config.Bridge.EnableIPTables,
		"EnableUserlandProxy": config.Bridge.EnableUserlandProxy}
	bridgeOption := options.Generic{netlabel.GenericData: bridgeConfig}

	dOptions := []nwconfig.Option{}
	dOptions = append(dOptions, nwconfig.OptionDriverConfig("bridge", bridgeOption))
	return dOptions
}
开发者ID:getsymbl,项目名称:docker,代码行数:11,代码来源:daemon_unix.go

示例2: dnetDaemon

func (d *dnetConnection) dnetDaemon(cfgFile string) error {
	if err := startTestDriver(); err != nil {
		return fmt.Errorf("failed to start test driver: %v\n", err)
	}

	cfg, err := d.parseConfig(cfgFile)
	var cOptions []config.Option
	if err == nil {
		cOptions = processConfig(cfg)
	} else {
		logrus.Errorf("Error parsing config %v", err)
	}

	bridgeConfig := options.Generic{
		"EnableIPForwarding": true,
		"EnableIPTables":     true,
	}

	bridgeOption := options.Generic{netlabel.GenericData: bridgeConfig}

	cOptions = append(cOptions, config.OptionDriverConfig("bridge", bridgeOption))

	controller, err := libnetwork.New(cOptions...)
	if err != nil {
		fmt.Println("Error starting dnetDaemon :", err)
		return err
	}
	controller.SetClusterProvider(d)

	if d.Orchestration.Agent || d.Orchestration.Manager {
		d.configEvent <- struct{}{}
	}

	createDefaultNetwork(controller)
	httpHandler := api.NewHTTPHandler(controller)
	r := mux.NewRouter().StrictSlash(false)
	post := r.PathPrefix("/{.*}/networks").Subrouter()
	post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
	post = r.PathPrefix("/networks").Subrouter()
	post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
	post = r.PathPrefix("/{.*}/services").Subrouter()
	post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
	post = r.PathPrefix("/services").Subrouter()
	post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
	post = r.PathPrefix("/{.*}/sandboxes").Subrouter()
	post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)
	post = r.PathPrefix("/sandboxes").Subrouter()
	post.Methods("GET", "PUT", "POST", "DELETE").HandlerFunc(httpHandler)

	handleSignals(controller)
	setupDumpStackTrap()

	return http.ListenAndServe(d.addr, r)
}
开发者ID:vdemeester,项目名称:libnetwork,代码行数:54,代码来源:dnet.go

示例3: main

func main() {
	// Select and configure the network driver
	networkType := "bridge"

	// Create a new controller instance
	driverOptions := options.Generic{}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = driverOptions
	controller, err := libnetwork.New(config.OptionDriverConfig(networkType, genericOption))
	if err != nil {
		return
	}

	// Create a network for containers to join.
	// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can use.
	network, err := controller.NewNetwork(networkType, "network1")
	if err != nil {
		return
	}

	// For each new container: allocate IP and interfaces. The returned network
	// settings will be used for container infos (inspect and such), as well as
	// iptables rules for port publishing. This info is contained or accessible
	// from the returned endpoint.
	ep, err := network.CreateEndpoint("Endpoint1")
	if err != nil {
		return
	}

	// Create the sandbox for the containr.
	sbx, err := controller.NewSandbox("container1",
		libnetwork.OptionHostname("test"),
		libnetwork.OptionDomainname("docker.io"))

	// A sandbox can join the endpoint via the join api.
	// Join accepts Variadic arguments which libnetwork and Drivers can use.
	err = ep.Join(sbx)
	if err != nil {
		return
	}

	// libnetwork client can check the endpoint's operational data via the Info() API
	epInfo, err := ep.DriverInfo()
	mapData, ok := epInfo[netlabel.PortMap]
	if ok {
		portMapping, ok := mapData.([]types.PortBinding)
		if ok {
			fmt.Printf("Current port mapping for endpoint %s: %v", ep.Name(), portMapping)
		}
	}
}
开发者ID:nmatsui,项目名称:libnetwork,代码行数:51,代码来源:readme.go

示例4: getTestEnv

func getTestEnv(t *testing.T, empty bool) (NetworkController, Network, Network) {
	netType := "bridge"

	option := options.Generic{
		"EnableIPForwarding": true,
	}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = option

	cfgOptions, err := OptionBoltdbWithRandomDBFile()
	if err != nil {
		t.Fatal(err)
	}
	c, err := New(append(cfgOptions, config.OptionDriverConfig(netType, genericOption))...)
	if err != nil {
		t.Fatal(err)
	}

	if empty {
		return c, nil, nil
	}

	name1 := "test_nw_1"
	netOption1 := options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName": name1,
		},
	}
	n1, err := c.NewNetwork(netType, name1, "", NetworkOptionGeneric(netOption1))
	if err != nil {
		t.Fatal(err)
	}

	name2 := "test_nw_2"
	netOption2 := options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName": name2,
		},
	}
	n2, err := c.NewNetwork(netType, name2, "", NetworkOptionGeneric(netOption2))
	if err != nil {
		t.Fatal(err)
	}

	return c, n1, n2
}
开发者ID:YujiOshima,项目名称:libnetwork,代码行数:46,代码来源:sandbox_test.go

示例5: testLocalBackend

func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Config) {
	cfgOptions := []config.Option{}
	cfgOptions = append(cfgOptions, config.OptionLocalKVProvider(provider))
	cfgOptions = append(cfgOptions, config.OptionLocalKVProviderURL(url))
	cfgOptions = append(cfgOptions, config.OptionLocalKVProviderConfig(storeConfig))

	driverOptions := options.Generic{}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = driverOptions
	cfgOptions = append(cfgOptions, config.OptionDriverConfig("host", genericOption))

	fmt.Printf("URL : %s\n", url)
	ctrl, err := New(cfgOptions...)
	if err != nil {
		t.Fatalf("Error new controller: %v", err)
	}
	nw, err := ctrl.NewNetwork("host", "host")
	if err != nil {
		t.Fatalf("Error creating default \"host\" network: %v", err)
	}
	ep, err := nw.CreateEndpoint("newendpoint", []EndpointOption{}...)
	if err != nil {
		t.Fatalf("Error creating endpoint: %v", err)
	}
	store := ctrl.(*controller).localStore.KVStore()
	if exists, err := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, string(nw.ID()))); !exists || err != nil {
		t.Fatalf("Network key should have been created.")
	}
	if exists, err := store.Exists(datastore.Key([]string{datastore.EndpointKeyPrefix, string(nw.ID()), string(ep.ID())}...)); exists || err != nil {
		t.Fatalf("Endpoint key shouldn't have been created.")
	}
	store.Close()

	// test restore of local store
	ctrl, err = New(cfgOptions...)
	if err != nil {
		t.Fatalf("Error creating controller: %v", err)
	}
	if _, err = ctrl.NetworkByID(nw.ID()); err != nil {
		t.Fatalf("Error getting network %v", err)
	}
}
开发者ID:nmatsui,项目名称:libnetwork,代码行数:42,代码来源:store_test.go

示例6: createController

func createController() error {
	var err error

	option := options.Generic{
		"EnableIPForwarding": true,
	}

	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = option

	cfgOptions, err := libnetwork.OptionBoltdbWithRandomDBFile()
	if err != nil {
		return err
	}
	controller, err = libnetwork.New(append(cfgOptions, config.OptionDriverConfig(bridgeNetType, genericOption))...)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:c0b,项目名称:libnetwork,代码行数:21,代码来源:libnetwork_test.go

示例7: getTestEnv

func getTestEnv(t *testing.T) (NetworkController, Network, Network) {
	netType := "bridge"

	option := options.Generic{
		"EnableIPForwarding": true,
	}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = option

	c, err := New(config.OptionDriverConfig(netType, genericOption))
	if err != nil {
		t.Fatal(err)
	}

	name1 := "test_nw_1"
	netOption1 := options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName":            name1,
			"AllowNonDefaultBridge": true,
		},
	}
	n1, err := c.NewNetwork(netType, name1, NetworkOptionGeneric(netOption1))
	if err != nil {
		t.Fatal(err)
	}

	name2 := "test_nw_2"
	netOption2 := options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName":            name2,
			"AllowNonDefaultBridge": true,
		},
	}
	n2, err := c.NewNetwork(netType, name2, NetworkOptionGeneric(netOption2))
	if err != nil {
		t.Fatal(err)
	}

	return c, n1, n2
}
开发者ID:wangxujun163163,项目名称:libnetwork,代码行数:40,代码来源:sandbox_test.go

示例8: getTestEnv

func getTestEnv(t *testing.T, numNetworks int) (NetworkController, []Network) {
	netType := "bridge"

	option := options.Generic{
		"EnableIPForwarding": true,
	}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = option

	cfgOptions, err := OptionBoltdbWithRandomDBFile()
	if err != nil {
		t.Fatal(err)
	}
	c, err := New(append(cfgOptions, config.OptionDriverConfig(netType, genericOption))...)
	if err != nil {
		t.Fatal(err)
	}

	if numNetworks == 0 {
		return c, nil
	}

	nwList := make([]Network, 0, numNetworks)
	for i := 0; i < numNetworks; i++ {
		name := fmt.Sprintf("test_nw_%d", i)
		netOption := options.Generic{
			netlabel.GenericData: options.Generic{
				"BridgeName": name,
			},
		}
		n, err := c.NewNetwork(netType, name, "", NetworkOptionGeneric(netOption))
		if err != nil {
			t.Fatal(err)
		}

		nwList = append(nwList, n)
	}

	return c, nwList
}
开发者ID:vdemeester,项目名称:libnetwork,代码行数:40,代码来源:sandbox_test.go

示例9: createController

func createController() error {
	var err error

	// Cleanup local datastore file
	os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)

	option := options.Generic{
		"EnableIPForwarding": true,
	}

	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = option

	cfgOptions, err := libnetwork.OptionBoltdbWithRandomDBFile()
	if err != nil {
		return err
	}
	controller, err = libnetwork.New(append(cfgOptions, config.OptionDriverConfig(bridgeNetType, genericOption))...)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:pirater,项目名称:os,代码行数:24,代码来源:libnetwork_test.go

示例10: main

func main() {
	if reexec.Init() {
		return
	}

	// Select and configure the network driver
	networkType := "bridge"

	// Create a new controller instance
	driverOptions := options.Generic{}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = driverOptions
	controller, err := libnetwork.New(config.OptionDriverConfig(networkType, genericOption))
	if err != nil {
		log.Fatalf("libnetwork.New: %s", err)
	}

	// Create a network for containers to join.
	// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can use.
	network, err := controller.NewNetwork(networkType, "network1")
	if err != nil {
		log.Fatalf("controller.NewNetwork: %s", err)
	}

	// For each new container: allocate IP and interfaces. The returned network
	// settings will be used for container infos (inspect and such), as well as
	// iptables rules for port publishing. This info is contained or accessible
	// from the returned endpoint.
	ep, err := network.CreateEndpoint("Endpoint1")
	if err != nil {
		log.Fatalf("network.CreateEndpoint: %s", err)
	}

	// Create the sandbox for the container.
	// NewSandbox accepts Variadic optional arguments which libnetwork can use.
	sbx, err := controller.NewSandbox("container1",
		libnetwork.OptionHostname("test"),
		libnetwork.OptionDomainname("docker.io"))
	if err != nil {
		log.Fatalf("controller.NewSandbox: %s", err)
	}

	// A sandbox can join the endpoint via the join api.
	err = ep.Join(sbx)
	if err != nil {
		log.Fatalf("ep.Join: %s", err)
	}

	// libnetwork client can check the endpoint's operational data via the Info() API
	epInfo, err := ep.DriverInfo()
	if err != nil {
		log.Fatalf("ep.DriverInfo: %s", err)
	}

	macAddress, ok := epInfo[netlabel.MacAddress]
	if !ok {
		log.Fatalf("failed to get mac address from endpoint info")
	}

	fmt.Printf("Joined endpoint %s (%s) to sandbox %s (%s)\n", ep.Name(), macAddress, sbx.ContainerID(), sbx.Key())
}
开发者ID:jak-atx,项目名称:vic,代码行数:61,代码来源:readme.go


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