Class: VagrantPlugins::HP::Action::ConnectHP

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-hp/action/connect_hp.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ConnectHP

Returns a new instance of ConnectHP.



16
17
18
19
# File 'lib/vagrant-hp/action/connect_hp.rb', line 16

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_hp::action::connect_hp")
end

Instance Method Details

#availability_zone(availability_zone) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-hp/action/connect_hp.rb', line 41

def availability_zone(availability_zone)
  case availability_zone
  when 'az3'
    return 'az-3.region-a.geo-1'
  when 'az2'
    return 'az-2.region-a.geo-1'
  else
    return 'az-1.region-a.geo-1'
  end
end

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-hp/action/connect_hp.rb', line 21

def call(env)
  # Get the configs
  config = env[:machine].provider_config
  access_key = config.access_key
  secret_key = config.secret_key
  tenant_id = config.tenant_id
  availability_zone = availability_zone(config.availability_zone)

  @logger.info("Connecting to HP...")
  env[:hp_compute] = Fog::Compute.new({
    :provider => :hp,
    :hp_access_key => access_key,
    :hp_secret_key => secret_key,
    :hp_tenant_id => tenant_id,
    :hp_avl_zone => availability_zone,
  })

  @app.call(env)
end