Sha256: 0f70a951cc9455200b585fe80e85edc3efded65fef4040ede7a20d83921043b1

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

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

          @logger.info("Connecting to OpenStack...")
          env[:openstack_compute] = Fog::Compute.new({
            :provider => :openstack,
            :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,
              :openstack_username => username,
              :openstack_api_key => api_key,
              :openstack_auth_url => endpoint,
              :openstack_tenant => tenant
            })
          end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-openstack-plugin-0.3.0 lib/vagrant-openstack-plugin/action/connect_openstack.rb