blob: 9b8e88b9cc8ed79a2839d21b883fb59b26927dc1 [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
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050020 if hasattr(obj, 'root_createbuffer'):
21 rootEdgePort = NetworkEdgePort.objects.get(pid=obj.root_createbuffer)
22 obj.root = rootEdgePort
Rizwan Haider65baf552016-09-28 16:47:28 -040023
24
25 # Method for handline post save semantics
26 # content here would be model specific but could include handling Many-to-Many relationship
27 # creation - which must occur post save
28 #
29 # obj - Whatever obj was just saved
30 # returns - N/A - this is a pure invoke() call
31 #
32 def postsave(self, obj):
33 #
34 # Ok - we need to handle the multipoint many-to-many relationships in here
35 #
36 # By design convnetion we will look for them in the 'backend_register' object field
37 # this is a json field that is general purpose - we will expect to find a JSON array
38 # called 'eps' that just containts a reference to a bunch of NetworkEdgePorts
39 #
40 #
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050041 if hasattr(obj, 'eps_createbuffer'):
42 scratchpad = json.loads(obj.eps_createbuffer)
43 eps = scratchpad['eps']
Rizwan Haider65baf552016-09-28 16:47:28 -040044
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050045 for ep in eps:
46 port = NetworkEdgePort.objects.get(pid=ep)
47 obj.eps.add(port)