Browse code

Changed Labels to DriverOpts

Signed-off-by: Madhu Venugopal <madhu@docker.com>

Madhu Venugopal authored on 2015/10/15 08:38:46
Showing 7 changed files
... ...
@@ -279,8 +279,8 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
279 279
 	processCreateDefaults(c, &create)
280 280
 
281 281
 	options := []libnetwork.NetworkOption{}
282
-	if len(create.Labels) > 0 {
283
-		options = append(options, libnetwork.NetworkOptionLabels(create.Labels))
282
+	if len(create.DriverOpts) > 0 {
283
+		options = append(options, libnetwork.NetworkOptionDriverOpts(create.DriverOpts))
284 284
 	}
285 285
 	nw, err := c.NewNetwork(create.NetworkType, create.Name, options...)
286 286
 	if err != nil {
... ...
@@ -229,7 +229,7 @@ func TestCreateDeleteNetwork(t *testing.T) {
229 229
 		bridge.BridgeName:   "abc",
230 230
 		netlabel.EnableIPv6: "true",
231 231
 	}
232
-	nc := networkCreate{Name: "network_1", NetworkType: bridgeNetType, Labels: ops}
232
+	nc := networkCreate{Name: "network_1", NetworkType: bridgeNetType, DriverOpts: ops}
233 233
 	goodBody, err := json.Marshal(nc)
234 234
 	if err != nil {
235 235
 		t.Fatal(err)
... ...
@@ -263,7 +263,7 @@ func TestCreateDeleteNetwork(t *testing.T) {
263 263
 		netlabel.EnableIPv6: "true",
264 264
 		bridge.BridgeName:   "abc",
265 265
 	}
266
-	nc = networkCreate{Name: "network_2", NetworkType: bridgeNetType, Labels: labels}
266
+	nc = networkCreate{Name: "network_2", NetworkType: bridgeNetType, DriverOpts: labels}
267 267
 	goodBody, err = json.Marshal(nc)
268 268
 	if err != nil {
269 269
 		t.Fatal(err)
... ...
@@ -297,7 +297,7 @@ func TestGetNetworksAndEndpoints(t *testing.T) {
297 297
 	ops := map[string]string{
298 298
 		bridge.BridgeName: "api_test_nw",
299 299
 	}
300
-	nc := networkCreate{Name: "sh", NetworkType: bridgeNetType, Labels: ops}
300
+	nc := networkCreate{Name: "sh", NetworkType: bridgeNetType, DriverOpts: ops}
301 301
 	body, err := json.Marshal(nc)
302 302
 	if err != nil {
303 303
 		t.Fatal(err)
... ...
@@ -1837,7 +1837,7 @@ func TestEndToEnd(t *testing.T) {
1837 1837
 	}
1838 1838
 
1839 1839
 	// Create network
1840
-	nc := networkCreate{Name: "network-fiftyfive", NetworkType: bridgeNetType, Labels: ops}
1840
+	nc := networkCreate{Name: "network-fiftyfive", NetworkType: bridgeNetType, DriverOpts: ops}
1841 1841
 	body, err := json.Marshal(nc)
1842 1842
 	if err != nil {
1843 1843
 		t.Fatal(err)
... ...
@@ -36,7 +36,7 @@ type sandboxResource struct {
36 36
 type networkCreate struct {
37 37
 	Name        string            `json:"name"`
38 38
 	NetworkType string            `json:"network_type"`
39
-	Labels      map[string]string `json:"labels"`
39
+	DriverOpts  map[string]string `json:"driver_opts"`
40 40
 }
41 41
 
42 42
 // endpointCreate represents the body of the "create endpoint" http request message
... ...
@@ -48,8 +48,8 @@ func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
48 48
 	}
49 49
 
50 50
 	// Construct network create request body
51
-	var labels []string
52
-	nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, Labels: labels}
51
+	var driverOpts []string
52
+	nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, DriverOpts: driverOpts}
53 53
 	obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
54 54
 	if err != nil {
55 55
 		return err
... ...
@@ -36,7 +36,7 @@ type SandboxResource struct {
36 36
 type networkCreate struct {
37 37
 	Name        string   `json:"name"`
38 38
 	NetworkType string   `json:"network_type"`
39
-	Labels      []string `json:"labels"`
39
+	DriverOpts  []string `json:"driver_opts"`
40 40
 }
41 41
 
42 42
 // serviceCreate represents the body of the "publish service" http request message
... ...
@@ -74,7 +74,6 @@ type NetworkController interface {
74 74
 	Config() config.Config
75 75
 
76 76
 	// Create a new network. The options parameter carries network specific options.
77
-	// Labels support will be added in the near future.
78 77
 	NewNetwork(networkType, name string, options ...NetworkOption) (Network, error)
79 78
 
80 79
 	// Networks returns the list of Network(s) managed by this controller.
... ...
@@ -33,7 +33,6 @@ type Network interface {
33 33
 
34 34
 	// Create a new endpoint to this network symbolically identified by the
35 35
 	// specified unique name. The options parameter carry driver specific options.
36
-	// Labels support will be added in the near future.
37 36
 	CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error)
38 37
 
39 38
 	// Delete the network.
... ...
@@ -58,7 +57,7 @@ type Network interface {
58 58
 // NetworkInfo returns some configuration and operational information about the network
59 59
 type NetworkInfo interface {
60 60
 	IpamConfig() (string, []*IpamConf, []*IpamConf)
61
-	Labels() map[string]string
61
+	DriverOptions() map[string]string
62 62
 	Scope() string
63 63
 }
64 64
 
... ...
@@ -402,7 +401,7 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
402 402
 
403 403
 	if v, ok := netMap["generic"]; ok {
404 404
 		n.generic = v.(map[string]interface{})
405
-		// Restore labels in their map[string]string form
405
+		// Restore opts in their map[string]string form
406 406
 		if v, ok := n.generic[netlabel.GenericData]; ok {
407 407
 			var lmap map[string]string
408 408
 			ba, err := json.Marshal(v)
... ...
@@ -484,19 +483,19 @@ func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ip
484 484
 	}
485 485
 }
486 486
 
487
-// NetworkOptionLabels function returns an option setter for any parameter described by a map
488
-func NetworkOptionLabels(labels map[string]string) NetworkOption {
487
+// NetworkOptionDriverOpts function returns an option setter for any parameter described by a map
488
+func NetworkOptionDriverOpts(opts map[string]string) NetworkOption {
489 489
 	return func(n *network) {
490 490
 		if n.generic == nil {
491 491
 			n.generic = make(map[string]interface{})
492 492
 		}
493
-		if labels == nil {
494
-			labels = make(map[string]string)
493
+		if opts == nil {
494
+			opts = make(map[string]string)
495 495
 		}
496 496
 		// Store the options
497
-		n.generic[netlabel.GenericData] = labels
497
+		n.generic[netlabel.GenericData] = opts
498 498
 		// Decode and store the endpoint options of libnetwork interest
499
-		if val, ok := labels[netlabel.EnableIPv6]; ok {
499
+		if val, ok := opts[netlabel.EnableIPv6]; ok {
500 500
 			var err error
501 501
 			if n.enableIPv6, err = strconv.ParseBool(val); err != nil {
502 502
 				log.Warnf("Failed to parse %s' value: %s (%s)", netlabel.EnableIPv6, val, err.Error())
... ...
@@ -1056,7 +1055,7 @@ func (n *network) Info() NetworkInfo {
1056 1056
 	return n
1057 1057
 }
1058 1058
 
1059
-func (n *network) Labels() map[string]string {
1059
+func (n *network) DriverOptions() map[string]string {
1060 1060
 	n.Lock()
1061 1061
 	defer n.Unlock()
1062 1062
 	if n.generic != nil {