From b48521950e6bce2167eb5fd628d6e8a3f7ba241a Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Mon, 5 Oct 2015 17:31:47 +0200 Subject: [PATCH] Always use got instead of request. --- package.json | 1 - src/api/host.coffee | 12 +++++------- src/api/vm.coffee | 15 ++++++--------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index f9c605db1..ec9905fdf 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "passport-local": "^1.0.0", "proxy-http-request": "0.1.0", "redis": "^2.0.1", - "request": "^2.53.0", "schema-inspector": "^1.5.1", "serve-static": "^1.9.2", "source-map-support": "^0.3.2", diff --git a/src/api/host.coffee b/src/api/host.coffee index 86366f17b..5583fc4b5 100644 --- a/src/api/host.coffee +++ b/src/api/host.coffee @@ -3,12 +3,11 @@ $find = require 'lodash.find' $findIndex = require 'lodash.findindex' $forEach = require 'lodash.foreach' endsWith = require 'lodash.endswith' +got = require('got') startsWith = require 'lodash.startswith' {coroutine: $coroutine} = require 'bluebird' {parseXml, promisify} = require '../utils' -$request = promisify(require('request')) - #===================================================================== set = $coroutine (params) -> @@ -278,11 +277,10 @@ stats = $coroutine ({host, granularity}) -> granularity = {0:0, 1:1, 2:4, 3:7}[granularity] xapi = @getXAPI host - [response, body] = yield $request { - method: 'get' - rejectUnauthorized: false - url: 'https://'+host.address+'/host_rrd?session_id='+xapi.sessionId - } + {body} = response = yield got( + "https://#{host.address}/host_rrd?session_id=#{xapi.sessionId}", + { rejectUnauthorized: false } + ) if response.statusCode isnt 200 throw new Error('Cannot fetch the RRDs') diff --git a/src/api/vm.coffee b/src/api/vm.coffee index 10d2f789c..7a0566aa3 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -8,6 +8,7 @@ $result = require 'lodash.result' endsWith = require 'lodash.endswith' escapeStringRegexp = require 'escape-string-regexp' eventToPromise = require 'event-to-promise' +got = require('got') map = require 'lodash.map' sortBy = require 'lodash.sortby' startsWith = require 'lodash.startswith' @@ -16,13 +17,10 @@ startsWith = require 'lodash.startswith' { formatXml: $js2xml, parseXml, - pFinally, - promisify + pFinally } = require '../utils' {isVmRunning: $isVMRunning} = require('../xapi') -$request = promisify(require('request')) - #===================================================================== # TODO: Implement ACLs @@ -788,11 +786,10 @@ stats = $coroutine ({vm, granularity}) -> else unless type is 'host' throw new Error "unexpected type: got #{type} instead of host" - [response, body] = yield $request { - method: 'get' - rejectUnauthorized: false - url: 'https://'+host.address+'/vm_rrd?session_id='+xapi.sessionId+'&uuid='+vm.id - } + {body} = response = yield got( + "https://#{host.address}/vm_rrd?session_id=#{xapi.sessionId}&uuid=#{vm.id}", + { rejectUnauthorized: false } + ) if response.statusCode isnt 200 throw new Error('Cannot fetch the RRDs')