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/data-centers?api_server=' +
56 beforeSend
: Utils
.addAuthorizationStub
,
57 success: function (data
) {
63 success
: Alt
.actions
.global
.getDataCentersSuccess
,
64 error
: Alt
.actions
.global
.getDataCentersError
67 remote (state
, VNFDid
) {
68 return new Promise((resolve
,reject
) => {
70 url
: 'api/vnfd?api_server=' + API_SERVER
,
72 beforeSend
: Utils
.addAuthorizationStub
,
77 success: function (data
) {
79 typeof(data
) == "string" ? JSON
.parse(data
):data
85 success
: Alt
.actions
.global
.getVDUSuccess
,
86 error
: Alt
.actions
.global
.getVDUError
90 return new Promise((resolve
, reject
) => {
91 console
.log('Attempting to instantiate NSR:', NSR
)
93 url
: 'api/nsr?api_server=' + API_SERVER
,
95 beforeSend
: Utils
.addAuthorizationStub
,
100 success: function (data
) {
102 typeof(data
) == "string" ? JSON
.parse(data
):data
105 error: function (err
) {
106 console
.log('There was an error launching')
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');
115 loading
: Alt
.actions
.global
.launchNSRLoading
,
116 success
: Alt
.actions
.global
.launchNSRSuccess
,
117 error
: Alt
.actions
.global
.launchNSRError
121 return new Promise((resolve
,reject
) => {
123 url
: 'api/ssh-key?api_server=' + API_SERVER
,
125 beforeSend
: Utils
.addAuthorizationStub
,
126 success: function (data
) {
129 }).fail(function(xhr
){
131 //Authentication and the handling of fail states should be wrapped up into a connection class.
132 Utils
.checkAuthentication(xhr
.status
);
136 loading
: Actions
.getInstantiateSshKeyLoading
,
137 success
: Actions
.getInstantiateSshKeySuccess
,
138 error
: Actions
.getInstantiateSshKeyError
142 return new Promise((resolve
, reject
) => {
144 url
: 'api/nsd/' + encodeURIComponent(NSDId
) + '/input-param?api_server=' + API_SERVER
,
146 beforeSend
: Utils
.addAuthorizationStub
,
147 success: function (data
) {
156 return new Promise((resolve
, reject
) => {
158 url
: 'api/config-agent-account?api_server=' +
161 beforeSend
: Utils
.addAuthorizationStub
,
162 success: function (data
) {
171 success
: Alt
.actions
.global
.getConfigAgentSuccess
,
172 error
: Alt
.actions
.global
.getConfigAgentError
174 getResourceOrchestratorAccounts
: {
175 remote: function(state
, cb
) {
176 return new Promise(function(resolve
, reject
) {
178 url
: 'api/ro-account' + '?api_server=' + API_SERVER
,
180 beforeSend
: Utils
.addAuthorizationStub
,
181 contentType
: "application/json",
182 success: function(data
) {
188 error: function(error
) {
189 console
.log("There was an error updating the account: ", arguments
);
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');
199 interceptResponse
: interceptResponse({
200 'error': 'There was an error retrieving the resource orchestrator information.'
202 success
: Alt
.actions
.global
.getResourceOrchestratorAccountsSuccess
,
203 loading
: Alt
.actions
.global
.showScreenLoader
,
204 error
: Alt
.actions
.global
.handleServerReportedError
208 function interceptResponse (responses
) {
209 return function(data
, action
, args
) {
210 if(responses
.hasOwnProperty(data
)) {