1 define(['app/cpeui/cpeui.module'],function(cpeui) {
3 cpeui.factory('CpeuiSvc', function($http) {
4 var baseUrl = "/restconf/config/mef-global:mef-global/";
7 svc.getTenantList = function(callback) {
11 url:baseUrl + "tenants-instances"
12 }).then(function successCallback(response) {
13 tenantList = response.data["tenants-instances"]["tenant-list"];
14 if (callback != undefined) {
17 }, function errorCallback(response) {
18 if (response.status == 404) {
21 console.log(response);
26 svc.addTenant = function(name, callback){
29 url:baseUrl + "tenants-instances/",
30 data: {"tenant-list":[{
33 }).then(function successCallback(response) {
34 if (callback != undefined) {
39 svc.deleteTenant = function(id, callback) {
42 url:baseUrl + "tenants-instances/tenant-list/" + id + "/",
43 }).then(function successCallback(response) {
44 if (callback != undefined) {
51 svc.getProfiles = function(callback) {
54 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/"
55 }).then(function successCallback(response) {
56 if (callback != undefined) {
57 callback(response.data["ingress-bwp-flows"]["bwp-flow"]);
59 }, function errorCallback(response) {
60 if (response.status == 404) {
63 console.log(response);
67 svc.addProfile = function(name, cir, cbs, callback){
70 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/",
76 }).then(function successCallback(response) {
77 if (callback != undefined) {
83 svc.deleteProfile = function(name, callback) {
86 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/bwp-flow/"+name,
87 }).then(function successCallback(response) {
88 if (callback != undefined) {
95 svc.addCe = function(id, name, callback) {
98 url:"/restconf/config/mef-topology:mef-topology/devices/",
105 "interfaces": {"interface": []}
110 }).then(function successCallback(response) {
111 if (callback != undefined) {
117 svc.addCeName = function(ce, new_name, callback) {
120 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id'],
121 data: {"device-name": new_name}
122 }).then(function successCallback(response) {
123 if (callback != undefined) {
126 }, function errorCallback(response) {
127 console.log(response);
130 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id']
131 }).then(function successCallback(response) {
132 ce["device-name"] = response.data["device"][0]["device-name"];
137 svc.getCes = function(callback) {
143 url:"/restconf/operational/mef-topology:mef-topology/devices/"
144 }).then(function successCallback(response) {
145 ces = response.data["devices"]["device"];
146 ces.forEach(function(c) {
147 c.displayName = c['dev-id'];
148 operMap[c['dev-id']] = c;
150 }).finally(function() {
153 url:"/restconf/config/mef-topology:mef-topology/devices/"
154 }).then(function(response){
155 var confCes = response.data["devices"]["device"];
156 confCes.forEach(function(c) {
157 c.displayName = c['device-name'] ? c['device-name'] : c['dev-id'];
158 if (operMap[c['dev-id']]) {
159 for (var attrname in c) {
160 operMap[c['dev-id']][attrname] = c[attrname];
163 operMap[c['dev-id']] = c;
166 }).finally(function() {
167 if (callback != undefined) {
168 callback(Object.values(operMap));
174 svc.removeCe = function(ceid, callback) {
177 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ceid + "/"
178 }).then(function successCallback(response) {
179 if (callback != undefined) {
187 svc.addUni = function(id, tenantid, callback) {
190 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/",
193 "tenant-id":tenantid,
194 "admin-state-enabled":true
196 }).then(function successCallback(response) {
197 if (callback != undefined) {
204 svc.updateUni = function(id, tenantid, callback) {
205 // TODO didn't find a better way to keep other uni fields, PATCH method is not supported :(
208 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/uni/" + id + "/"
209 }).then(function successCallback(response) {
211 uni["uni"][0]["tenant-id"] = tenantid;
213 delete uni["uni"][0]["tenant-id"];
215 uni["uni"][0]["admin-state-enabled"] = true;
218 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + id + "/",
220 }).then(function successCallback(response) {
221 if (callback != undefined) {
228 svc.getUnis = function(callback) {
232 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/"
233 }).then(function successCallback(response) {
234 unis = response.data["unis"]["uni"];
235 if (unis != undefined){
236 for (i=0; i < unis.length; i++) {
237 if ((unis[i]["physical-layers"] != undefined) && (unis[i]["physical-layers"].links != undefined)){
238 unis[i].device = unis[i]["physical-layers"].links.link[0].device;
245 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/"
246 }).then(function(response){
247 var confUnis = response.data["unis"]["uni"];
248 confUnis.forEach(function(u) {
249 confMap[u['uni-id']] = u;
251 }).finally(function(){
252 unis.forEach(function(u) {
253 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
254 // copy config fields like tenant-id
255 if (confMap[u['uni-id']]){
256 for (var attrname in confMap[u['uni-id']]) {
257 u[attrname] = confMap[u['uni-id']][attrname];
261 if (callback != undefined) {
265 }, function errorCallback(response) {
266 if (response.status == 404) {
269 console.log(response);
273 svc.getTenantUnis = function(tenantid, callback) {
275 svc.getUnis(function(unis){
276 if (unis != undefined){
277 unis = unis.filter(function(u){return u["tenant-id"] == tenantid;});
279 if (callback != undefined) {
285 svc.removeUni = function(uniid, callback) {
288 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + uniid + "/"
289 }).then(function successCallback(response) {
290 if (callback != undefined) {
297 svc.addIpvc = function(ipvc, tenant, callback) {
301 "svc-type" : 'eplan',
302 "tenant-id" : tenant,
305 "ipvc-type" : 'multipoint',
311 url:"/restconf/config/mef-services:mef-services/",
313 }).then(function successCallback(response) {
314 if (callback != undefined) {
320 svc.addIpUni = function(uniid, ipuni_id, ip_address, vlan, callback) {
321 var data = {"ip-uni":{
322 "ip-uni-id": ipuni_id,
323 "ip-address": ip_address
326 data["ip-uni"].vlan = vlan;
330 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/",
332 }).then(function successCallback(response) {
333 if (callback != undefined) {
339 svc.getAllIpUniSubnets = function(callback) {
342 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/"
343 }).then(function successCallback(response) {
344 var raw_subnets = response.data["subnets"]["subnet"];
346 raw_subnets.forEach(function(sub){
347 if (subnets[sub["uni-id"]] == undefined) {
348 subnets[sub["uni-id"]] = {};
350 if (subnets[sub["uni-id"]][sub["ip-uni-id"]] == undefined) {
351 subnets[sub["uni-id"]][sub["ip-uni-id"]] = [];
353 subnets[sub["uni-id"]][sub["ip-uni-id"]].push(sub);
355 if (callback != undefined) {
358 }, function errorCallback(response) {
359 console.log(response);
363 svc.addIpUniSubnet = function(uniid, ipuniid, subnet, gateway, callback) {
376 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/",
378 }).then(function successCallback(response) {
379 if (callback != undefined) {
385 svc.deleteIpUniSubnet = function(uniid, ipuni_id, subnet, callback) {
389 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/subnet/"+uniid+"/"+ipuni_id+"/"+subnet.replace("/","%2F")+"/"
390 }).then(function successCallback(response) {
391 if (callback != undefined) {
396 svc.deleteIpUni = function(uniid, ipuni_id, callback) {
400 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/"
401 }).then(function successCallback(response) {
402 if (callback != undefined) {
408 svc.getIpUniSubnets = function(uniid, ipuni_id, callback) {
411 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/"
412 //subnet/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/subnets"
413 }).then(function successCallback(response) {
414 subnets = response.data["subnets"]["subnet"];
415 subnets = subnets.filterByField('uni-id',uniid).filterByField('ip-uni-id',ipuni_id);
416 if (callback != undefined) {
424 function getJsonUnis(unis) {
426 if (unis == undefined) {
429 unis.forEach(function(i){uni_json.push({"uni-id":i});});
432 svc.addEvc = function(evc, evc_type, tenant, callback) {
433 var uni_json = getJsonUnis(evc.unis);
438 "svc-type" : evc.svc_type,
439 "tenant-id" : tenant,
442 "evc-type" : evc_type,
443 "preserve-ce-vlan-id" : evc.is_preserve_vlan,
444 "max-svc-frame-size" : evc.mtu_size,
445 "unicast-svc-frm-delivery" : evc.unicast,
446 "multicast-svc-frm-delivery" : evc.multicast,
450 "admin-state-enabled" : true
454 if (evc.is_preserve_vlan) {
455 data["mef-service"]["evc"]["preserved-vlan"] = evc.preserved_vlan;
459 url:"/restconf/config/mef-services:mef-services/",
461 }).then(function successCallback(response) {
462 if (callback != undefined) {
467 svc.getServices = function(tenantid, callback) {
471 url:"/restconf/config/mef-services:mef-services/"
472 }).then(function successCallback(response) {
473 evcs = response.data["mef-services"]["mef-service"]; // TODO try to filter on server side
474 if (evcs != undefined) {
475 evcs = evcs.filter(function(evc){return evc["tenant-id"] == tenantid;});
476 for (i=0; i < evcs.length; i++) {
477 if ((evcs[i].evc != undefined) && (evcs[i].evc.unis.uni != undefined)) {
478 var unis = evcs[i].evc.unis.uni;
479 for (j=0; j < unis.length; j++) {
480 if ((unis[j]['evc-uni-ce-vlans'] != undefined) && (unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'] != undefined)){
481 unis[j].vlans = unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'].map(function(u){return u.vid;}).sort();
489 if (callback != undefined) {
492 }, function errorCallback(response) {
493 console.log(response);
498 svc.getAllServices = function(callback) {
501 url:"/restconf/config/mef-services:mef-services/"
502 }).then(function successCallback(response) {
503 if (callback != undefined) {
504 callback(response.data["mef-services"]["mef-service"]);
506 }, function errorCallback(response) {
507 if (response.status == 404) {
510 console.log(response);
514 svc.addTenantToService = function(svcId, tenantName, callbackSuccess, callbackFailure){
517 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcId,
518 data:{"tenant-id":tenantName}
520 if (callbackSuccess != undefined) {
524 if (callbackFailure != undefined) {
527 console.log(response);
532 svc.removeEvc = function(svcid, callback) {
535 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/"
536 }).then(function successCallback(response) {
537 if (callback != undefined) {
543 svc.addIpvcUni = function(svcid, uni_id, ipuni_id, profile_name, callback) {
550 data.uni["ingress-bw-profile"] = profile_name;
554 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/"+uni_id+"/"+ipuni_id,
556 }).then(function successCallback(response) {
557 if (callback != undefined) {
560 }, function failureCallback(response) {
561 if (callback != undefined) {
567 svc.deleteIpvcUni = function(svcid, uni_id, ipuni_id, callback) {
570 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/" + uni_id +"/"+ipuni_id + "/"
571 }).then(function successCallback(response) {
572 if (callback != undefined) {
580 svc.addEvcUni = function(svcid, uni_id, role, vlans, profile_name, callback) {
584 "admin-state-enabled":true
588 data.uni["ingress-bw-profile"] = profile_name;
590 if (vlans != undefined) {
591 data.uni['evc-uni-ce-vlans'] = {"evc-uni-ce-vlan":[]}
592 for (var i=0; i< vlans.length; ++i) {
593 data.uni['evc-uni-ce-vlans']["evc-uni-ce-vlan"].push({"vid":vlans[i]});
598 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis",
600 }).then(function successCallback(response) {
601 if (callback != undefined) {
604 }, function failureCallback(response) {
605 if (callback != undefined) {
611 svc.addEvcUniVlan = function(svcid, uni_id, vlan, callback) {
614 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/evc-uni-ce-vlans/",
615 data:{"evc-uni-ce-vlan":{"vid":vlan}}
616 }).then(function successCallback(response) {
617 if (callback != undefined) {
623 svc.deleteEvcUni = function(svcid, uni_id, callback) {
626 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/"
627 }).then(function successCallback(response) {
628 if (callback != undefined) {
636 svc.deleteVlan = function(svc_id, uni_id, vlan,callback) {
639 url:"/restconf/config/mef-services:mef-services/mef-service/" + svc_id + "/evc/unis/uni/" + uni_id + "/evc-uni-ce-vlans/evc-uni-ce-vlan/"+ vlan+"/"
640 }).then(function successCallback(response) {
641 if (callback != undefined) {
647 svc.addVlan = function(svc_id, uni_id, vlan, callback) {
650 url:"/restconf/config/mef-services:mef-services/mef-service/" + svc_id + "/evc/unis/uni/"+uni_id+"/evc-uni-ce-vlans/evc-uni-ce-vlan/"+vlan+"/",
651 data:{"evc-uni-ce-vlan":{"vid":vlan}}
652 }).then(function successCallback(response) {
653 if (callback != undefined) {
659 svc.getNetworkNames = function(callback){
662 url:"/restconf/config/neutron:neutron/networks/"
663 }).then(function successCallback(response) {
664 if (callback != undefined) {
665 callback(response.data.networks.network);