Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 1 | from xos.logger import Logger, logging |
| 2 | from synchronizers.vnodlocal.pseudowireproviders.pseudowireprovider import PseudowireProvider |
| 3 | from services.metronetwork.models import NetworkEdgeToEdgePointConnection, NetworkEdgePort |
| 4 | |
| 5 | logger = Logger(level=logging.INFO) |
| 6 | |
| 7 | class MetronetworkPseudowireProvider(PseudowireProvider): |
| 8 | |
| 9 | def __init__(self, **args): |
| 10 | pass |
| 11 | |
| 12 | # Methods to support creation |
| 13 | # |
| 14 | # Returns: handle |
| 15 | # |
| 16 | def create(self, port1, port2, vlanid, psuedowireservice): |
| 17 | # Create method - create eline with the ports |
| 18 | # Vlan is TBD |
Michael Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame^] | 19 | pseudowirename = ("Vlan: %s" % vlanid) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 20 | logger.info("Metronetwork create called, name: %s" % pseudowirename ) |
| 21 | # Edge to Edge Point Connectivity creation |
| 22 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection() |
| 23 | uni1port = NetworkEdgePort.objects.filter(pid__icontains=port1) |
| 24 | if uni1port: |
| 25 | uni1port = uni1port[0] |
| 26 | uni2port = NetworkEdgePort.objects.filter(pid__icontains=port2) |
| 27 | if uni2port: |
| 28 | uni2port = uni2port[0] |
| 29 | edgetoedgeconnectivity.uni1 = uni1port |
| 30 | edgetoedgeconnectivity.uni2 = uni2port |
| 31 | edgetoedgeconnectivity.vlanid = vlanid |
| 32 | edgetoedgeconnectivity.type = 'Point_To_Point' |
| 33 | edgetoedgeconnectivity.operstate = 'inactive' |
| 34 | edgetoedgeconnectivity.adminstate = 'disabled' |
Michael Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame^] | 35 | edgetoedgeconnectivity.name = pseudowirename |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 36 | edgetoedgeconnectivity.save() |
| 37 | return pseudowirename |
| 38 | |
| 39 | # Method to support connect |
| 40 | # |
| 41 | def connect(self, handle): |
| 42 | # Connect method - simply transition the state of the underlying object - the Metronet sync will do the rest |
| 43 | logger.info("Metronetwork Pseudowire connect called, handle = %s" % handle) |
Michael Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame^] | 44 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 45 | edgetoedgeconnectivity.adminstate = 'activationrequested' |
| 46 | edgetoedgeconnectivity.save() |
| 47 | |
| 48 | # Method to support disconnect connect |
| 49 | # |
| 50 | def disconnect(self, handle): |
| 51 | # Connect method - simply transition the state of the underlying object - the Metronet sync will do the rest |
| 52 | logger.info("Metronetwork Pseudowire disconnect called, handle = %s" % handle) |
Michael Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame^] | 53 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 54 | edgetoedgeconnectivity.adminstate = 'deactivationrequested' |
| 55 | edgetoedgeconnectivity.save() |
| 56 | |
| 57 | # Method to support deletion |
| 58 | # |
| 59 | def delete(self, handle): |
| 60 | # Delete method - simply set the state to deleted and the Metronet sync will do the rest |
| 61 | logger.info("Metronetwork Pseudowire delete called, handle = %s" % handle) |
Michael Best | 162b08e | 2016-11-10 15:44:50 -0500 | [diff] [blame^] | 62 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(name=handle) |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 63 | edgetoedgeconnectivity.deleted = True |
| 64 | edgetoedgeconnectivity.save() |
| 65 | |