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