4 * Copyright 2016 RIFT.IO Inc
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
;
29 return new Promise((resolve
,reject
) => {
31 url
: 'api/decorated-catalog?api_server=' + API_SERVER
,
33 beforeSend
: Utils
.addAuthorizationStub
,
34 success: function (data
) {
36 typeof(data
) == "string" ? JSON
.parse(data
):data
39 }).fail(function(xhr
){
41 //Authentication and the handling of fail states should be wrapped up into a connection class.
42 Utils
.checkAuthentication(xhr
.status
);
46 success
: Alt
.actions
.global
.getCatalogSuccess
,
47 error
: Alt
.actions
.global
.getCatalogError
51 return new Promise((resolve
, reject
) => {
53 url
: 'api/cloud-account?api_server=' +
56 beforeSend
: Utils
.addAuthorizationStub
,
57 success: function (data
) {
66 success
: Alt
.actions
.global
.getLaunchCloudAccountSuccess
,
67 error
: Alt
.actions
.global
.getLaunchCloudAccountError
71 return new Promise((resolve
, reject
) => {
73 url
: 'api/data-centers?api_server=' +
76 beforeSend
: Utils
.addAuthorizationStub
,
77 success: function (data
) {
83 success
: Alt
.actions
.global
.getDataCentersSuccess
,
84 error
: Alt
.actions
.global
.getDataCentersError
87 remote (state
, VNFDid
) {
88 return new Promise((resolve
,reject
) => {
90 url
: 'api/vnfd?api_server=' + API_SERVER
,
92 beforeSend
: Utils
.addAuthorizationStub
,
97 success: function (data
) {
99 typeof(data
) == "string" ? JSON
.parse(data
):data
105 success
: Alt
.actions
.global
.getVDUSuccess
,
106 error
: Alt
.actions
.global
.getVDUError
109 remote (state
, NSR
) {
110 return new Promise((resolve
, reject
) => {
111 console
.log('Attempting to instantiate NSR:', NSR
)
113 url
: 'api/nsr?api_server=' + API_SERVER
,
115 beforeSend
: Utils
.addAuthorizationStub
,
120 success: function (data
) {
122 typeof(data
) == "string" ? JSON
.parse(data
):data
125 error: function (err
) {
126 console
.log('There was an error launching')
128 }).fail(function(xhr
){
129 //Authentication and the handling of fail states should be wrapped up into a connection class.
130 Utils
.checkAuthentication(xhr
.status
);
132 if(xhr
.responseText
) {
134 error
= JSON
.stringify(xhr
.responseText
);
143 loading
: Alt
.actions
.global
.launchNSRLoading
,
144 success
: Alt
.actions
.global
.launchNSRSuccess
,
145 error
: Alt
.actions
.global
.launchNSRError
149 return new Promise((resolve
,reject
) => {
151 url
: 'api/ssh-key?api_server=' + API_SERVER
,
153 beforeSend
: Utils
.addAuthorizationStub
,
154 success: function (data
) {
157 }).fail(function(xhr
){
159 //Authentication and the handling of fail states should be wrapped up into a connection class.
160 Utils
.checkAuthentication(xhr
.status
);
164 loading
: Actions
.getInstantiateSshKeyLoading
,
165 success
: Actions
.getInstantiateSshKeySuccess
,
166 error
: Actions
.getInstantiateSshKeyError
170 return new Promise((resolve
, reject
) => {
172 url
: 'api/nsd/' + NSDId
+ '/input-param?api_server=' + API_SERVER
,
174 beforeSend
: Utils
.addAuthorizationStub
,
175 success: function (data
) {
184 return new Promise((resolve
, reject
) => {
186 url
: 'api/config-agent-account?api_server=' +
189 beforeSend
: Utils
.addAuthorizationStub
,
190 success: function (data
) {
199 success
: Alt
.actions
.global
.getConfigAgentSuccess
,
200 error
: Alt
.actions
.global
.getConfigAgentError
202 getResourceOrchestrator
: {
204 return new Promise(function(resolve
, reject
) {
206 url
: 'passthrough/data/api/running/resource-orchestrator' + '?api_server=' + API_SERVER
,
208 beforeSend
: Utils
.addAuthorizationStub
,
209 contentType
: "application/json",
210 success: function(data
) {
212 if (data
.hasOwnProperty("rw-launchpad:resource-orchestrator")) {
213 returnedData
= data
['rw-launchpad:resource-orchestrator'];
217 resolve(returnedData
);
219 error: function(error
) {
220 console
.log("There was an error updating the account: ", arguments
);
223 }).fail(function(xhr
){
224 //Authentication and the handling of fail states should be wrapped up into a connection class.
225 Utils
.checkAuthentication(xhr
.status
);
226 return reject('error');
230 interceptResponse
: interceptResponse({
231 'error': 'There was an error retrieving the resource orchestrator information.'
233 success
: Alt
.actions
.global
.getResourceOrchestratorSuccess
,
234 loading
: Alt
.actions
.global
.showScreenLoader
,
235 error
: Alt
.actions
.global
.showNotification
240 function interceptResponse (responses
) {
241 return function(data
, action
, args
) {
242 if(responses
.hasOwnProperty(data
)) {