Matteo Scandolo | fcf842e | 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 | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 17 | from xos.logger import Logger, logging
|
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 18 | from services.metronetwork.models import *
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 19 | from synchronizers.metronetwork.providers.metronetworkprovider import MetroNetworkProvider
|
| 20 |
|
| 21 | import requests, json
|
| 22 | from requests.auth import HTTPBasicAuth
|
| 23 |
|
| 24 | logger = Logger(level=logging.INFO)
|
| 25 |
|
| 26 |
|
| 27 | class MetroNetworkRestProvider(MetroNetworkProvider):
|
| 28 | def __init__(self, networkdevice, **args):
|
| 29 | MetroNetworkProvider.__init__(self, networkdevice, **args)
|
| 30 |
|
| 31 | def get_network_ports(self):
|
| 32 |
|
| 33 | objs = []
|
| 34 |
|
| 35 | restCtrlUrl = self.networkdevice.restCtrlUrl
|
| 36 | username = self.networkdevice.username
|
| 37 | password = self.networkdevice.password
|
| 38 |
|
| 39 | resp = requests.get("{}/mef-sca-api/SCA_ETH_FPP_UNI_N".format(restCtrlUrl),
|
| 40 | auth=HTTPBasicAuth(username, password))
|
| 41 |
|
| 42 | if resp.status_code == 200:
|
| 43 | for uni in resp.json():
|
| 44 | hostname = uni['transportPort']['Hostname']
|
| 45 | port = uni['transportPort']['Port']
|
| 46 |
|
| 47 | # Default values
|
| 48 | bwpCfgCbs = 0
|
| 49 | bwpCfgEbs = 0
|
| 50 | bwpCfgCir = 0
|
| 51 | bwpCfgEir = 0
|
| 52 |
|
| 53 | if 'interfaceCfgIngressBwp' in uni:
|
| 54 | bwpCfgCbs = uni['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 55 | bwpCfgEbs = uni['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 56 | bwpCfgCir = uni['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 57 | bwpCfgEir = uni['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 58 |
|
| 59 | uniPort = NetworkEdgePort()
|
| 60 | uniPort.element = self.networkdevice
|
| 61 | uniPort.pid = "{}.{}/{}".format(self.networkdevice.id, hostname, port)
|
| 62 | uniPort.bwpCfgCbs = bwpCfgCbs
|
| 63 | uniPort.bwpCfgEbs = bwpCfgEbs
|
| 64 | uniPort.bwpCfgCir = bwpCfgCir
|
| 65 | uniPort.bwpCfgEir = bwpCfgEir
|
| 66 |
|
| 67 | objs.append(uniPort)
|
| 68 |
|
| 69 | return objs
|
| 70 |
|
| 71 | else:
|
| 72 | raise Exception("OnosApiError: get_network_ports()")
|
| 73 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 74 | def get_network_ports(self):
|
| 75 |
|
| 76 | objs = []
|
| 77 |
|
| 78 | restCtrlUrl = self.networkdevice.restCtrlUrl
|
| 79 | username = self.networkdevice.username
|
| 80 | password = self.networkdevice.password
|
| 81 |
|
| 82 | resp = requests.get("{}/mef-sca-api/SCA_ETH_FPP_UNI_N".format(restCtrlUrl),
|
| 83 | auth=HTTPBasicAuth(username, password))
|
| 84 |
|
| 85 | if resp.status_code == 200:
|
| 86 | for uni in resp.json():
|
| 87 | hostname = uni['transportPort']['Hostname']
|
| 88 | port = uni['transportPort']['Port']
|
| 89 |
|
| 90 | # Default values
|
| 91 | bwpCfgCbs = 0
|
| 92 | bwpCfgEbs = 0
|
| 93 | bwpCfgCir = 0
|
| 94 | bwpCfgEir = 0
|
| 95 |
|
| 96 | if 'interfaceCfgIngressBwp' in uni:
|
| 97 | bwpCfgCbs = uni['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 98 | bwpCfgEbs = uni['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 99 | bwpCfgCir = uni['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 100 | bwpCfgEir = uni['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 101 |
|
| 102 | uniPort = NetworkEdgePort()
|
| 103 | uniPort.element = self.networkdevice
|
| 104 | uniPort.pid = "{}.{}/{}".format(self.networkdevice.id, hostname, port)
|
| 105 | uniPort.bwpCfgCbs = bwpCfgCbs
|
| 106 | uniPort.bwpCfgEbs = bwpCfgEbs
|
| 107 | uniPort.bwpCfgCir = bwpCfgCir
|
| 108 | uniPort.bwpCfgEir = bwpCfgEir
|
| 109 |
|
| 110 | objs.append(uniPort)
|
| 111 |
|
| 112 | return objs
|
| 113 |
|
| 114 | else:
|
| 115 | raise Exception("OnosApiError: get_network_ports()")
|
| 116 |
|
| 117 | def get_network_eline_link(self, networkDevice, evc):
|
| 118 |
|
| 119 | sid = evc['id']
|
| 120 | uni1 = evc['SCA_ETH_Flow_Points'][0]
|
| 121 | hostname = uni1['scaEthFppUniN']['transportPort']['Hostname']
|
| 122 | port = uni1['scaEthFppUniN']['transportPort']['Port']
|
| 123 |
|
| 124 | edgePort1 = NetworkEdgePort()
|
| 125 | edgePort1.element = networkDevice
|
| 126 | edgePort1.pid = "{}.{}/{}".format(networkDevice.id, hostname, port)
|
| 127 |
|
| 128 | if 'interfaceCfgIngressBwp' in uni1['scaEthFppUniN']:
|
| 129 | edgePort1.bwpCfgCbs = uni1['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 130 | edgePort1.bwpCfgEbs = uni1['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 131 | edgePort1.bwpCfgCir = uni1['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 132 | edgePort1.bwpCfgEir = uni1['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 133 |
|
| 134 | uni2 = evc['SCA_ETH_Flow_Points'][1]
|
| 135 | hostname = uni2['scaEthFppUniN']['transportPort']['Hostname']
|
| 136 | port = uni2['scaEthFppUniN']['transportPort']['Port']
|
| 137 |
|
| 138 | edgePort2 = NetworkEdgePort()
|
| 139 | edgePort2.element = networkDevice
|
| 140 | edgePort2.pid = "{}.{}/{}".format(networkDevice.id, hostname, port)
|
| 141 |
|
| 142 | if 'interfaceCfgIngressBwp' in uni1['scaEthFppUniN']:
|
| 143 | edgePort2.bwpCfgCbs = uni2['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 144 | edgePort2.bwpCfgEbs = uni2['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 145 | edgePort2.bwpCfgCir = uni2['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 146 | edgePort2.bwpCfgEir = uni2['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 147 |
|
| 148 | edgeToEdgeConnectivity = NetworkEdgeToEdgePointConnection()
|
| 149 | edgeToEdgeConnectivity.sid = sid
|
| 150 | edgeToEdgeConnectivity.type = "Point_To_Point"
|
| 151 | edgeToEdgeConnectivity.uni1 = edgePort1
|
| 152 | edgeToEdgeConnectivity.uni2 = edgePort2
|
| 153 | edgeToEdgeConnectivity.operstate = "active"
|
| 154 | edgeToEdgeConnectivity.adminstate = "enabled"
|
| 155 |
|
| 156 | return(edgeToEdgeConnectivity)
|
| 157 |
|
| 158 | def get_network_elan_link(self, networkDevice, evc):
|
| 159 |
|
| 160 | sid = evc['id']
|
| 161 | eps = []
|
| 162 |
|
| 163 | for ep in evc['SCA_ETH_Flow_Points']:
|
| 164 | hostname = ep['scaEthFppUniN']['transportPort']['Hostname']
|
| 165 | port = ep['scaEthFppUniN']['transportPort']['Port']
|
| 166 |
|
| 167 | edgePort = NetworkEdgePort()
|
| 168 | edgePort.element = networkDevice
|
| 169 | edgePort.pid = "{}.{}/{}".format(networkDevice.id, hostname, port)
|
| 170 |
|
| 171 | if 'interfaceCfgIngressBwp' in ep['scaEthFppUniN']:
|
| 172 | edgePort.bwpCfgCbs = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 173 | edgePort.bwpCfgEbs = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 174 | edgePort.bwpCfgCir = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 175 | edgePort.bwpCfgEir = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 176 |
|
| 177 | eps.append(edgePort)
|
| 178 |
|
| 179 | multipointToMultipointConnectivity = NetworkMultipointToMultipointConnection()
|
| 180 | multipointToMultipointConnectivity.sid = sid
|
| 181 | multipointToMultipointConnectivity.type = "Multipoint_To_Multipoint"
|
| 182 | multipointToMultipointConnectivity.eps = eps
|
| 183 | multipointToMultipointConnectivity.operstate = "active"
|
| 184 | multipointToMultipointConnectivity.adminstate = "enabled"
|
| 185 |
|
| 186 | return(multipointToMultipointConnectivity)
|
| 187 |
|
| 188 | def get_network_etree_link(self, networkDevice, evc):
|
| 189 |
|
| 190 | sid = evc['id']
|
| 191 | eps = []
|
| 192 |
|
| 193 | root = evc['SCA_ETH_Flow_Points'][0]
|
| 194 | hostname = root['scaEthFppUniN']['transportPort']['Hostname']
|
| 195 | port = root['scaEthFppUniN']['transportPort']['Port']
|
| 196 |
|
| 197 | edgePort = NetworkEdgePort()
|
| 198 | edgePort.element = networkDevice
|
| 199 | edgePort.pid = "{}.{}/{}".format(networkDevice.id, hostname, port)
|
| 200 |
|
| 201 | if 'interfaceCfgIngressBwp' in root['scaEthFppUniN']:
|
| 202 | edgePort.bwpCfgCbs = root['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 203 | edgePort.bwpCfgEbs = root['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 204 | edgePort.bwpCfgCir = root['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 205 | edgePort.bwpCfgEir = root['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 206 |
|
| 207 | edgeToMultipointConnectivity = NetworkEdgeToMultipointConnection()
|
| 208 | edgeToMultipointConnectivity.sid = sid
|
| 209 | edgeToMultipointConnectivity.type = "Root_Multipoint"
|
| 210 | edgeToMultipointConnectivity.root = edgePort
|
| 211 |
|
| 212 | for ep in evc['SCA_ETH_Flow_Points'][1:]:
|
| 213 | hostname = ep['scaEthFppUniN']['transportPort']['Hostname']
|
| 214 | port = ep['scaEthFppUniN']['transportPort']['Port']
|
| 215 |
|
| 216 | edgePort = NetworkEdgePort()
|
| 217 | edgePort.element = networkDevice
|
| 218 | edgePort.pid = "{}.{}/{}".format(networkDevice.id, hostname, port)
|
| 219 |
|
| 220 | if 'interfaceCfgIngressBwp' in ep['scaEthFppUniN']:
|
| 221 | edgePort.bwpCfgCbs = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCbs']
|
| 222 | edgePort.bwpCfgEbs = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEbs']
|
| 223 | edgePort.bwpCfgCir = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgCir']
|
| 224 | edgePort.bwpCfgEir = ep['scaEthFppUniN']['interfaceCfgIngressBwp']['bwpCfgEir']
|
| 225 |
|
| 226 | eps.append(edgePort)
|
| 227 |
|
| 228 | edgeToMultipointConnectivity.eps = eps
|
| 229 | edgeToMultipointConnectivity.operstate = "active"
|
| 230 | edgeToMultipointConnectivity.adminstate = "enabled"
|
| 231 |
|
| 232 | return(edgeToMultipointConnectivity)
|
| 233 |
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 234 | def get_network_links(self):
|
| 235 |
|
| 236 | objs = []
|
| 237 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 238 | networkDevice = self.networkdevice
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 239 | restCtrlUrl = self.networkdevice.restCtrlUrl
|
| 240 | username = self.networkdevice.username
|
| 241 | password = self.networkdevice.password
|
| 242 |
|
| 243 | resp = requests.get("{}/mef-sca-api/SCA_ETH_FDFr_EC/findByState?state=Active".format(restCtrlUrl),
|
| 244 | auth=HTTPBasicAuth(username, password))
|
| 245 |
|
| 246 | if resp.status_code == 200:
|
| 247 | for evc in resp.json():
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 248 | evcServiceType = evc['evcServiceType']
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 249 | if (evcServiceType == "Point_To_Point"):
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 250 | objs.append(self.get_network_eline_link(networkDevice, evc))
|
| 251 | elif (evcServiceType == "Multipoint_To_Multipoint"):
|
| 252 | objs.append(self.get_network_elan_link(networkDevice, evc))
|
| 253 | elif (evcServiceType == "Root_Multipoint"):
|
| 254 | objs.append(self.get_network_etree_link(networkDevice, evc))
|
| 255 | else:
|
| 256 | raise Exception("OnosApiError: get_network_links() - unknown link type")
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 257 | else:
|
| 258 | raise Exception("OnosApiError: get_network_links()")
|
| 259 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 260 | return objs
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 261 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 262 | def create_point_to_point_connectivity_json_data(self, obj):
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 263 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 264 | p2p_json_data = {}
|
| 265 | p2p_json_data["evcServiceType"] = "Point_To_Point"
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 266 |
|
| 267 | uni1 = obj.uni1
|
| 268 | uni1Id = uni1.pid
|
| 269 | uni1IdToken = (uni1Id.split('.', 1))[1].split('/', 1)
|
| 270 | uni1Hostname = uni1IdToken[0]
|
| 271 | uni1Port = uni1IdToken[1]
|
| 272 | uni1BwpCfgCbs = uni1.bwpCfgCbs
|
| 273 | uni1BwpCfgEbs = uni1.bwpCfgEbs
|
| 274 | uni1BwpCfgCir = uni1.bwpCfgCir
|
| 275 | uni1BwpCfgEir = uni1.bwpCfgEir
|
| 276 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 277 | uni1_json_data = {}
|
| 278 | uni1_json_data['scaEthFppUniN'] = {}
|
| 279 | uni1_json_data['scaEthFppUniN']['ceVlanId'] = obj.vlanid
|
| 280 | uni1_json_data['scaEthFppUniN']["transportPort"] = {}
|
| 281 | uni1_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"] = {}
|
| 282 |
|
| 283 | uni1_json_data['scaEthFppUniN']["transportPort"]["Hostname"] = uni1Hostname
|
| 284 | uni1_json_data['scaEthFppUniN']["transportPort"]["Port"] = uni1Port
|
| 285 | uni1_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCbs"] = uni1BwpCfgCbs
|
| 286 | uni1_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEbs"] = uni1BwpCfgEbs
|
| 287 | uni1_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCir"] = uni1BwpCfgCir
|
| 288 | uni1_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEir"] = uni1BwpCfgEir
|
| 289 |
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 290 | uni2 = obj.uni2
|
| 291 | uni2Id = uni2.pid
|
| 292 | uni2IdToken = (uni2Id.split('.', 1))[1].split('/', 1)
|
| 293 | uni2Hostname = uni2IdToken[0]
|
| 294 | uni2Port = uni2IdToken[1]
|
| 295 | uni2BwpCfgCbs = uni2.bwpCfgCbs
|
| 296 | uni2BwpCfgEbs = uni2.bwpCfgEbs
|
| 297 | uni2BwpCfgCir = uni2.bwpCfgCir
|
| 298 | uni2BwpCfgEir = uni2.bwpCfgEir
|
| 299 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 300 | uni2_json_data = {}
|
| 301 | uni2_json_data['scaEthFppUniN'] = {}
|
| 302 | uni2_json_data['scaEthFppUniN']['ceVlanId'] = obj.vlanid
|
| 303 | uni2_json_data['scaEthFppUniN']["transportPort"] = {}
|
| 304 | uni2_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"] = {}
|
| 305 |
|
| 306 | uni2_json_data['scaEthFppUniN']["transportPort"]["Hostname"] = uni2Hostname
|
| 307 | uni2_json_data['scaEthFppUniN']["transportPort"]["Port"] = uni2Port
|
| 308 | uni2_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCbs"] = uni2BwpCfgCbs
|
| 309 | uni2_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEbs"] = uni2BwpCfgEbs
|
| 310 | uni2_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCir"] = uni2BwpCfgCir
|
| 311 | uni2_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEir"] = uni2BwpCfgEir
|
| 312 |
|
| 313 | p2p_json_data["SCA_ETH_Flow_Points"] = []
|
| 314 | p2p_json_data["SCA_ETH_Flow_Points"].append(uni1_json_data)
|
| 315 | p2p_json_data["SCA_ETH_Flow_Points"].append(uni2_json_data)
|
| 316 |
|
| 317 | return p2p_json_data
|
| 318 |
|
| 319 | # nchoi: create elan service json data
|
| 320 | def create_multipoint_to_multipoint_connectivity_json_data(self, obj):
|
| 321 |
|
| 322 | mp2mp_json_data = {}
|
| 323 | mp2mp_json_data["evcServiceType"] = "Multipoint_To_Multipoint"
|
| 324 | mp2mp_json_data["SCA_ETH_Flow_Points"] = []
|
| 325 |
|
| 326 | for ep in obj.eps.all():
|
| 327 | uniId = ep.pid
|
| 328 | uniIdToken = (uniId.split('.', 1))[1].split('/', 1)
|
| 329 | uniHostname = uniIdToken[0]
|
| 330 | uniPort = uniIdToken[1]
|
| 331 | uniBwpCfgCbs = ep.bwpCfgCbs
|
| 332 | uniBwpCfgEbs = ep.bwpCfgEbs
|
| 333 | uniBwpCfgCir = ep.bwpCfgCir
|
| 334 | uniBwpCfgEir = ep.bwpCfgEir
|
| 335 |
|
| 336 | uni_json_data = {}
|
| 337 | uni_json_data['scaEthFppUniN'] = {}
|
| 338 | uni_json_data['scaEthFppUniN']['ceVlanId'] = obj.vlanid
|
| 339 | uni_json_data['scaEthFppUniN']["transportPort"] = {}
|
| 340 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"] = {}
|
| 341 |
|
| 342 | uni_json_data['scaEthFppUniN']["transportPort"]["Hostname"] = uniHostname
|
| 343 | uni_json_data['scaEthFppUniN']["transportPort"]["Port"] = uniPort
|
| 344 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCbs"] = uniBwpCfgCbs
|
| 345 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEbs"] = uniBwpCfgEbs
|
| 346 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCir"] = uniBwpCfgCir
|
| 347 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEir"] = uniBwpCfgEir
|
| 348 |
|
| 349 | mp2mp_json_data["SCA_ETH_Flow_Points"].append(uni_json_data)
|
| 350 |
|
| 351 | return mp2mp_json_data
|
| 352 |
|
| 353 | # nchoi: create etree service json data
|
| 354 | def create_root_multipoint_connectivity_json_data(self, obj):
|
| 355 |
|
| 356 | r2mp_json_data = {}
|
| 357 | r2mp_json_data["evcServiceType"] = "Root_Multipoint"
|
| 358 | r2mp_json_data["SCA_ETH_Flow_Points"] = []
|
| 359 |
|
| 360 | root = obj.root
|
| 361 | uniId = root.pid
|
| 362 | uniIdToken = (uniId.split('.', 1))[1].split('/', 1)
|
| 363 | uniHostname = uniIdToken[0]
|
| 364 | uniPort = uniIdToken[1]
|
| 365 | uniBwpCfgCbs = root.bwpCfgCbs
|
| 366 | uniBwpCfgEbs = root.bwpCfgEbs
|
| 367 | uniBwpCfgCir = root.bwpCfgCir
|
| 368 | uniBwpCfgEir = root.bwpCfgEir
|
| 369 |
|
| 370 | uni_json_data = {}
|
| 371 | uni_json_data['scaEthFppUniN'] = {}
|
| 372 | uni_json_data['scaEthFppUniN']['ceVlanId'] = obj.vlanid
|
| 373 | uni_json_data['scaEthFppUniN']["transportPort"] = {}
|
| 374 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"] = {}
|
| 375 |
|
| 376 | uni_json_data['scaEthFppUniN']["transportPort"]["Hostname"] = uniHostname
|
| 377 | uni_json_data['scaEthFppUniN']["transportPort"]["Port"] = uniPort
|
| 378 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCbs"] = uniBwpCfgCbs
|
| 379 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEbs"] = uniBwpCfgEbs
|
| 380 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCir"] = uniBwpCfgCir
|
| 381 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEir"] = uniBwpCfgEir
|
| 382 |
|
| 383 | r2mp_json_data["SCA_ETH_Flow_Points"].append(uni_json_data)
|
| 384 |
|
| 385 | for ep in obj.eps.all():
|
| 386 | uniId = ep.pid
|
| 387 | uniIdToken = (uniId.split('.', 1))[1].split('/', 1)
|
| 388 | uniHostname = uniIdToken[0]
|
| 389 | uniPort = uniIdToken[1]
|
| 390 | uniBwpCfgCbs = ep.bwpCfgCbs
|
| 391 | uniBwpCfgEbs = ep.bwpCfgEbs
|
| 392 | uniBwpCfgCir = ep.bwpCfgCir
|
| 393 | uniBwpCfgEir = ep.bwpCfgEir
|
| 394 |
|
| 395 | uni_json_data = {}
|
| 396 | uni_json_data['scaEthFppUniN'] = {}
|
| 397 | uni_json_data['scaEthFppUniN']['ceVlanId'] = obj.vlanid
|
| 398 | uni_json_data['scaEthFppUniN']["transportPort"] = {}
|
| 399 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"] = {}
|
| 400 |
|
| 401 | uni_json_data['scaEthFppUniN']["transportPort"]["Hostname"] = uniHostname
|
| 402 | uni_json_data['scaEthFppUniN']["transportPort"]["Port"] = uniPort
|
| 403 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCbs"] = uniBwpCfgCbs
|
| 404 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEbs"] = uniBwpCfgEbs
|
| 405 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgCir"] = uniBwpCfgCir
|
| 406 | uni_json_data['scaEthFppUniN']["interfaceCfgIngressBwp"]["bwpCfgEir"] = uniBwpCfgEir
|
| 407 |
|
| 408 | r2mp_json_data["SCA_ETH_Flow_Points"].append(uni_json_data)
|
| 409 |
|
| 410 | return r2mp_json_data
|
| 411 |
|
| 412 | def create_network_connectivity(self, obj):
|
| 413 |
|
| 414 | restCtrlUrl = self.networkdevice.restCtrlUrl
|
| 415 | username = self.networkdevice.username
|
| 416 | password = self.networkdevice.password
|
| 417 |
|
| 418 | evcServiceType = obj.type
|
| 419 | if (evcServiceType == "Point_To_Point"):
|
| 420 | network_connectivity_json_data = self.create_point_to_point_connectivity_json_data(obj)
|
| 421 | elif (evcServiceType == "Multipoint_To_Multipoint"):
|
| 422 | network_connectivity_json_data = self.create_multipoint_to_multipoint_connectivity_json_data(obj)
|
| 423 | elif (evcServiceType == "Root_Multipoint"):
|
| 424 | network_connectivity_json_data = self.create_root_multipoint_connectivity_json_data(obj)
|
| 425 | else:
|
| 426 | raise Exception("OnosApiError: get_network_links() - unknown link type")
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 427 |
|
| 428 | headers = {'Content-Type': 'application/json'}
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 429 | resp = requests.post('{}/mef-sca-api/SCA_ETH_FDFr_EC'.format(restCtrlUrl),
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 430 | data=json.dumps(network_connectivity_json_data), headers=headers, auth=HTTPBasicAuth(username, password))
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 431 |
|
| 432 | if resp.status_code == 201:
|
| 433 | result = resp.json()
|
| 434 | message = result['message']
|
| 435 |
|
| 436 | msg_token = message.split()
|
| 437 | for i, token in enumerate(msg_token):
|
| 438 | if token == 'id':
|
| 439 | service_id = msg_token[i + 1]
|
| 440 | obj.sid = service_id
|
| 441 | obj.adminstate = "enabled"
|
| 442 | obj.operstate = "active"
|
| 443 |
|
| 444 | return True
|
| 445 |
|
| 446 | elif resp.status_code == 204:
|
| 447 | obj.adminstate = "invalid" # what's the meaning?
|
| 448 | obj.operstate = "inactive"
|
| 449 | obj.backend_status = '204 - No network resource'
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 450 |
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 451 | return False
|
| 452 |
|
| 453 | elif resp.status_code == 500:
|
| 454 | obj.adminstate = "enabled"
|
| 455 | obj.operstate = "inactive"
|
| 456 | obj.backend_status = '500 - Internal Server Error'
|
| 457 | return False
|
| 458 |
|
| 459 | else:
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 460 | raise Exception("OnosApiError: create_network_connectivity()")
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 461 |
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 462 | def delete_network_connectivity(self, obj):
|
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 463 |
|
| 464 | restCtrlUrl = self.networkdevice.restCtrlUrl
|
| 465 | username = self.networkdevice.username
|
| 466 | password = self.networkdevice.password
|
| 467 | evcId = obj.sid
|
| 468 |
|
| 469 | resp = requests.delete("{}/mef-sca-api/SCA_ETH_FDFr_EC/{}".format(restCtrlUrl, evcId),
|
| 470 | auth=HTTPBasicAuth(username, password))
|
| 471 |
|
| 472 | if resp.status_code == 200:
|
| 473 | obj.adminstate = 'disabled'
|
| 474 | obj.operstate = 'inactive'
|
| 475 | return True
|
| 476 |
|
| 477 | elif resp.status_code == 204:
|
| 478 | obj.adminstate = "invalid" # what's the meaning?
|
| 479 | obj.backend_status = '204 - No such network resource: {}'.format(evcId)
|
| 480 | return False
|
| 481 |
|
| 482 | elif resp.status_code == 500:
|
| 483 | obj.adminstate = "disabled"
|
| 484 | obj.backend_status = '500 - Internal Server Error'
|
| 485 | return False
|
| 486 |
|
| 487 | else:
|
Rizwan Haider | e6ffdc0 | 2016-11-08 13:43:48 -0500 | [diff] [blame] | 488 | raise Exception("OnosApiError: delete_network_connectivity()")
|