mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #17316 from rmb938/ipam_conf_options
Add IPAM Config Options to match libnetwork
This commit is contained in:
commit
e35f5a481a
8 changed files with 36 additions and 5 deletions
|
@ -40,12 +40,14 @@ func (cli *DockerCli) CmdNetworkCreate(args ...string) error {
|
||||||
flIpamIPRange := opts.NewListOpts(nil)
|
flIpamIPRange := opts.NewListOpts(nil)
|
||||||
flIpamGateway := opts.NewListOpts(nil)
|
flIpamGateway := opts.NewListOpts(nil)
|
||||||
flIpamAux := opts.NewMapOpts(nil, nil)
|
flIpamAux := opts.NewMapOpts(nil, nil)
|
||||||
|
flIpamOpt := opts.NewMapOpts(nil, nil)
|
||||||
|
|
||||||
cmd.Var(&flIpamSubnet, []string{"-subnet"}, "subnet in CIDR format that represents a network segment")
|
cmd.Var(&flIpamSubnet, []string{"-subnet"}, "subnet in CIDR format that represents a network segment")
|
||||||
cmd.Var(&flIpamIPRange, []string{"-ip-range"}, "allocate container ip from a sub-range")
|
cmd.Var(&flIpamIPRange, []string{"-ip-range"}, "allocate container ip from a sub-range")
|
||||||
cmd.Var(&flIpamGateway, []string{"-gateway"}, "ipv4 or ipv6 Gateway for the master subnet")
|
cmd.Var(&flIpamGateway, []string{"-gateway"}, "ipv4 or ipv6 Gateway for the master subnet")
|
||||||
cmd.Var(flIpamAux, []string{"-aux-address"}, "auxiliary ipv4 or ipv6 addresses used by Network driver")
|
cmd.Var(flIpamAux, []string{"-aux-address"}, "auxiliary ipv4 or ipv6 addresses used by Network driver")
|
||||||
cmd.Var(flOpts, []string{"o", "-opt"}, "set driver specific options")
|
cmd.Var(flOpts, []string{"o", "-opt"}, "set driver specific options")
|
||||||
|
cmd.Var(flIpamOpt, []string{"-ipam-opt"}, "set IPAM driver specific options")
|
||||||
|
|
||||||
flInternal := cmd.Bool([]string{"-internal"}, false, "restricts external access to the network")
|
flInternal := cmd.Bool([]string{"-internal"}, false, "restricts external access to the network")
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ func (cli *DockerCli) CmdNetworkCreate(args ...string) error {
|
||||||
nc := types.NetworkCreate{
|
nc := types.NetworkCreate{
|
||||||
Name: cmd.Arg(0),
|
Name: cmd.Arg(0),
|
||||||
Driver: driver,
|
Driver: driver,
|
||||||
IPAM: network.IPAM{Driver: *flIpamDriver, Config: ipamCfg},
|
IPAM: network.IPAM{Driver: *flIpamDriver, Config: ipamCfg, Options: flIpamOpt.GetAll()},
|
||||||
Options: flOpts.GetAll(),
|
Options: flOpts.GetAll(),
|
||||||
CheckDuplicate: true,
|
CheckDuplicate: true,
|
||||||
Internal: *flInternal,
|
Internal: *flInternal,
|
||||||
|
|
|
@ -182,10 +182,12 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildIpamResources(r *types.NetworkResource, nw libnetwork.Network) {
|
func buildIpamResources(r *types.NetworkResource, nw libnetwork.Network) {
|
||||||
id, _, ipv4conf, ipv6conf := nw.Info().IpamConfig()
|
id, opts, ipv4conf, ipv6conf := nw.Info().IpamConfig()
|
||||||
|
|
||||||
r.IPAM.Driver = id
|
r.IPAM.Driver = id
|
||||||
|
|
||||||
|
r.IPAM.Options = opts
|
||||||
|
|
||||||
r.IPAM.Config = []network.IPAMConfig{}
|
r.IPAM.Config = []network.IPAMConfig{}
|
||||||
for _, ip4 := range ipv4conf {
|
for _, ip4 := range ipv4conf {
|
||||||
iData := network.IPAMConfig{}
|
iData := network.IPAMConfig{}
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (daemon *Daemon) CreateNetwork(name, driver string, ipam network.IPAM, opti
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf, nil))
|
nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf, ipam.Options))
|
||||||
nwOptions = append(nwOptions, libnetwork.NetworkOptionDriverOpts(options))
|
nwOptions = append(nwOptions, libnetwork.NetworkOptionDriverOpts(options))
|
||||||
if internal {
|
if internal {
|
||||||
nwOptions = append(nwOptions, libnetwork.NetworkOptionInternalNetwork())
|
nwOptions = append(nwOptions, libnetwork.NetworkOptionInternalNetwork())
|
||||||
|
|
|
@ -117,6 +117,10 @@ This section lists each version from latest to oldest. Each listing includes a
|
||||||
* `POST /networks/create` now supports restricting external access to the network by setting the `internal` field.
|
* `POST /networks/create` now supports restricting external access to the network by setting the `internal` field.
|
||||||
* `POST /networks/(id)/disconnect` now includes a `Force` option to forcefully disconnect a container from network
|
* `POST /networks/(id)/disconnect` now includes a `Force` option to forcefully disconnect a container from network
|
||||||
* `GET /containers/(id)/json` now returns the `NetworkID` of containers.
|
* `GET /containers/(id)/json` now returns the `NetworkID` of containers.
|
||||||
|
* `POST /networks/create` Now supports an options field in the IPAM config that provides options
|
||||||
|
for custom IPAM plugins.
|
||||||
|
* `GET /networks/{network-id}` Now returns IPAM config options for custom IPAM plugins if any
|
||||||
|
are available.
|
||||||
|
|
||||||
### v1.21 API changes
|
### v1.21 API changes
|
||||||
|
|
||||||
|
|
|
@ -2956,7 +2956,10 @@ Content-Type: application/json
|
||||||
{
|
{
|
||||||
"Subnet": "172.17.0.0/16"
|
"Subnet": "172.17.0.0/16"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"Options": {
|
||||||
|
"foo": "bar"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Containers": {
|
"Containers": {
|
||||||
"39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": {
|
"39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": {
|
||||||
|
@ -3003,7 +3006,10 @@ Content-Type: application/json
|
||||||
"Subnet":"172.20.0.0/16",
|
"Subnet":"172.20.0.0/16",
|
||||||
"IPRange":"172.20.10.0/24",
|
"IPRange":"172.20.10.0/24",
|
||||||
"Gateway":"172.20.10.11"
|
"Gateway":"172.20.10.11"
|
||||||
}]
|
}],
|
||||||
|
"Options": {
|
||||||
|
"foo": "bar"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Internal":true
|
"Internal":true
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ parent = "smn_cli"
|
||||||
--ip-range=[] Allocate container ip from a sub-range
|
--ip-range=[] Allocate container ip from a sub-range
|
||||||
--ipam-driver=default IP Address Management Driver
|
--ipam-driver=default IP Address Management Driver
|
||||||
-o --opt=map[] Set custom network plugin options
|
-o --opt=map[] Set custom network plugin options
|
||||||
|
--ipam-opt=map[] Set custom IPAM plugin options
|
||||||
--subnet=[] Subnet in CIDR format that represents a network segment
|
--subnet=[] Subnet in CIDR format that represents a network segment
|
||||||
|
|
||||||
Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the
|
Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the
|
||||||
|
|
|
@ -523,6 +523,18 @@ func (s *DockerNetworkSuite) TestDockerNetworkCustomIpam(c *check.C) {
|
||||||
assertNwNotAvailable(c, "br0")
|
assertNwNotAvailable(c, "br0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerNetworkSuite) TestDockerNetworkIpamOptions(c *check.C) {
|
||||||
|
// Create a bridge network using custom ipam driver and options
|
||||||
|
dockerCmd(c, "network", "create", "--ipam-driver", dummyIpamDriver, "--ipam-opt", "opt1=drv1", "--ipam-opt", "opt2=drv2", "br0")
|
||||||
|
assertNwIsAvailable(c, "br0")
|
||||||
|
|
||||||
|
// Verify expected network ipam options
|
||||||
|
nr := getNetworkResource(c, "br0")
|
||||||
|
opts := nr.IPAM.Options
|
||||||
|
c.Assert(opts["opt1"], checker.Equals, "drv1")
|
||||||
|
c.Assert(opts["opt2"], checker.Equals, "drv2")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DockerNetworkSuite) TestDockerNetworkInspect(c *check.C) {
|
func (s *DockerNetworkSuite) TestDockerNetworkInspect(c *check.C) {
|
||||||
// if unspecified, network gateway will be selected from inside preferred pool
|
// if unspecified, network gateway will be selected from inside preferred pool
|
||||||
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")
|
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
|
||||||
[**--internal**]
|
[**--internal**]
|
||||||
[**--ip-range**=*[]*]
|
[**--ip-range**=*[]*]
|
||||||
[**--ipam-driver**=*default*]
|
[**--ipam-driver**=*default*]
|
||||||
|
[**--ipam-opt**=*map[]*]
|
||||||
[**-o**|**--opt**=*map[]*]
|
[**-o**|**--opt**=*map[]*]
|
||||||
[**--subnet**=*[]*]
|
[**--subnet**=*[]*]
|
||||||
NETWORK-NAME
|
NETWORK-NAME
|
||||||
|
@ -148,6 +149,9 @@ If you want to create an externally isolated `overlay` network, you can specify
|
||||||
**--ipam-driver**=*default*
|
**--ipam-driver**=*default*
|
||||||
IP Address Management Driver
|
IP Address Management Driver
|
||||||
|
|
||||||
|
**--ipam-opt**=map[]
|
||||||
|
Set custom IPAM plugin options
|
||||||
|
|
||||||
**-o**, **--opt**=map[]
|
**-o**, **--opt**=map[]
|
||||||
Set custom network plugin options
|
Set custom network plugin options
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue