Matteo Scandolo | 4e0e88c | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | |
| 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 Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 17 | from xos.logger import Logger, logging |
| 18 | from synchronizers.vnodlocal.pseudowireproviders.pseudowireprovider import PseudowireProvider |
| 19 | from services.metronetwork.models import NetworkEdgeToEdgePointConnection, NetworkEdgePort |
| 20 | |
| 21 | logger = Logger(level=logging.INFO) |
| 22 | |
| 23 | class 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 Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame] | 35 | pseudowirename = ("Vlan: %s" % vlanid) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 36 | 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 Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame] | 51 | edgetoedgeconnectivity.name = pseudowirename |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 52 | 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 Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame] | 60 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 61 | 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 Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame] | 69 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 70 | 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 Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame] | 78 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 79 | edgetoedgeconnectivity.deleted = True |
| 80 | edgetoedgeconnectivity.save() |
| 81 | |