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