30b53225f32ac17efae23aef80fde62731e891bf
[osm/riftware.git] /
1 /*
2  *    Copyright 2016 RIFT.IO Inc
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17
18 /*
19  * STANDARD_RIFT_IO_COPYRIGHT
20  */
21 import NS_ACTIONS from './launchNetworkServiceActions.js';
22 import $ from 'jquery';
23 let Utils = require('utils/utils.js');
24 let rw = require('utils/rw.js');
25 const API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
26 const API_PORT = require('utils/rw.js').getSearchParams(window.location).api_port;
27 const NODE_PORT = API_PORT || 3000;
28 export default {
29   getCatalog() {
30     return {
31       remote (state) {
32         return new Promise((resolve,reject) => {
33           $.ajax({
34             url: '//' + window.location.hostname + ':' + NODE_PORT + '/launchpad/catalog?api_server=' + API_SERVER,
35             type: 'GET',
36             beforeSend: Utils.addAuthorizationStub,
37             success: function (data) {
38               resolve(
39                       typeof(data) == "string" ? JSON.parse(data):data
40                       );
41             }
42           }).fail(function(xhr){
43             console.log(xhr)
44             //Authentication and the handling of fail states should be wrapped up into a connection class.
45             Utils.checkAuthentication(xhr.status);
46           });
47         });
48       },
49       success: NS_ACTIONS.getCatalogSuccess,
50       error: NS_ACTIONS.getCatalogError
51     }
52   },
53   getCloudAccount() {
54     return {
55       remote (state, cb) {
56         return new Promise((resolve, reject) => {
57           $.ajax({
58             url: '//' + window.location.hostname + ':' +
59               NODE_PORT + '/launchpad/cloud-account?api_server=' +
60               API_SERVER,
61               type: 'GET',
62               beforeSend: Utils.addAuthorizationStub,
63               success: function (data) {
64                 resolve(data);
65                 if(cb) {
66                   cb();
67                 }
68               }
69           })
70         })
71       },
72       success: NS_ACTIONS.getCloudAccountSuccess,
73       error: NS_ACTIONS.getCloudAccountError
74     }
75   },
76   getDataCenters() {
77     return {
78       remote () {
79         return new Promise((resolve, reject) => {
80           $.ajax({
81             url: '//' + window.location.hostname + ':' +
82               NODE_PORT + '/launchpad/data-centers?api_server=' +
83               API_SERVER,
84               type: 'GET',
85               beforeSend: Utils.addAuthorizationStub,
86               success: function (data) {
87                 resolve(data);
88               }
89           })
90         })
91       },
92       success: NS_ACTIONS.getDataCentersSuccess,
93       error: NS_ACTIONS.getDataCentersError
94     }
95   },
96   getVDU() {
97     return {
98       remote (state, VNFDid) {
99         return new Promise((resolve,reject) => {
100           $.ajax({
101             url: '//' + window.location.hostname + ':' + NODE_PORT + '/launchpad/vnfd?api_server=' + API_SERVER,
102             type: 'POST',
103             beforeSend: Utils.addAuthorizationStub,
104             dataType:'json',
105             data: {
106               data: VNFDid
107             },
108             success: function (data) {
109               resolve(
110                 typeof(data) == "string" ? JSON.parse(data):data
111               );
112             }
113           })
114         });
115       },
116       success: NS_ACTIONS.getVDUSuccess,
117       error: NS_ACTIONS.getVDUError
118     }
119   },
120   launchNSR() {
121     return {
122       remote (state, NSR) {
123         return new Promise((resolve, reject) => {
124           console.log('Attempting to instantiate NSR:', NSR)
125           $.ajax({
126             url: '//' + window.location.hostname + ':' + NODE_PORT + '/launchpad/nsr?api_server=' + API_SERVER,
127             type: 'POST',
128             beforeSend: Utils.addAuthorizationStub,
129             dataType:'json',
130             data: {
131               data: NSR
132             },
133             success: function (data) {
134               resolve(
135                       typeof(data) == "string" ? JSON.parse(data):data
136                       );
137             },
138             error: function (err) {
139               reject({});
140             }
141           })
142         })
143       },
144       loading: NS_ACTIONS.launchNSRLoading,
145       success: NS_ACTIONS.launchNSRSuccess,
146       error: NS_ACTIONS.launchNSRError
147     }
148   },
149   getInputParams() {
150     return {
151       remote(state, NSDId) {
152         return new Promise((resolve, reject) => {
153           $.ajax({
154             url: '//' + window.location.hostname + ':' + NODE_PORT + '/launchpad/nsd/' + NSDId + '/input-param?api_server=' + API_SERVER,
155             type: 'GET',
156               beforeSend: Utils.addAuthorizationStub,
157               success: function (data) {
158                 resolve(data);
159               }
160           });
161         });
162       }
163     }
164   },
165   getLaunchpadConfig: function() {
166     return {
167       remote: function() {
168         return new Promise(function(resolve, reject) {
169           $.ajax({
170             url: '//' + window.location.hostname + ':' + NODE_PORT + '/launchpad/config?api_server=' + API_SERVER,
171             type: 'GET',
172             beforeSend: Utils.addAuthorizationStub,
173             success: function(data) {
174               resolve(data);
175             }
176           });
177         });
178       },
179       success: NS_ACTIONS.getLaunchpadConfigSuccess,
180       error: NS_ACTIONS.getLaunchpadConfigError
181     };
182   }
183   // getCatalog() {
184   //   return {
185   //     remote (state) {
186   //       return new Promise((resolve,reject) => {
187   //         $.ajax({
188   //           url: '//' + window.location.hostname + ':' + NODE_PORT + '/launchpad/catalog?api_server=' + API_SERVER,
189   //           success: function (data) {
190   //             resolve(
191   //                     typeof(data) == "string" ? JSON.parse(data):data
192   //                     );
193   //           }
194   //         })
195   //       });
196   //     },
197   //     success: NS_ACTIONS.getCatalogSuccess,
198   //     error: NS_ACTIONS.getCatalogError
199   //   }
200   // }
201 }