vBDManager services initial commit
[honeycomb.git] / vbd / gui / module / src / main / resources / vpp / services / bdm.vpp.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('bdmVppService', function(VPPRestangular) {
10         var s = {};
11
12         var Vpp = function(nodeId, vppId) {
13             this['node-id'] = nodeId || null;
14             this['supporting-node'] = [
15                 {
16                     'topology-ref': 'topology-netconf',
17                     'node-ref': vppId
18                 }
19             ];
20             this['netconf-node-topology:pass-through'] = {};
21         };
22
23         s.createObj = function(nodeId, vppId) {
24             return new Vpp(nodeId, vppId);
25         };
26
27         s.add = function(vpp, bridgeDomainId,  successCallback, errorCallback) {
28             var restObj = VPPRestangular.one('restconf').one('config').one('network-topology:network-topology').one('topology').one(bridgeDomainId).one('node').one(vpp['node-id']);
29             var dataObj = {'node': [vpp]};
30
31             restObj.customPUT(dataObj).then(function(data) {
32                 successCallback(data);
33             }, function(res) {
34                 errorCallback(res.data, res.status);
35             });
36         };
37
38         s.get = function(bridgeDomainId, successCallback, errorCallback) {
39             var restObj = VPPRestangular.one('restconf').one('config').one('network-topology:network-topology').one('topology').one(bridgeDomainId);
40
41             restObj.get().then(function(data) {
42                 successCallback(data);
43             }, function(res) {
44                 errorCallback(res.data, res.status);
45             });
46         };
47
48
49         return s;
50     });
51 });