Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 1 | import json |
| 2 | from synchronizers.metronetwork.invokers.invoker import Invoker |
| 3 | from services.metronetwork.models import NetworkEdgeToMultipointConnection, NetworkEdgePort |
| 4 | |
| 5 | class 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 Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame^] | 20 | if hasattr(obj, 'root_createbuffer'): |
| 21 | rootEdgePort = NetworkEdgePort.objects.get(pid=obj.root_createbuffer) |
| 22 | obj.root = rootEdgePort |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 23 | |
| 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 Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame^] | 41 | if hasattr(obj, 'eps_createbuffer'): |
| 42 | scratchpad = json.loads(obj.eps_createbuffer) |
| 43 | eps = scratchpad['eps'] |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 44 | |
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame^] | 45 | for ep in eps: |
| 46 | port = NetworkEdgePort.objects.get(pid=ep) |
| 47 | obj.eps.add(port) |