Class: VagrantPlugins::SimpleCloud::Actions::SetupKey

Inherits:
Object
  • Object
show all
Includes:
Helpers::Client
Defined in:
lib/vagrant-simplecloud/actions/setup_key.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#simple_client

Constructor Details

#initialize(app, env) ⇒ SetupKey

Returns a new instance of SetupKey.



9
10
11
12
13
14
# File 'lib/vagrant-simplecloud/actions/setup_key.rb', line 9

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @simple_client = simple_client
  @logger = Log4r::Logger.new('vagrant::simplecloud::setup_key')
end

Instance Method Details

#call(env) ⇒ Object

TODO check the content of the key to see if it has changed



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-simplecloud/actions/setup_key.rb', line 17

def call(env)
    ssh_key_name = @machine.provider_config.ssh_key_name
    # assigns existing ssh key id to env for use by other commands
    res = @simple_client.request('/v2/account/keys')
    key_data = res.fetch('ssh_keys').select {|a| a['name'] == ssh_key_name}.first
    if key_data.nil?
        env[:ssh_key_id] = create_ssh_key(ssh_key_name, env)
    else
        env[:ssh_key_id] = key_data['id']
    end
    env[:ui].info I18n.t('vagrant_simple_cloud.info.using_key', {:name => ssh_key_name})
    @app.call(env)
end