Module: VagrantPlugins::Openstack::HttpUtils

Includes:
RequestLogger
Included in:
CinderClient, GlanceClient, HeatClient, NeutronClient, NovaClient
Defined in:
lib/vagrant-openstack-provider/client/http_utils.rb,
lib/vagrant-openstack-provider/client/request_logger.rb

Defined Under Namespace

Modules: RequestLogger

Instance Method Summary collapse

Methods included from RequestLogger

#log_request, #log_response

Instance Method Details

#delete(env, url, headers = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-openstack-provider/client/http_utils.rb', line 43

def delete(env, url, headers = {})
  calling_method = caller[0][/`.*'/][1..-2]
  @logger.debug("#{calling_method} - start")

  headers.merge!('X-Auth-Token' => @session.token, :accept => :json, :content_type => :json)

  log_request(:DELETE, url, headers)

  authenticated(env) do
    RestUtils.delete(env, url, headers) { |res| handle_response(res) }.tap do
      @logger.debug("#{calling_method} - end")
    end
  end
end

#get(env, url, headers = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-openstack-provider/client/http_utils.rb', line 13

def get(env, url, headers = {})
  calling_method = caller[0][/`.*'/][1..-2]
  @logger.debug("#{calling_method} - start")

  headers.merge!('X-Auth-Token' => @session.token, :accept => :json)

  log_request(:GET, url, headers)

  authenticated(env) do
    RestUtils.get(env, url, headers) { |res| handle_response(res) }.tap do
      @logger.debug("#{calling_method} - end")
    end
  end
end

#get_api_version_list(env, service_type) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vagrant-openstack-provider/client/http_utils.rb', line 58

def get_api_version_list(env, service_type)
  url = @session.endpoints[service_type]
  headers = { 'X-Auth-Token' => @session.token, :accept => :json }
  log_request(:GET, url, headers)

  json = RestUtils.get(env, url, headers) do |response|
    log_response(response)
    case response.code
    when 200, 300
      response
    when 401
      fail Errors::AuthenticationFailed
    else
      fail Errors::VagrantOpenstackError, message: response.to_s
    end
  end
  JSON.parse(json)['versions']
end

#post(env, url, body = nil, headers = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-openstack-provider/client/http_utils.rb', line 28

def post(env, url, body = nil, headers = {})
  calling_method = caller[0][/`.*'/][1..-2]
  @logger.debug("#{calling_method} - start")

  headers.merge!('X-Auth-Token' => @session.token, :accept => :json, :content_type => :json)

  log_request(:POST, url, body, headers)

  authenticated(env) do
    RestUtils.post(env, url, body, headers) { |res| handle_response(res) }.tap do
      @logger.debug("#{calling_method} - end")
    end
  end
end