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 | import requests, json |
| 6 | from requests.auth import HTTPBasicAuth |
| 7 | |
| 8 | logger = Logger(level=logging.INFO) |
| 9 | |
| 10 | class SegmentRoutingVlanXconnectPseudowireProvider(PseudowireProvider): |
| 11 | |
| 12 | def __init__(self, **args): |
| 13 | pass |
| 14 | |
| 15 | # Methods to support creation |
| 16 | # |
| 17 | # Returns: handle |
| 18 | # |
| 19 | def create(self, port1, port2, vlanid, pseudowireservice): |
| 20 | # Create method - create xconnect |
| 21 | # Vlan is TBD |
| 22 | pseudowirename = ("port1: %s, port2: %s, vlan: %s" % (port1, port2, vlanid)) |
| 23 | logger.info("SegmentRoutingXConnect create called, name: %s" % pseudowirename ) |
| 24 | |
| 25 | # Pull out Ports from FQN |
| 26 | |
| 27 | |
| 28 | # Pull out Device from FQN |
| 29 | # Use default user/password? |
| 30 | |
| 31 | # curl --user onos:rocks -X POST -H "Content-Type: application/json" http://138.120.151.126:8181/onos/v1/network/configuration/apps/org.onosproject.segmentrouting/xconnect -d '{ "of:0000000000000001" : [{"vlan" : "100", "ports" : [1, 2], "name" : "Mike"}] }' |
| 32 | |
| 33 | # Port 1 Device and Num |
| 34 | port1IdToken = port1.split('/', 1) |
| 35 | port1Devicename = port1IdToken[0] |
| 36 | port1Num = port1IdToken[1] |
| 37 | |
| 38 | # Port 2 Device and Num |
| 39 | port2IdToken = port2.split('/', 1) |
| 40 | port2Devicename = port2IdToken[0] |
| 41 | port2Num = port2IdToken[1] |
| 42 | |
| 43 | # Lets make sure the Devices are the same - otherwise its an error - Xconnect must be on same device |
| 44 | |
| 45 | if (port1Devicename != port2Devicename): |
| 46 | Exception("XConnect Device must be the same. D1= % D2=%" % (port1Devicename, port2Devicename)) |
| 47 | |
| 48 | # Get URL from PwaaS Ojbect |
| 49 | restCtrlUrl = pseudowireservice.networkControllerUrl |
| 50 | |
| 51 | data = { |
| 52 | port2Devicename : [ |
| 53 | { |
| 54 | "vlan" : vlanid, |
| 55 | "ports" : [port1Num, port2Num], |
| 56 | "name" : pseudowirename |
| 57 | } |
| 58 | ] |
| 59 | } |
| 60 | |
| 61 | headers = {'Content-Type': 'application/json'} |
| 62 | |
| 63 | resp = requests.post('{}/v1/network/configuration/apps/org.onosproject.segmentrouting/xconnect'.format(restCtrlUrl), |
| 64 | data=json.dumps(data), headers=headers, auth=HTTPBasicAuth('karaf', 'karaf')) |
| 65 | |
| 66 | if resp.status_code == 200: |
| 67 | logger.info("SegmentRoutingXConnect create successful") |
| 68 | return pseudowirename |
| 69 | else: |
| 70 | Exception("Pseudowire create failed Error Code: %s" % resp.status_code) |
| 71 | |
| 72 | |
| 73 | # Method to support connect |
| 74 | # |
| 75 | def connect(self, handle): |
| 76 | # Connect method - this is a no-op for this module, it does not support a complext state machine |
| 77 | logger.info("SegmentRoutingXConnect Pseudowire connect called, handle = %s" % handle) |
| 78 | |
| 79 | # Method to support disconnect connect |
| 80 | # |
| 81 | def disconnect(self, handle): |
| 82 | # Disconnect method - impl is TBD |
| 83 | logger.info("SegmentRoutingXConnect Pseudowire disconnect called, handle = %s" % handle) |
| 84 | |
| 85 | # Example command line syntax: |
| 86 | # curl --user onos:rocks -X DELETE http://138.120.151.126:8181/onos/v1/network/configuration/apps/org.onosproject.segmentrouting/xconnect |
| 87 | |
| 88 | # Method to support deletion |
| 89 | # |
| 90 | def delete(self, handle): |
| 91 | # Delete method - impl is TBD |
| 92 | logger.info("SegmentRoutingXConnect Pseudowire delete called, handle = %s" % handle) |
| 93 | |
| 94 | |