Add IPAM Config Options to match libnetwork
| ... | ... |
@@ -40,12 +40,14 @@ func (cli *DockerCli) CmdNetworkCreate(args ...string) error {
|
| 40 | 40 |
flIpamIPRange := opts.NewListOpts(nil) |
| 41 | 41 |
flIpamGateway := opts.NewListOpts(nil) |
| 42 | 42 |
flIpamAux := opts.NewMapOpts(nil, nil) |
| 43 |
+ flIpamOpt := opts.NewMapOpts(nil, nil) |
|
| 43 | 44 |
|
| 44 | 45 |
cmd.Var(&flIpamSubnet, []string{"-subnet"}, "subnet in CIDR format that represents a network segment")
|
| 45 | 46 |
cmd.Var(&flIpamIPRange, []string{"-ip-range"}, "allocate container ip from a sub-range")
|
| 46 | 47 |
cmd.Var(&flIpamGateway, []string{"-gateway"}, "ipv4 or ipv6 Gateway for the master subnet")
|
| 47 | 48 |
cmd.Var(flIpamAux, []string{"-aux-address"}, "auxiliary ipv4 or ipv6 addresses used by Network driver")
|
| 48 | 49 |
cmd.Var(flOpts, []string{"o", "-opt"}, "set driver specific options")
|
| 50 |
+ cmd.Var(flIpamOpt, []string{"-ipam-opt"}, "set IPAM driver specific options")
|
|
| 49 | 51 |
|
| 50 | 52 |
flInternal := cmd.Bool([]string{"-internal"}, false, "restricts external access to the network")
|
| 51 | 53 |
|
| ... | ... |
@@ -71,7 +73,7 @@ func (cli *DockerCli) CmdNetworkCreate(args ...string) error {
|
| 71 | 71 |
nc := types.NetworkCreate{
|
| 72 | 72 |
Name: cmd.Arg(0), |
| 73 | 73 |
Driver: driver, |
| 74 |
- IPAM: network.IPAM{Driver: *flIpamDriver, Config: ipamCfg},
|
|
| 74 |
+ IPAM: network.IPAM{Driver: *flIpamDriver, Config: ipamCfg, Options: flIpamOpt.GetAll()},
|
|
| 75 | 75 |
Options: flOpts.GetAll(), |
| 76 | 76 |
CheckDuplicate: true, |
| 77 | 77 |
Internal: *flInternal, |
| ... | ... |
@@ -182,10 +182,12 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
|
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 | 184 |
func buildIpamResources(r *types.NetworkResource, nw libnetwork.Network) {
|
| 185 |
- id, _, ipv4conf, ipv6conf := nw.Info().IpamConfig() |
|
| 185 |
+ id, opts, ipv4conf, ipv6conf := nw.Info().IpamConfig() |
|
| 186 | 186 |
|
| 187 | 187 |
r.IPAM.Driver = id |
| 188 | 188 |
|
| 189 |
+ r.IPAM.Options = opts |
|
| 190 |
+ |
|
| 189 | 191 |
r.IPAM.Config = []network.IPAMConfig{}
|
| 190 | 192 |
for _, ip4 := range ipv4conf {
|
| 191 | 193 |
iData := network.IPAMConfig{}
|
| ... | ... |
@@ -114,7 +114,7 @@ func (daemon *Daemon) CreateNetwork(name, driver string, ipam network.IPAM, opti |
| 114 | 114 |
return nil, err |
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 |
- nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf, nil)) |
|
| 117 |
+ nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf, ipam.Options)) |
|
| 118 | 118 |
nwOptions = append(nwOptions, libnetwork.NetworkOptionDriverOpts(options)) |
| 119 | 119 |
if internal {
|
| 120 | 120 |
nwOptions = append(nwOptions, libnetwork.NetworkOptionInternalNetwork()) |
| ... | ... |
@@ -117,6 +117,10 @@ This section lists each version from latest to oldest. Each listing includes a |
| 117 | 117 |
* `POST /networks/create` now supports restricting external access to the network by setting the `internal` field. |
| 118 | 118 |
* `POST /networks/(id)/disconnect` now includes a `Force` option to forcefully disconnect a container from network |
| 119 | 119 |
* `GET /containers/(id)/json` now returns the `NetworkID` of containers. |
| 120 |
+* `POST /networks/create` Now supports an options field in the IPAM config that provides options |
|
| 121 |
+ for custom IPAM plugins. |
|
| 122 |
+* `GET /networks/{network-id}` Now returns IPAM config options for custom IPAM plugins if any
|
|
| 123 |
+ are available. |
|
| 120 | 124 |
|
| 121 | 125 |
### v1.21 API changes |
| 122 | 126 |
|
| ... | ... |
@@ -2956,7 +2956,10 @@ Content-Type: application/json |
| 2956 | 2956 |
{
|
| 2957 | 2957 |
"Subnet": "172.17.0.0/16" |
| 2958 | 2958 |
} |
| 2959 |
- ] |
|
| 2959 |
+ ], |
|
| 2960 |
+ "Options": {
|
|
| 2961 |
+ "foo": "bar" |
|
| 2962 |
+ } |
|
| 2960 | 2963 |
}, |
| 2961 | 2964 |
"Containers": {
|
| 2962 | 2965 |
"39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": {
|
| ... | ... |
@@ -3003,7 +3006,10 @@ Content-Type: application/json |
| 3003 | 3003 |
"Subnet":"172.20.0.0/16", |
| 3004 | 3004 |
"IPRange":"172.20.10.0/24", |
| 3005 | 3005 |
"Gateway":"172.20.10.11" |
| 3006 |
- }] |
|
| 3006 |
+ }], |
|
| 3007 |
+ "Options": {
|
|
| 3008 |
+ "foo": "bar" |
|
| 3009 |
+ } |
|
| 3007 | 3010 |
}, |
| 3008 | 3011 |
"Internal":true |
| 3009 | 3012 |
} |
| ... | ... |
@@ -22,6 +22,7 @@ parent = "smn_cli" |
| 22 | 22 |
--ip-range=[] Allocate container ip from a sub-range |
| 23 | 23 |
--ipam-driver=default IP Address Management Driver |
| 24 | 24 |
-o --opt=map[] Set custom network plugin options |
| 25 |
+ --ipam-opt=map[] Set custom IPAM plugin options |
|
| 25 | 26 |
--subnet=[] Subnet in CIDR format that represents a network segment |
| 26 | 27 |
|
| 27 | 28 |
Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the |
| ... | ... |
@@ -523,6 +523,18 @@ func (s *DockerNetworkSuite) TestDockerNetworkCustomIpam(c *check.C) {
|
| 523 | 523 |
assertNwNotAvailable(c, "br0") |
| 524 | 524 |
} |
| 525 | 525 |
|
| 526 |
+func (s *DockerNetworkSuite) TestDockerNetworkIpamOptions(c *check.C) {
|
|
| 527 |
+ // Create a bridge network using custom ipam driver and options |
|
| 528 |
+ dockerCmd(c, "network", "create", "--ipam-driver", dummyIpamDriver, "--ipam-opt", "opt1=drv1", "--ipam-opt", "opt2=drv2", "br0") |
|
| 529 |
+ assertNwIsAvailable(c, "br0") |
|
| 530 |
+ |
|
| 531 |
+ // Verify expected network ipam options |
|
| 532 |
+ nr := getNetworkResource(c, "br0") |
|
| 533 |
+ opts := nr.IPAM.Options |
|
| 534 |
+ c.Assert(opts["opt1"], checker.Equals, "drv1") |
|
| 535 |
+ c.Assert(opts["opt2"], checker.Equals, "drv2") |
|
| 536 |
+} |
|
| 537 |
+ |
|
| 526 | 538 |
func (s *DockerNetworkSuite) TestDockerNetworkInspect(c *check.C) {
|
| 527 | 539 |
// if unspecified, network gateway will be selected from inside preferred pool |
| 528 | 540 |
dockerCmd(c, "network", "create", "--driver=bridge", "--subnet=172.28.0.0/16", "--ip-range=172.28.5.0/24", "--gateway=172.28.5.254", "br0") |
| ... | ... |
@@ -13,6 +13,7 @@ docker-network-create - create a new network |
| 13 | 13 |
[**--internal**] |
| 14 | 14 |
[**--ip-range**=*[]*] |
| 15 | 15 |
[**--ipam-driver**=*default*] |
| 16 |
+[**--ipam-opt**=*map[]*] |
|
| 16 | 17 |
[**-o**|**--opt**=*map[]*] |
| 17 | 18 |
[**--subnet**=*[]*] |
| 18 | 19 |
NETWORK-NAME |
| ... | ... |
@@ -148,6 +149,9 @@ If you want to create an externally isolated `overlay` network, you can specify |
| 148 | 148 |
**--ipam-driver**=*default* |
| 149 | 149 |
IP Address Management Driver |
| 150 | 150 |
|
| 151 |
+**--ipam-opt**=map[] |
|
| 152 |
+ Set custom IPAM plugin options |
|
| 153 |
+ |
|
| 151 | 154 |
**-o**, **--opt**=map[] |
| 152 | 155 |
Set custom network plugin options |
| 153 | 156 |
|