blob: a0b7ffd255ec7023d19ef4f1126f30b1c7ba9034 [file] [log] [blame]
Rizwan Haider65baf552016-09-28 16:47:28 -04001import json
2from synchronizers.metronetwork.invokers.invoker import Invoker
3from services.metronetwork.models import NetworkEdgeToMultipointConnection, NetworkEdgePort
4
5class NetworkEdgeToMultipointInvoker(Invoker):
6
7 def __init__(self, **args):
8 pass
9
10 # Method for handline pre save semantics
11 # content here would be model specific but could include handling Many-to-Many relationship
12 # creation - which must occur post save
13 #
14 # obj - Whatever obj was just saved
15 # returns - None - this is a pure invoke() call, return type is None
16 #
17 def presave(self, obj):
18 # Now that the Ports are created - get a proper reference to them and update the
19 # root field
20 rootEdgePort = NetworkEdgePort.objects.get(pid=obj.root_createbuffer)
21 obj.root = rootEdgePort
22
23
24 # Method for handline post save semantics
25 # content here would be model specific but could include handling Many-to-Many relationship
26 # creation - which must occur post save
27 #
28 # obj - Whatever obj was just saved
29 # returns - N/A - this is a pure invoke() call
30 #
31 def postsave(self, obj):
32 #
33 # Ok - we need to handle the multipoint many-to-many relationships in here
34 #
35 # By design convnetion we will look for them in the 'backend_register' object field
36 # this is a json field that is general purpose - we will expect to find a JSON array
37 # called 'eps' that just containts a reference to a bunch of NetworkEdgePorts
38 #
39 #
40 scratchpad = json.loads(obj.eps_createbuffer)
41 eps = scratchpad['eps']
42
43 for ep in eps:
44 port = NetworkEdgePort.objects.get(pid=ep)
45 obj.eps.add(port)