pyIPAM - Docker Plugin for IPAM written in Python
Jacek Kowalski
2020-05-18 f0d935291715742b2e9f71c1b5e1ecbf23d02eff
commit | author | age
659253 1 from docker_plugin_api.Plugin import Blueprint
JK 2 import flask
3 from .Ipam import *
4 from .IpamDriverData import *
5 from docker_plugin_api.IpamDriverEntities import *
6
7 app = Blueprint('IpamDriver', __name__)
8
9
10 @app.route('/IpamDriver.GetCapabilities', methods=['POST'])
11 def GetCapabilities():
12     return {
13         'RequiresMACAddress': True,
14         'RequiresRequestReplay': True,
15     }
16
17
18 @app.route('/IpamDriver.GetDefaultAddressSpaces', methods=['POST'])
19 def GetDefaultAddressSpaces():
20     return {
21         'LocalDefaultAddressSpace': 'local',
22         'GlobalDefaultAddressSpace': 'global',
23     }
24
25
26 @app.route('/IpamDriver.RequestPool', methods=['POST'])
27 def RequestPool():
28     request = RequestPoolEntity(**flask.request.get_json(force=True))
29     space = spaces[request.AddressSpace]
30     pool = Pool(pool=request.Pool, subPool=request.SubPool, options=request.Options, v6=request.V6)
31     pool_id = space.add_pool(pool)
32     full_id = '{}-{}'.format(space.name, pool_id)
33     return {
34         'PoolID': full_id,
35         'Pool': str(pool),
36         'Data': {},
37     }
38
39
40 @app.route('/IpamDriver.ReleasePool', methods=['POST'])
41 def ReleasePool():
42     request = ReleasePoolEntity(**flask.request.get_json(force=True))
43     space, pool = get_space_pool(request.PoolID)
44     space.remove_pool(pool)
45     return {}
46
47
48 @app.route('/IpamDriver.RequestAddress', methods=['POST'])
49 def RequestAddress():
50     request = RequestAddressEntity(**flask.request.get_json(force=True))
51     space, pool = get_space_pool(request.PoolID)
52     address = pool.allocate(request.Address)
53     return {
54         'Address': address,
55         'Data': {},
56     }
57
58
59 @app.route('/IpamDriver.ReleaseAddress', methods=['POST'])
60 def ReleaseAddress():
61     request = ReleaseAddressEntity(**flask.request.get_json(force=True))
62     space, pool = get_space_pool(request.PoolID)
63     pool.deallocate(request.Address)
64     return {}
65
66
67 __all__ = ['app']