d2abc77b133d67854909ab0d1f814736dd4dcd0a
[honeycomb.git] / vbd / gui / module / src / main / resources / vpp / services / bdm.interface.service.js
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 define(['app/vpp/vpp.module'], function(vpp) {
9     vpp.register.factory('bdmInterfaceService', function(VPPRestangular, bdmVppService) {
10         var s = {};
11
12         var Interface = function(tpId, interfaceName) {
13             this['tp-id'] = tpId || null;
14             this['vbridge-topology:user-interface'] = interfaceName;
15         };
16
17         s.createObj = function(tpId, interfaceName) {
18             return new Interface(tpId, interfaceName);
19         };
20
21         s.add = function(interf, bridgeDomainId, vppId, successCallback, errorCallback) {
22             var restObj = VPPRestangular.one('restconf').one('config').one('network-topology:network-topology')
23                 .one('topology').one(bridgeDomainId).one('node').one(vppId).one('termination-point').one(encodeURIComponent(interf['tp-id']));
24
25             var dataObj = {'termination-point': [interf]};
26
27             var write = function() {
28                 restObj.customPUT(dataObj).then(function(data) {
29                     successCallback(data);
30                 }, function(res) {
31                     errorCallback(res.data, res.status);
32                 });
33             };
34
35             var errorCallback = function() {};
36
37             bdmVppService.checkAndWriteVpp(bridgeDomainId, vppId, write, errorCallback);
38
39
40         };
41
42         s.delete = function(interf, bridgeDomainId, vppId, successCallback, errorCallback) {
43             var restObj = VPPRestangular.one('restconf').one('config').one('network-topology:network-topology')
44                 .one('topology').one(bridgeDomainId).one('node').one(vppId).one('termination-point').one(encodeURIComponent(interf['tp-id']));
45
46             restObj.remove().then(function(data) {
47                 successCallback(data);
48             }, function(res) {
49                 errorCallback(res.data, res.status);
50             });
51         };
52
53         s.get = function(bridgeDomainId, vppId, successCallback, errorCallback) {
54             var restObj = VPPRestangular.one('restconf').one('config').one('network-topology:network-topology')
55                 .one('topology').one(bridgeDomainId).one('node').one(vppId);
56
57             restObj.get().then(function(data) {
58                 successCallback(data);
59             }, function(res) {
60                 errorCallback(res.data, res.status);
61             });
62         };
63
64         return s;
65     });
66 });