Class: VagrantPlugins::Vultr::Action::SetupSSHKey
- Inherits:
-
Object
- Object
- VagrantPlugins::Vultr::Action::SetupSSHKey
- Includes:
- Helpers::Client
- Defined in:
- lib/vagrant-vultr/action/setup_ssh_key.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ SetupSSHKey
constructor
A new instance of SetupSSHKey.
Methods included from Helpers::Client
Constructor Details
#initialize(app, env) ⇒ SetupSSHKey
Returns a new instance of SetupSSHKey.
9 10 11 12 13 14 15 |
# File 'lib/vagrant-vultr/action/setup_ssh_key.rb', line 9 def initialize(app, env) @app = app @machine = env[:machine] @name = @machine.provider_config.ssh_key @client = client @logger = Log4r::Logger.new('vagrant::vultr::setup_ssh_key') end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vagrant-vultr/action/setup_ssh_key.rb', line 17 def call(env) ssh_key_id = @client.ssh_key_id(@name) unless ssh_key_id @logger.info 'SSH key does not exist. Creating new one...' key_path = File.("#{@machine.config.ssh.private_key_path.first}.pub") ssh_key_id = @client.create_ssh_key(@name, File.read(key_path)) end @logger.info "Using SSH key: #{ssh_key_id}." @app.call(env) end |