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