Sha256: ecbe01e5906d1145258719e70117807606f7e3f0651a1cf159107227d41bf00f

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

require "fog"
require "log4r"

module VagrantPlugins
  module Rackspace
    module Action
      # This action connects to Rackspace, verifies credentials work, and
      # puts the Rackspace connection object into the `:rackspace_compute` key
      # in the environment.
      class ConnectRackspace
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_rackspace::action::connect_rackspace")
        end

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

          params = {
            :provider => :rackspace,
            :version  => :v2,
            :rackspace_api_key => api_key,
            :rackspace_username => username,
            :rackspace_auth_url => config.rackspace_auth_url
          }

          if config.rackspace_compute_url
            @logger.info("Connecting to Rackspace compute_url...")
            params[:rackspace_compute_url] = config.rackspace_compute_url
          else
            @logger.info("Connecting to Rackspace region...")
            params[:rackspace_region] = config.rackspace_region
          end

          env[:rackspace_compute] = Fog::Compute.new params

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-rackspace-0.1.10 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.9 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.8 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.7 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.6 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.5 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.4 lib/vagrant-rackspace/action/connect_rackspace.rb
vagrant-rackspace-0.1.3 lib/vagrant-rackspace/action/connect_rackspace.rb