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 core.models import Site |
| 4 | from services.metronetwork.models import RemotePort |
| 5 | |
| 6 | |
| 7 | class ServiceSpokeInvoker(Invoker): |
| 8 | def __init__(self, **args): |
| 9 | pass |
| 10 | |
| 11 | # Method for handline pre save semantics |
| 12 | # content here would be model specific but could include handling Many-to-Many relationship |
| 13 | # creation - which must occur post save |
| 14 | # |
| 15 | # obj - Whatever obj was just saved |
| 16 | # returns - None - this is a pure invoke() call, return type is None |
| 17 | # |
| 18 | def presave(self, obj): |
| 19 | # Now that the Ports are created - get a proper reference to them and update the |
| 20 | # src and dst fields |
| 21 | if hasattr(obj, 'sitename'): |
| 22 | site = Site.objects.get(login_base=obj.sitename) |
| 23 | obj.vnodlocalsite = site |
| 24 | |
| 25 | if hasattr(obj, 'remoteportname'): |
| 26 | remoteport = RemotePort.objects.get(name=obj.remoteportname) |
| 27 | obj.vnodlocalport = remoteport |
| 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 | pass |