Skip to content

Commit

Permalink
Merge ab77001 into f5679ab
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi committed Jul 26, 2018
2 parents f5679ab + ab77001 commit 683c071
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/lib/vagrant-openstack-provider/client/rest_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
module VagrantPlugins
module Openstack
module RestUtils
def self._set_proxy(config)
@logger = Log4r::Logger.new('vagrant_openstack::restutils')
if config.http.proxy
RestClient.proxy = config.http.proxy
@logger.info "Setting up HTTP proxy to '#{config.http.proxy}'"
end
end

def self.get(env, url, headers = {}, &block)
config = env[:machine].provider_config
_set_proxy(config)
RestClient::Request.execute(method: :get, url: url, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end

def self.post(env, url, payload, headers = {}, &block)
config = env[:machine].provider_config
_set_proxy(config)
RestClient::Request.execute(method: :post, url: url, payload: payload, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end

def self.delete(env, url, headers = {}, &block)
config = env[:machine].provider_config
_set_proxy(config)
RestClient::Request.execute(method: :delete, url: url, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
Expand Down
6 changes: 6 additions & 0 deletions source/lib/vagrant-openstack-provider/config/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ class HttpConfig
# @return [Integer]
attr_accessor :read_timeout

#
# @return [Integer]
attr_accessor :proxy

def initialize
@open_timeout = UNSET_VALUE
@read_timeout = UNSET_VALUE
@proxy = UNSET_VALUE
end

def finalize!
@open_timeout = 60 if @open_timeout == UNSET_VALUE
@read_timeout = 30 if @read_timeout == UNSET_VALUE
@proxy = nil if @proxy == UNSET_VALUE
end

def merge(other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
double('http').tap do |http|
http.stub(:read_timeout) { 42 }
http.stub(:open_timeout) { 43 }
http.stub(:proxy) { nil }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
double('http').tap do |http|
http.stub(:read_timeout) { 42 }
http.stub(:open_timeout) { 43 }
http.stub(:proxy) { nil }
end
end

Expand Down
1 change: 1 addition & 0 deletions source/spec/vagrant-openstack-provider/client/heat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
double('http').tap do |http|
http.stub(:read_timeout) { 42 }
http.stub(:open_timeout) { 43 }
http.stub(:proxy) { nil }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
double('http').tap do |http|
http.stub(:read_timeout) { 42 }
http.stub(:open_timeout) { 43 }
http.stub(:proxy) { nil }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
double('http').tap do |http|
http.stub(:read_timeout) { 42 }
http.stub(:open_timeout) { 43 }
http.stub(:proxy) { nil }
end
end

Expand Down
1 change: 1 addition & 0 deletions source/spec/vagrant-openstack-provider/client/nova_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
double('http').tap do |http|
http.stub(:read_timeout) { 42 }
http.stub(:open_timeout) { 43 }
http.stub(:proxy) { nil }
end
end

Expand Down

0 comments on commit 683c071

Please sign in to comment.