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) {
49 svc.addCe = function(id, name, callback) {
52 url:"/restconf/config/mef-topology:mef-topology/devices/",
59 "interfaces": {"interface": []}
64 }).then(function successCallback(response) {
65 if (callback != undefined) {
71 svc.addCeName = function(ce, new_name, callback) {
74 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id'],
75 data: {"device-name": new_name}
76 }).then(function successCallback(response) {
77 if (callback != undefined) {
80 }, function errorCallback(response) {
81 console.log(response);
84 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id']
85 }).then(function successCallback(response) {
86 ce["device-name"] = response.data["device"][0]["device-name"];
91 svc.getCes = function(callback) {
95 url:"/restconf/config/mef-topology:mef-topology/devices/"
96 }).then(function successCallback(response) {
97 ces = response.data["devices"]["device"];
98 ces.forEach(function(c){
99 c.displayName = c['device-name'] ? c['device-name'] : c['dev-id'];
101 if (callback != undefined) {
104 }, function errorCallback(response) {
105 if (response.status == 404) {
108 console.log(response);
114 svc.removeCe = function(ceid, callback) {
117 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ceid + "/"
118 }).then(function successCallback(response) {
119 if (callback != undefined) {
127 svc.addUni = function(id, tenantid, callback) {
130 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/",
133 "tenant-id":tenantid,
134 "admin-state-enabled":true
136 }).then(function successCallback(response) {
137 if (callback != undefined) {
144 svc.updateUni = function(id, tenantid, callback) {
145 // TODO didn't find a better way to keep other uni fields, PATCH method is not supported :(
148 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/uni/" + id + "/"
149 }).then(function successCallback(response) {
151 uni["uni"][0]["tenant-id"] = tenantid;
153 delete uni["uni"][0]["tenant-id"];
155 uni["uni"][0]["admin-state-enabled"] = true;
158 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + id + "/",
160 }).then(function successCallback(response) {
161 if (callback != undefined) {
168 svc.getUnis = function(callback) {
172 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/"
173 }).then(function successCallback(response) {
174 unis = response.data["unis"]["uni"];
175 if (unis != undefined){
176 for (i=0; i < unis.length; i++) {
177 if ((unis[i]["physical-layers"] != undefined) && (unis[i]["physical-layers"].links != undefined)){
178 unis[i].device = unis[i]["physical-layers"].links.link[0].device;
185 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/"
186 }).then(function(response){
187 var confUnis = response.data["unis"]["uni"];
188 confUnis.forEach(function(u) {
189 confMap[u['uni-id']] = u;
191 }).finally(function(){
192 unis.forEach(function(u) {
193 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
194 // copy config fields like tenant-id
195 if (confMap[u['uni-id']]){
196 for (var attrname in confMap[u['uni-id']]) {
197 u[attrname] = confMap[u['uni-id']][attrname];
201 if (callback != undefined) {
205 }, function errorCallback(response) {
206 if (response.status == 404) {
209 console.log(response);
213 svc.getTenantUnis = function(tenantid, callback) {
215 svc.getUnis(function(unis){
216 if (unis != undefined){
217 unis = unis.filter(function(u){return u["tenant-id"] == tenantid;});
219 if (callback != undefined) {
225 svc.removeUni = function(uniid, callback) {
228 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + uniid + "/"
229 }).then(function successCallback(response) {
230 if (callback != undefined) {
237 svc.addIpvc = function(ipvc, tenant, callback) {
238 // var uni_json = getJsonUnis(evc.unis);
243 "svc-type" : 'eplan',
244 "tenant-id" : tenant,
247 "ipvc-type" : 'multipoint',
256 url:"/restconf/config/mef-services:mef-services/",
258 }).then(function successCallback(response) {
259 if (callback != undefined) {
265 svc.addIpUni = function(uniid, ipuni_id, ip_address, vlan, callback) {
266 var data = {"ip-uni":{
267 "ip-uni-id": ipuni_id,
268 "ip-address": ip_address
271 data["ip-uni"].vlan = vlan;
275 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/",
277 }).then(function successCallback(response) {
278 if (callback != undefined) {
284 svc.getAllIpUniSubnets = function(callback) {
287 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/"
288 }).then(function successCallback(response) {
289 var raw_subnets = response.data["subnets"]["subnet"];
291 raw_subnets.forEach(function(sub){
292 if (subnets[sub["uni-id"]] == undefined) {
293 subnets[sub["uni-id"]] = {};
295 if (subnets[sub["uni-id"]][sub["ip-uni-id"]] == undefined) {
296 subnets[sub["uni-id"]][sub["ip-uni-id"]] = [];
298 subnets[sub["uni-id"]][sub["ip-uni-id"]].push(sub);
300 if (callback != undefined) {
303 }, function errorCallback(response) {
304 console.log(response);
308 svc.addIpUniSubnet = function(uniid, ipuniid, subnet, gateway, callback) {
321 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/",
323 }).then(function successCallback(response) {
324 if (callback != undefined) {
330 svc.deleteIpUniSubnet = function(uniid, ipuni_id, subnet, callback) {
334 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/subnet/"+uniid+"/"+ipuni_id+"/"+subnet.replace("/","%2F")+"/"
335 }).then(function successCallback(response) {
336 if (callback != undefined) {
341 svc.deleteIpUni = function(uniid, ipuni_id, callback) {
345 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/"
346 }).then(function successCallback(response) {
347 if (callback != undefined) {
353 svc.getIpUniSubnets = function(uniid, ipuni_id, callback) {
356 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/"
357 //subnet/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/subnets"
358 }).then(function successCallback(response) {
359 subnets = response.data["subnets"]["subnet"];
360 subnets = subnets.filterByField('uni-id',uniid).filterByField('ip-uni-id',ipuni_id);
361 if (callback != undefined) {
369 function getJsonUnis(unis) {
371 if (unis == undefined) {
374 unis.forEach(function(i){uni_json.push({"uni-id":i});});
377 svc.addEvc = function(evc, evc_type, tenant, callback) {
378 var uni_json = getJsonUnis(evc.unis);
383 "svc-type" : evc.svc_type,
384 "tenant-id" : tenant,
387 "evc-type" : evc_type,
388 "preserve-ce-vlan-id" : evc.is_preserve_vlan,
389 "max-svc-frame-size" : evc.mtu_size,
390 "unicast-svc-frm-delivery" : evc.unicast,
391 "multicast-svc-frm-delivery" : evc.multicast,
395 "admin-state-enabled" : true
399 if (evc.is_preserve_vlan) {
400 data["mef-service"]["evc"]["preserved-vlan"] = evc.preserved_vlan;
404 url:"/restconf/config/mef-services:mef-services/",
406 }).then(function successCallback(response) {
407 if (callback != undefined) {
412 svc.getServices = function(tenantid, callback) {
416 url:"/restconf/config/mef-services:mef-services/"
417 }).then(function successCallback(response) {
418 evcs = response.data["mef-services"]["mef-service"]; // TODO try to filter on server side
419 if (evcs != undefined) {
420 evcs = evcs.filter(function(evc){return evc["tenant-id"] == tenantid;});
421 for (i=0; i < evcs.length; i++) {
422 if ((evcs[i].evc != undefined) && (evcs[i].evc.unis.uni != undefined)) {
423 var unis = evcs[i].evc.unis.uni;
424 for (j=0; j < unis.length; j++) {
425 if ((unis[j]['evc-uni-ce-vlans'] != undefined) && (unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'] != undefined)){
426 unis[j].vlans = unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'].map(function(u){return u.vid;}).sort();
434 if (callback != undefined) {
437 }, function errorCallback(response) {
438 console.log(response);
443 svc.getAllServices = function(callback) {
446 url:"/restconf/config/mef-services:mef-services/"
447 }).then(function successCallback(response) {
448 if (callback != undefined) {
449 callback(response.data["mef-services"]["mef-service"]);
451 }, function errorCallback(response) {
452 if (response.status == 404) {
455 console.log(response);
459 svc.addTenantToService = function(svcId, tenantName, callbackSuccess, callbackFailure){
462 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcId,
463 data:{"tenant-id":tenantName}
465 if (callbackSuccess != undefined) {
469 if (callbackFailure != undefined) {
472 console.log(response);
477 svc.removeEvc = function(svcid, callback) {
480 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/"
481 }).then(function successCallback(response) {
482 if (callback != undefined) {
488 svc.addIpvcUni = function(svcid, uni_id, ipuni_id, callback) {
496 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/"+uni_id+"/"+ipuni_id,
498 }).then(function successCallback(response) {
499 if (callback != undefined) {
502 }, function failureCallback(response) {
503 if (callback != undefined) {
509 svc.deleteIpvcUni = function(svcid, uni_id, ipuni_id, callback) {
512 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/" + uni_id +"/"+ipuni_id + "/"
513 }).then(function successCallback(response) {
514 if (callback != undefined) {
522 svc.addEvcUni = function(svcid, uni_id, role, vlans, callback) {
526 "admin-state-enabled":true
529 if (vlans != undefined) {
530 data.uni['evc-uni-ce-vlans'] = {"evc-uni-ce-vlan":[]}
531 for (var i=0; i< vlans.length; ++i) {
532 data.uni['evc-uni-ce-vlans']["evc-uni-ce-vlan"].push({"vid":vlans[i]});
537 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis",
539 }).then(function successCallback(response) {
540 if (callback != undefined) {
543 }, function failureCallback(response) {
544 if (callback != undefined) {
550 svc.addEvcUniVlan = function(svcid, uni_id, vlan, callback) {
553 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/evc-uni-ce-vlans/",
554 data:{"evc-uni-ce-vlan":{"vid":vlan}}
555 }).then(function successCallback(response) {
556 if (callback != undefined) {
562 svc.deleteEvcUni = function(svcid, uni_id, callback) {
565 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/"
566 }).then(function successCallback(response) {
567 if (callback != undefined) {
575 svc.deleteVlan = function(svc_id, uni_id, vlan,callback) {
578 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+"/"
579 }).then(function successCallback(response) {
580 if (callback != undefined) {
586 svc.addVlan = function(svc_id, uni_id, vlan, callback) {
589 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+"/",
590 data:{"evc-uni-ce-vlan":{"vid":vlan}}
591 }).then(function successCallback(response) {
592 if (callback != undefined) {
598 svc.getNetworkNames = function(callback){
601 url:"/restconf/config/neutron:neutron/networks/"
602 }).then(function successCallback(response) {
603 if (callback != undefined) {
604 callback(response.data.networks.network);