Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / docker / libnetwork / ipams / null / null.go
1 // Package null implements the null ipam driver. Null ipam driver satisfies ipamapi contract,
2 // but does not effectively reserve/allocate any address pool or address
3 package null
4
5 import (
6         "fmt"
7         "net"
8
9         "github.com/docker/libnetwork/discoverapi"
10         "github.com/docker/libnetwork/ipamapi"
11         "github.com/docker/libnetwork/types"
12 )
13
14 var (
15         defaultAS      = "null"
16         defaultPool, _ = types.ParseCIDR("0.0.0.0/0")
17         defaultPoolID  = fmt.Sprintf("%s/%s", defaultAS, defaultPool.String())
18 )
19
20 type allocator struct{}
21
22 func (a *allocator) GetDefaultAddressSpaces() (string, string, error) {
23         return defaultAS, defaultAS, nil
24 }
25
26 func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
27         if addressSpace != defaultAS {
28                 return "", nil, nil, types.BadRequestErrorf("unknown address space: %s", addressSpace)
29         }
30         if pool != "" {
31                 return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address pool requests")
32         }
33         if subPool != "" {
34                 return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle specific address subpool requests")
35         }
36         if v6 {
37                 return "", nil, nil, types.BadRequestErrorf("null ipam driver does not handle IPv6 address pool pool requests")
38         }
39         return defaultPoolID, defaultPool, nil, nil
40 }
41
42 func (a *allocator) ReleasePool(poolID string) error {
43         return nil
44 }
45
46 func (a *allocator) RequestAddress(poolID string, ip net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) {
47         if poolID != defaultPoolID {
48                 return nil, nil, types.BadRequestErrorf("unknown pool id: %s", poolID)
49         }
50         return nil, nil, nil
51 }
52
53 func (a *allocator) ReleaseAddress(poolID string, ip net.IP) error {
54         if poolID != defaultPoolID {
55                 return types.BadRequestErrorf("unknown pool id: %s", poolID)
56         }
57         return nil
58 }
59
60 func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
61         return nil
62 }
63
64 func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
65         return nil
66 }
67
68 func (a *allocator) IsBuiltIn() bool {
69         return true
70 }
71
72 // Init registers a remote ipam when its plugin is activated
73 func Init(ic ipamapi.Callback, l, g interface{}) error {
74         return ic.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{})
75 }