Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 1 | import json |
| 2 | from synchronizers.metronetwork.invokers.invoker import Invoker |
| 3 | from services.metronetwork.models import ServiceSpoke |
| 4 | from services.metronetwork.models import BandwidthProfile |
| 5 | from services.metronetwork.models import NetworkEdgeToEdgePointConnection |
| 6 | |
| 7 | class VnodGlobalServiceInvoker(Invoker): |
| 8 | |
| 9 | def __init__(self, **args): |
| 10 | pass |
| 11 | |
| 12 | # Method for handline pre save semantics |
| 13 | # content here would be model specific but could include handling Many-to-Many relationship |
| 14 | # creation - which must occur post save |
| 15 | # |
| 16 | # obj - Whatever obj was just saved |
| 17 | # returns - None - this is a pure invoke() call, return type is None |
| 18 | # |
| 19 | def presave(self, obj): |
| 20 | |
| 21 | if hasattr(obj, 'bwpname'): |
| 22 | bwprofile = BandwidthProfile.objects.get(name=obj.bwpname) |
| 23 | obj.bandwidthProfile = bwprofile |
| 24 | |
| 25 | if hasattr(obj, 'pointtopointsid'): |
| 26 | connection = NetworkEdgeToEdgePointConnection.objects.get(sid=obj.pointtopointsid) |
| 27 | obj.metronetworkpointtopoint = connection |
| 28 | |
| 29 | # Method for handline post save semantics |
| 30 | # content here would be model specific but could include handling Many-to-Many relationship |
| 31 | # creation - which must occur post save |
| 32 | # |
| 33 | # obj - Whatever obj was just saved |
| 34 | # returns - N/A - this is a pure invoke() call |
| 35 | # |
| 36 | def postsave(self, obj): |
| 37 | # |
| 38 | # Ok - we need to handle the multipoint many-to-many relationships in here |
| 39 | # |
| 40 | # By design convnetion we will look for them in the 'backend_register' object field |
| 41 | # this is a json field that is general purpose - we will expect to find a JSON array |
| 42 | # called 'eps' that just containts a reference to a bunch of NetworkEdgePorts |
| 43 | # |
| 44 | if hasattr(obj, 'spokes_createbuffer'): |
| 45 | scratchpad = json.loads(obj.spokes_createbuffer) |
| 46 | spokes = scratchpad['spokes'] |
| 47 | |
| 48 | for spokeid in spokes: |
| 49 | spoke = ServiceSpoke.objects.get(name=spokeid) |
| 50 | obj.spokes.add(spoke) |