d9271d630305fe7210f3ba2860a134757368a215
[osm/UI.git] / skyquake / plugins / launchpad / src / createSource.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 var alt = require('./alt');
20 var Utils = require('utils/utils.js');
21 var API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
22 var NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
23 var createActions = require('./createActions.js');
24 import $ from 'jquery';
25
26 module.exports = {
27 getNetworkServices: function() {
28 return {
29 remote: function() {
30 return new Promise(function(resolve, reject) {
31 $.ajax({
32 url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/network-service?api_server=' + API_SERVER,
33 type: 'GET',
34 beforeSend: Utils.addAuthorizationStub,
35 success: function(data) {
36 resolve(data);
37 }
38 })
39 })
40 },
41 success: createActions.getNetworkServicesSuccess,
42 error: createActions.getNetworkServicesError
43 }
44 },
45 createEnvironment: function() {
46 return {
47 remote: function(state, environment) {
48 return $.ajax({
49 url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/environment?api_server=' + API_SERVER,
50 type: 'POST',
51 beforeSend: Utils.addAuthorizationStub,
52 dataType: 'json',
53 data: JSON.stringify(environment),
54 contentType: 'application/json',
55 accept: 'application/json'
56 })
57
58 },
59 success: createActions.createEnvironmentSuccess,
60 error: createActions.createEnvironmentsError
61 }
62 },
63 getPools: function() {
64 return {
65 remote: function() {
66 return new Promise(function(resolve, reject) {
67 $.ajax({
68 url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/pools?api_server=' + API_SERVER,
69 type: 'GET',
70 beforeSend: Utils.addAuthorizationStub,
71 success: function(data) {
72 resolve(data);
73 }
74 })
75 })
76 },
77 success: createActions.getPoolsSuccess,
78 error: createActions.getPoolsError
79 }
80 },
81 getSlaParams: function() {
82 return {
83 remote: function() {
84 return new Promise(function(resolve, reject) {
85 $.ajax({
86 url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/sla-params?api_server=' + API_SERVER,
87 type: 'GET',
88 beforeSend: Utils.addAuthorizationStub,
89 success: function(data) {
90 resolve(data);
91 }
92 })
93 })
94 },
95 success: createActions.getSlaParamsSuccess,
96 error: createActions.getSlaParamsError
97 }
98 }
99 }