blob: 436f77b65b4edf19c5570cc60c3f0aceb6083611 [file] [log] [blame]
Matteo Scandolo4e0e88c2017-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 Haider51fdb3f2016-11-09 18:29:32 -050017from xos.logger import Logger, logging
18from synchronizers.vnodlocal.pseudowireproviders.pseudowireprovider import PseudowireProvider
19from services.metronetwork.models import NetworkEdgeToEdgePointConnection, NetworkEdgePort
20
21logger = Logger(level=logging.INFO)
22
23class MetronetworkPseudowireProvider(PseudowireProvider):
24
25 def __init__(self, **args):
26 pass
27
28 # Methods to support creation
29 #
30 # Returns: handle
31 #
32 def create(self, port1, port2, vlanid, psuedowireservice):
33 # Create method - create eline with the ports
34 # Vlan is TBD
Michael Best162b08e2016-11-10 15:44:50 -050035 pseudowirename = ("Vlan: %s" % vlanid)
Rizwan Haider51fdb3f2016-11-09 18:29:32 -050036 logger.info("Metronetwork create called, name: %s" % pseudowirename )
37 # Edge to Edge Point Connectivity creation
38 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection()
39 uni1port = NetworkEdgePort.objects.filter(pid__icontains=port1)
40 if uni1port:
41 uni1port = uni1port[0]
42 uni2port = NetworkEdgePort.objects.filter(pid__icontains=port2)
43 if uni2port:
44 uni2port = uni2port[0]
45 edgetoedgeconnectivity.uni1 = uni1port
46 edgetoedgeconnectivity.uni2 = uni2port
47 edgetoedgeconnectivity.vlanid = vlanid
48 edgetoedgeconnectivity.type = 'Point_To_Point'
49 edgetoedgeconnectivity.operstate = 'inactive'
50 edgetoedgeconnectivity.adminstate = 'disabled'
Michael Best162b08e2016-11-10 15:44:50 -050051 edgetoedgeconnectivity.name = pseudowirename
Rizwan Haider51fdb3f2016-11-09 18:29:32 -050052 edgetoedgeconnectivity.save()
53 return pseudowirename
54
55 # Method to support connect
56 #
57 def connect(self, handle):
58 # Connect method - simply transition the state of the underlying object - the Metronet sync will do the rest
59 logger.info("Metronetwork Pseudowire connect called, handle = %s" % handle)
Michael Best162b08e2016-11-10 15:44:50 -050060 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle)
Rizwan Haider51fdb3f2016-11-09 18:29:32 -050061 edgetoedgeconnectivity.adminstate = 'activationrequested'
62 edgetoedgeconnectivity.save()
63
64 # Method to support disconnect connect
65 #
66 def disconnect(self, handle):
67 # Connect method - simply transition the state of the underlying object - the Metronet sync will do the rest
68 logger.info("Metronetwork Pseudowire disconnect called, handle = %s" % handle)
Michael Best162b08e2016-11-10 15:44:50 -050069 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle)
Rizwan Haider51fdb3f2016-11-09 18:29:32 -050070 edgetoedgeconnectivity.adminstate = 'deactivationrequested'
71 edgetoedgeconnectivity.save()
72
73 # Method to support deletion
74 #
75 def delete(self, handle):
76 # Delete method - simply set the state to deleted and the Metronet sync will do the rest
77 logger.info("Metronetwork Pseudowire delete called, handle = %s" % handle)
Michael Best162b08e2016-11-10 15:44:50 -050078 edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle)
Rizwan Haider51fdb3f2016-11-09 18:29:32 -050079 edgetoedgeconnectivity.deleted = True
80 edgetoedgeconnectivity.save()
81