blob: 99acd89b74dede76f56684f2e09240967c0c6496 [file] [log] [blame]
Matteo Scandolofcf842e2017-08-08 13:05:25 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050017import json
18from synchronizers.metronetwork.invokers.invoker import Invoker
19from services.metronetwork.models import ServiceSpoke
20from services.metronetwork.models import BandwidthProfile
21from services.metronetwork.models import NetworkEdgeToEdgePointConnection
22
23class VnodGlobalServiceInvoker(Invoker):
24
25 def __init__(self, **args):
26 pass
27
28 # Method for handline pre save semantics
29 # content here would be model specific but could include handling Many-to-Many relationship
30 # creation - which must occur post save
31 #
32 # obj - Whatever obj was just saved
33 # returns - None - this is a pure invoke() call, return type is None
34 #
35 def presave(self, obj):
36
37 if hasattr(obj, 'bwpname'):
38 bwprofile = BandwidthProfile.objects.get(name=obj.bwpname)
39 obj.bandwidthProfile = bwprofile
40
41 if hasattr(obj, 'pointtopointsid'):
42 connection = NetworkEdgeToEdgePointConnection.objects.get(sid=obj.pointtopointsid)
43 obj.metronetworkpointtopoint = connection
44
45 # Method for handline post save semantics
46 # content here would be model specific but could include handling Many-to-Many relationship
47 # creation - which must occur post save
48 #
49 # obj - Whatever obj was just saved
50 # returns - N/A - this is a pure invoke() call
51 #
52 def postsave(self, obj):
53 #
54 # Ok - we need to handle the multipoint many-to-many relationships in here
55 #
56 # By design convnetion we will look for them in the 'backend_register' object field
57 # this is a json field that is general purpose - we will expect to find a JSON array
58 # called 'eps' that just containts a reference to a bunch of NetworkEdgePorts
59 #
60 if hasattr(obj, 'spokes_createbuffer'):
61 scratchpad = json.loads(obj.spokes_createbuffer)
62 spokes = scratchpad['spokes']
63
64 for spokeid in spokes:
65 spoke = ServiceSpoke.objects.get(name=spokeid)
66 obj.spokes.add(spoke)