require "fog"
require "log4r"

module VagrantPlugins
  module OpenStack
    module Action
      # This action connects to OpenStack, verifies credentials work, and
      # puts the OpenStack connection object into the `:openstack_compute` key
      # in the environment.
      class ConnectOpenStack
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_openstack::action::connect_openstack")
        end

        def call(env)
          # Get the configs
          config   = env[:machine].provider_config
          api_key  = config.api_key
          endpoint = config.endpoint
          username = config.username
          tenant = config.tenant
          region = config.region

          connection_options = { :proxy => config.proxy }

          @logger.info("Connecting to OpenStack...")
          env[:openstack_compute] = Fog::Compute.new({
            :provider => :openstack,
            :connection_options => connection_options,
            :openstack_username => username,
            :openstack_api_key => api_key,
            :openstack_auth_url => endpoint,
            :openstack_tenant => tenant,
            :openstack_region => region
          })

          if config.network
            env[:openstack_network] = Fog::Network.new({
              :provider => :openstack,
              :connection_options => connection_options,
              :openstack_username => username,
              :openstack_api_key => api_key,
              :openstack_auth_url => endpoint,
              :openstack_tenant => tenant
            })
          end

          @app.call(env)
        end
      end
    end
  end
end

require "fog"
require "log4r"

module VagrantPlugins
  module OpenStack
    module Action
      # This action connects to OpenStack, verifies credentials work, and
      # puts the OpenStack connection object into the `:openstack_compute` key
      # in the environment.
      class ConnectOpenStack
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_openstack::action::connect_openstack")
        end

        def call(env)
          # Get the configs
          config   = env[:machine].provider_config
          api_key  = config.api_key
          endpoint = config.endpoint
          username = config.username
          tenant = config.tenant
          region = config.region

          # Pass proxy config down into the Fog::Connection object using
          # the `connection_options` hash.
          connection_options = { :proxy => config.proxy }

          @logger.info("Connecting to OpenStack...")
          @logger.debug("API connection params: #{connection_options.inspect}")
          env[:openstack_compute] = Fog::Compute.new({
            :provider => :openstack,
            :connection_options => connection_options,
            :openstack_username => username,
            :openstack_api_key => api_key,
            :openstack_auth_url => endpoint,
            :openstack_tenant => tenant,
            :openstack_region => region
          })

          if config.network
            env[:openstack_network] = Fog::Network.new({
              :provider => :openstack,
              :connection_options => connection_options,
              :openstack_username => username,
              :openstack_api_key => api_key,
              :openstack_auth_url => endpoint,
              :openstack_tenant => tenant
            })
          end

          @app.call(env)
        end
      end
    end
  end
end

Add a little debugging output.
Add a little debugging output.

While testing it is helpful to be able to set VAGRANT_LOG and get debug
output from the settings. This is mainly to verify that proxy is
actually getting down into Fog objects.
