Class: VagrantPlugins::SoftLayer::Action::SetupSoftLayer

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-softlayer/action/setup_softlayer.rb

Overview

This action creates the SoftLayer service objects and puts them into keys in the environment. Also, if a machine id is found, another key called ‘:sl_machine` and containing the masked object is created.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetupSoftLayer

Returns a new instance of SetupSoftLayer.



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

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_softlayer::action::connect_softlayer")
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
# File 'lib/vagrant-softlayer/action/setup_softlayer.rb', line 16

def call(env)
  @logger.info("Creating the SoftLayer service objects...")

  env[:sl_credentials] = {
    :api_key      => env[:machine].provider_config.api_key,
    :endpoint_url => env[:machine].provider_config.endpoint_url,
    :username     => env[:machine].provider_config.username
  }

  env[:sl_account]       = ::SoftLayer::Service.new("SoftLayer_Account",       env[:sl_credentials])
  env[:sl_product_order] = ::SoftLayer::Service.new("SoftLayer_Product_Order", env[:sl_credentials])
  env[:sl_virtual_guest] = ::SoftLayer::Service.new("SoftLayer_Virtual_Guest", env[:sl_credentials])

  unless env[:machine].id.nil? || env[:machine].id.empty?
    env[:sl_machine] = env[:sl_virtual_guest].object_with_id(env[:machine].id.to_i)
  end

  # Carry on
  @app.call(env)
end