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