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 |
| 19 | pseudowirename = ("port1: %s, port2: %s, vlan: %s" % (port1, port2, vlanid)) |
| 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' |
| 35 | edgetoedgeconnectivity.sid = pseudowirename |
| 36 | edgetoedgeconnectivity.name = 'Metronetwork' |
| 37 | edgetoedgeconnectivity.save() |
| 38 | return pseudowirename |
| 39 | |
| 40 | # Method to support connect |
| 41 | # |
| 42 | def connect(self, handle): |
| 43 | # Connect method - simply transition the state of the underlying object - the Metronet sync will do the rest |
| 44 | logger.info("Metronetwork Pseudowire connect called, handle = %s" % handle) |
| 45 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(sid=handle) |
| 46 | edgetoedgeconnectivity.adminstate = 'activationrequested' |
| 47 | edgetoedgeconnectivity.save() |
| 48 | |
| 49 | # Method to support disconnect connect |
| 50 | # |
| 51 | def disconnect(self, handle): |
| 52 | # Connect method - simply transition the state of the underlying object - the Metronet sync will do the rest |
| 53 | logger.info("Metronetwork Pseudowire disconnect called, handle = %s" % handle) |
| 54 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(sid=handle) |
| 55 | edgetoedgeconnectivity.adminstate = 'deactivationrequested' |
| 56 | edgetoedgeconnectivity.save() |
| 57 | |
| 58 | # Method to support deletion |
| 59 | # |
| 60 | def delete(self, handle): |
| 61 | # Delete method - simply set the state to deleted and the Metronet sync will do the rest |
| 62 | logger.info("Metronetwork Pseudowire delete called, handle = %s" % handle) |
| 63 | edgetoedgeconnectivity = NetworkEdgeToEdgePointConnection.objects.get(sid=handle) |
| 64 | edgetoedgeconnectivity.deleted = True |
| 65 | edgetoedgeconnectivity.save() |
| 66 | |