Skip to content

Commit

Permalink
Merge pull request #346 from ggiamarchi/support-http-proxy
Browse files Browse the repository at this point in the history
Support HTTP Proxy
  • Loading branch information
ggiamarchi authored Jul 27, 2018
2 parents f5679ab + 466912b commit c3657b0
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ This provider exposes quite a few provider-specific configuration options:
* `ssl_ca_file` - The location of CA certificate file.
* `ssl_verify_peer` - Verify peer certificate when connecting to endpoint. Defaults to true. Set to false to disable check (beware this is not secure!)

### VM Configuration
### Machine Configuration

* `server_name` - The name of the server within OpenStack Cloud. This
defaults to the name of the Vagrant machine (via `config.vm.define`), but
Expand All @@ -113,6 +113,10 @@ This provider exposes quite a few provider-specific configuration options:
* `user_data` - String of User data to be sent to the newly created OpenStack instance. Use this e.g. to inject a script at boot time.
* `metadata` - A Hash of metadata that will be sent to the instance for configuration e.g. `os.metadata = { 'key' => 'value' }`
* `scheduler_hints` - Pass hints to the OpenStack scheduler, e.g. { "cell": "some cell name" }
* `server_create_timeout` - Time to wait in seconds for the server to be created when `vagrant up`. Default is `200`
* `server_active_timeout` - Time to wait in seconds for the server to become active when `vagrant up` or `vagrant resume`. Default is `200`
* `server_stop_timeout` - Time to wait in seconds for the server to stop when `vagrant halt`. Default is `200`
* `server_delete_timeout` - Time to wait in seconds for the server to be deleted when `vagrant destroy`. Default is `200`

#### Floating IPs

Expand Down Expand Up @@ -237,7 +241,6 @@ os.stacks = [
end
```


### SSH authentication

* `keypair_name` - The name of the key pair register in nova to associate with the VM. The public key should
Expand Down Expand Up @@ -285,14 +288,11 @@ the remote machine over SSH.
This is good enough for all built-in Vagrant provisioners (shell,
chef, and puppet) to work!

### Timeouts
### HTTP options

* `server_create_timeout` - Time to wait in seconds for the server to be created when `vagrant up`. Default is `200`
* `server_active_timeout` - Time to wait in seconds for the server to become active when `vagrant up` or `vagrant resume`. Default is `200`
* `server_stop_timeout` - Time to wait in seconds for the server to stop when `vagrant halt`. Default is `200`
* `server_delete_timeout` - Time to wait in seconds for the server to be deleted when `vagrant destroy`. Default is `200`
* `http.open_timeout` - Open timeout for any HTTP request. Default is `60`
* `http.read_timeout` - Read timeout for any HTTP request. Default is `30`
* `http.proxy` - HTTP Proxy URL to use for all OpenStack API calls

### Provisioners meta-args

Expand Down
21 changes: 21 additions & 0 deletions samples/09_with_http_proxy.001.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bats

load test_helper

@test "09 - With HTTP Proxy" {
title "$BATS_TEST_DESCRIPTION"

export VAGRANT_CWD=$BATS_TEST_DIRNAME/09_with_http_proxy

run exec_vagrant up
flush_out
[ "$status" -eq 0 ]

run exec_vagrant ssh -c "true"
flush_out
[ "$status" -eq 0 ]

run exec_vagrant destroy
flush_out
[ "$status" -eq 0 ]
}
25 changes: 25 additions & 0 deletions samples/09_with_http_proxy/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure('2') do |config|

config.ssh.username = ENV['OS_SSH_USERNAME']

config.vm.provider :openstack do |os, ov|
os.http.proxy = 'http://openstack:3128'

os.server_name = '09_with_http_proxy'
os.openstack_auth_url = ENV['OS_AUTH_URL']
os.tenant_name = ENV['OS_TENANT_NAME']
os.username = ENV['OS_USERNAME']
os.password = ENV['OS_PASSWORD']
os.region = ENV['OS_REGION_NAME']
os.floating_ip_pool = ENV['OS_FLOATING_IP_POOL']
os.floating_ip_pool_always_allocate = (ENV['OS_FLOATING_IP_ALWAYS_ALLOCATE'] == 'true')
os.flavor = ENV['OS_FLAVOR']
os.image = ENV['OS_IMAGE']
os.networks << ENV['OS_NETWORK']

ov.nfs.functional = false
end
end
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 c3657b0

Please sign in to comment.