blob: 40cea4ab286ad10bda7c6891365cd0dee6b8fd9c [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 Haider65baf552016-09-28 16:47:28 -040017import json
18from synchronizers.metronetwork.invokers.invoker import Invoker
19from services.metronetwork.models import NetworkMultipointToMultipointConnection, NetworkEdgePort
20
21class NetworkMultipointToMultipointInvoker(Invoker):
22
23 def __init__(self, **args):
24 pass
25
26 # Method for handline pre save semantics
27 # content here would be model specific but could include handling Many-to-Many relationship
28 # creation - which must occur post save
29 #
30 # obj - Whatever obj was just saved
31 # returns - None - this is a pure invoke() call, return type is None
32 #
33 def presave(self, obj):
34 pass
35
36
37 # Method for handline post save semantics
38 # content here would be model specific but could include handling Many-to-Many relationship
39 # creation - which must occur post save
40 #
41 # obj - Whatever obj was just saved
42 # returns - N/A - this is a pure invoke() call
43 #
44 def postsave(self, obj):
45 #
46 # Ok - we need to handle the multipoint many-to-many relationships in here
47 #
48 # By design convnetion we will look for them in the 'backend_register' object field
49 # this is a json field that is general purpose - we will expect to find a JSON array
50 # called 'eps' that just containts a reference to a bunch of NetworkEdgePorts
51 #
52 #
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050053 if hasattr(obj, 'eps_createbuffer'):
54 scratchpad = json.loads(obj.eps_createbuffer)
55 eps = scratchpad['eps']
Rizwan Haider65baf552016-09-28 16:47:28 -040056
Rizwan Haidere6ffdc02016-11-08 13:43:48 -050057 for ep in eps:
58 port = NetworkEdgePort.objects.get(pid=ep)
59 obj.eps.add(port)