Class: VagrantPlugins::Cloudstack::Action::ConnectCloudstack

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-cloudstack/action/connect_cloudstack.rb

Overview

This action connects to Cloudstack, verifies credentials work, and puts the Cloudstack connection object into the ‘:cloudstack_compute` key in the environment.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ConnectCloudstack

Returns a new instance of ConnectCloudstack.



11
12
13
14
# File 'lib/vagrant-cloudstack/action/connect_cloudstack.rb', line 11

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new('vagrant_cloudstack::action::connect_cloudstack')
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant-cloudstack/action/connect_cloudstack.rb', line 16

def call(env)
  # Get the domain we're going to booting up in
  domain        = env[:machine].provider_config.domain_id

  # Get the configs
  domain_config = env[:machine].provider_config.get_domain_config(domain)

  # Build the fog config
  fog_config    = {
      :provider => :cloudstack
      #:domain        => domain_config
  }

  if domain_config.api_key
    fog_config[:cloudstack_api_key]           = domain_config.api_key
    fog_config[:cloudstack_secret_access_key] = domain_config.secret_key
  end

  fog_config[:cloudstack_host]   = domain_config.host if domain_config.host
  fog_config[:cloudstack_path]   = domain_config.path if domain_config.path
  fog_config[:cloudstack_port]   = domain_config.port if domain_config.port
  fog_config[:cloudstack_scheme] = domain_config.scheme if domain_config.scheme

  @logger.info('Connecting to Cloudstack...')
  env[:cloudstack_compute] = Fog::Compute.new(fog_config)

  @app.call(env)
end