e439071e58b16522f506adb79f73d678f76333e3
[osm/riftware.git] /
1
2 /*
3  * 
4  *
5  */
6 import NS_ACTIONS from './launchNetworkServiceActions.js';
7 import $ from 'jquery';
8 let Utils = require('../../utils/utils.js');
9
10 const API_SERVER = rw.getSearchParams(window.location).api_server;
11 const API_PORT = rw.getSearchParams(window.location).api_port;
12 const NODE_PORT = API_PORT || 3000;
13 export default {
14   getCatalog() {
15     return {
16       remote (state) {
17         return new Promise((resolve,reject) => {
18           $.ajax({
19             url: 'http://' + window.location.hostname + ':' + NODE_PORT + '/launchpad/catalog?api_server=' + API_SERVER,
20             type: 'GET',
21             beforeSend: Utils.addAuthorizationStub,
22             success: function (data) {
23               resolve(
24                       typeof(data) == "string" ? JSON.parse(data):data
25                       );
26             }
27           }).fail(function(xhr){
28             console.log(xhr)
29             //Authentication and the handling of fail states should be wrapped up into a connection class.
30             Utils.checkAuthentication(xhr.status);
31           });
32         });
33       },
34       success: NS_ACTIONS.getCatalogSuccess,
35       error: NS_ACTIONS.getCatalogError
36     }
37   },
38   getCloudAccount() {
39     return {
40       remote (state, cb) {
41         return new Promise((resolve, reject) => {
42           $.ajax({
43             url: 'http://' + window.location.hostname + ':' +
44               NODE_PORT + '/launchpad/cloud-account?api_server=' +
45               API_SERVER,
46               type: 'GET',
47               beforeSend: Utils.addAuthorizationStub,
48               success: function (data) {
49                 resolve(data);
50                 if(cb) {
51                   cb();
52                 }
53               }
54           })
55         })
56       },
57       success: NS_ACTIONS.getCloudAccountSuccess,
58       error: NS_ACTIONS.getCloudAccountError
59     }
60   },
61   getDataCenters() {
62     return {
63       remote () {
64         return new Promise((resolve, reject) => {
65           $.ajax({
66             url: 'http://' + window.location.hostname + ':' +
67               NODE_PORT + '/launchpad/data-centers?api_server=' +
68               API_SERVER,
69               type: 'GET',
70               beforeSend: Utils.addAuthorizationStub,
71               success: function (data) {
72                 resolve(data);
73               }
74           })
75         })
76       },
77       success: NS_ACTIONS.getDataCentersSuccess,
78       error: NS_ACTIONS.getDataCentersError
79     }
80   },
81   getVDU() {
82     return {
83       remote (state, VNFDid) {
84         return new Promise((resolve,reject) => {
85           $.ajax({
86             url: 'http://' + window.location.hostname + ':' + NODE_PORT + '/launchpad/vnfd?api_server=' + API_SERVER,
87             type: 'POST',
88             beforeSend: Utils.addAuthorizationStub,
89             dataType:'json',
90             data: {
91               data: VNFDid
92             },
93             success: function (data) {
94               resolve(
95                 typeof(data) == "string" ? JSON.parse(data):data
96               );
97             }
98           })
99         });
100       },
101       success: NS_ACTIONS.getVDUSuccess,
102       error: NS_ACTIONS.getVDUError
103     }
104   },
105   launchNSR() {
106     return {
107       remote (state, NSR) {
108         return new Promise((resolve, reject) => {
109           $.ajax({
110             url: 'http://' + window.location.hostname + ':' + NODE_PORT + '/launchpad/nsr?api_server=' + API_SERVER,
111             type: 'POST',
112             beforeSend: Utils.addAuthorizationStub,
113             dataType:'json',
114             data: {
115               data: NSR
116             },
117             success: function (data) {
118               resolve(
119                       typeof(data) == "string" ? JSON.parse(data):data
120                       );
121             },
122             error: function (err) {
123               reject({});
124             }
125           })
126         })
127       },
128       loading: NS_ACTIONS.launchNSRLoading,
129       success: NS_ACTIONS.launchNSRSuccess,
130       error: NS_ACTIONS.launchNSRError
131     }
132   },
133 <<<<<<< HEAD
134   getInputParams() {
135     return {
136       remote(state, NSDId) {
137         return new Promise((resolve, reject) => {
138           $.ajax({
139             url: 'http://' + window.location.hostname + ':' + NODE_PORT + '/launchpad/nsd/' + NSDId + '/input-param?api_server=' + API_SERVER,
140             type: 'GET',
141               beforeSend: Utils.addAuthorizationStub,
142               success: function (data) {
143                 resolve(data);
144               }
145           });
146         });
147       }
148     }
149 =======
150   getLaunchpadConfig: function() {
151     return {
152       remote: function() {
153         return new Promise(function(resolve, reject) {
154           $.ajax({
155             url: 'http://' + window.location.hostname + ':' + NODE_PORT + '/launchpad/config?api_server=' + API_SERVER,
156             type: 'GET',
157             beforeSend: Utils.addAuthorizationStub,
158             success: function(data) {
159               resolve(data);
160             }
161           });
162         });
163       },
164       success: NS_ACTIONS.getLaunchpadConfigSuccess,
165       error: NS_ACTIONS.getLaunchpadConfigError
166     };
167 >>>>>>> osm_mwc
168   }
169   // getCatalog() {
170   //   return {
171   //     remote (state) {
172   //       return new Promise((resolve,reject) => {
173   //         $.ajax({
174   //           url: 'http://' + window.location.hostname + ':' + NODE_PORT + '/launchpad/catalog?api_server=' + API_SERVER,
175   //           success: function (data) {
176   //             resolve(
177   //                     typeof(data) == "string" ? JSON.parse(data):data
178   //                     );
179   //           }
180   //         })
181   //       });
182   //     },
183   //     success: NS_ACTIONS.getCatalogSuccess,
184   //     error: NS_ACTIONS.getCatalogError
185   //   }
186   // }
187 }