libnetwork/ipams/null: use consts for fixed values
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
63d477b20e
commit
821ef5cbaf
2 changed files with 13 additions and 12 deletions
|
@ -3,27 +3,28 @@
|
|||
package null
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/types"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultAS = "null"
|
||||
defaultPool, _ = types.ParseCIDR("0.0.0.0/0")
|
||||
defaultPoolID = fmt.Sprintf("%s/%s", defaultAS, defaultPool.String())
|
||||
const (
|
||||
defaultAddressSpace = "null"
|
||||
defaultPoolCIDR = "0.0.0.0/0"
|
||||
defaultPoolID = defaultAddressSpace + "/" + defaultPoolCIDR
|
||||
)
|
||||
|
||||
var defaultPool, _ = types.ParseCIDR(defaultPoolCIDR)
|
||||
|
||||
type allocator struct{}
|
||||
|
||||
func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
|
||||
return defaultAS, defaultAS, nil
|
||||
return defaultAddressSpace, defaultAddressSpace, nil
|
||||
}
|
||||
|
||||
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
|
||||
if addressSpace != defaultAS {
|
||||
func (a *allocator) RequestPool(addressSpace, pool, subPool string, _ map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
|
||||
if addressSpace != defaultAddressSpace {
|
||||
return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
|
||||
}
|
||||
if pool != "" {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
func TestPoolRequest(t *testing.T) {
|
||||
a := allocator{}
|
||||
|
||||
pid, pool, _, err := a.RequestPool(defaultAS, "", "", nil, false)
|
||||
pid, pool, _, err := a.RequestPool(defaultAddressSpace, "", "", nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -25,17 +25,17 @@ func TestPoolRequest(t *testing.T) {
|
|||
t.Fatal("Unexpected success")
|
||||
}
|
||||
|
||||
_, _, _, err = a.RequestPool(defaultAS, "192.168.0.0/16", "", nil, false)
|
||||
_, _, _, err = a.RequestPool(defaultAddressSpace, "192.168.0.0/16", "", nil, false)
|
||||
if err == nil {
|
||||
t.Fatal("Unexpected success")
|
||||
}
|
||||
|
||||
_, _, _, err = a.RequestPool(defaultAS, "", "192.168.0.0/24", nil, false)
|
||||
_, _, _, err = a.RequestPool(defaultAddressSpace, "", "192.168.0.0/24", nil, false)
|
||||
if err == nil {
|
||||
t.Fatal("Unexpected success")
|
||||
}
|
||||
|
||||
_, _, _, err = a.RequestPool(defaultAS, "", "", nil, true)
|
||||
_, _, _, err = a.RequestPool(defaultAddressSpace, "", "", nil, true)
|
||||
if err == nil {
|
||||
t.Fatal("Unexpected success")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue