| Jeremy Mordkoff | e29efc3 | 2016-09-07 18:59:17 -0400 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2016 RIFT.IO Inc |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | var Promise = require('bluebird'); |
| 21 | var utils = require('../../../framework/core/api_utils/utils.js'); |
| 22 | var request = utils.request; |
| 23 | var constants = require('../../../framework/core/api_utils/constants.js'); |
| 24 | var APIVersion = '/v1'; |
| 25 | var crashDetails = {}; |
| 26 | var debug = {}; |
| 27 | var _ = require('lodash'); |
| 28 | |
| 29 | crashDetails.get = function(req) { |
| 30 | var api_server = req.query["api_server"]; |
| 31 | |
| 32 | return new Promise(function(resolve, reject) { |
| 33 | var requestHeaders = {}; |
| 34 | _.extend(requestHeaders, |
| 35 | constants.HTTP_HEADERS.accept.data, { |
| 36 | 'Authorization': req.get('Authorization') |
| 37 | }); |
| 38 | request({ |
| 39 | url: utils.confdPort(api_server) + APIVersion +'/api/operational/crash?deep', |
| 40 | type: 'GET', |
| 41 | headers: requestHeaders, |
| 42 | forever: constants.FOREVER_ON, |
| 43 | rejectUnauthorized: false, |
| 44 | }, |
| 45 | function(error, response, body) { |
| 46 | var data; |
| 47 | console.log(error); |
| 48 | if (utils.validateResponse('crashDetails.get', error, response, body, resolve, reject)) { |
| 49 | try { |
| 50 | data = JSON.parse(response.body)['rwshell-mgmt:crash'].list.vm; |
| 51 | } catch (e) { |
| 52 | return reject(e); |
| 53 | } |
| 54 | |
| 55 | return resolve(data); |
| 56 | } |
| 57 | }); |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | debug.crashDetails = crashDetails; |
| 62 | |
| 63 | module.exports = debug; |