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
);
135 loading
: Alt
.actions
.global
.launchNSRLoading
,
136 success
: Alt
.actions
.global
.launchNSRSuccess
,
137 error
: Alt
.actions
.global
.launchNSRError
141 return new Promise((resolve
,reject
) => {
143 url
: 'api/ssh-key?api_server=' + API_SERVER
,
145 beforeSend
: Utils
.addAuthorizationStub
,
146 success: function (data
) {
149 }).fail(function(xhr
){
151 //Authentication and the handling of fail states should be wrapped up into a connection class.
152 Utils
.checkAuthentication(xhr
.status
);
156 loading
: Actions
.getInstantiateSshKeyLoading
,
157 success
: Actions
.getInstantiateSshKeySuccess
,
158 error
: Actions
.getInstantiateSshKeyError
162 return new Promise((resolve
, reject
) => {
164 url
: 'api/nsd/' + NSDId
+ '/input-param?api_server=' + API_SERVER
,
166 beforeSend
: Utils
.addAuthorizationStub
,
167 success: function (data
) {
176 return new Promise((resolve
, reject
) => {
178 url
: 'api/config-agent-account?api_server=' +
181 beforeSend
: Utils
.addAuthorizationStub
,
182 success: function (data
) {
191 success
: Alt
.actions
.global
.getConfigAgentSuccess
,
192 error
: Alt
.actions
.global
.getConfigAgentError
194 getResourceOrchestrator
: {
196 return new Promise(function(resolve
, reject
) {
198 url
: 'passthrough/data/api/running/resource-orchestrator' + '?api_server=' + API_SERVER
,
200 beforeSend
: Utils
.addAuthorizationStub
,
201 contentType
: "application/json",
202 success: function(data
) {
204 if (data
.hasOwnProperty("rw-launchpad:resource-orchestrator")) {
205 returnedData
= data
['rw-launchpad:resource-orchestrator'];
209 resolve(returnedData
);
211 error: function(error
) {
212 console
.log("There was an error updating the account: ", arguments
);
215 }).fail(function(xhr
){
216 //Authentication and the handling of fail states should be wrapped up into a connection class.
217 Utils
.checkAuthentication(xhr
.status
);
218 return reject('error');
222 interceptResponse
: interceptResponse({
223 'error': 'There was an error retrieving the resource orchestrator information.'
225 success
: Alt
.actions
.global
.getResourceOrchestratorSuccess
,
226 loading
: Alt
.actions
.global
.showScreenLoader
,
227 error
: Alt
.actions
.global
.showNotification
232 function interceptResponse (responses
) {
233 return function(data
, action
, args
) {
234 if(responses
.hasOwnProperty(data
)) {