Class: Beaker::Hcloud

Inherits:
Hypervisor
  • Object
show all
Defined in:
lib/beaker/hypervisor/hcloud.rb

Overview

beaker extension to manage cloud instances from www.hetzner.com/cloud

Instance Method Summary collapse

Constructor Details

#initialize(hosts, options) ⇒ Hcloud

Returns a new instance of Hcloud.

Parameters:

  • hosts (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.

  • options (Hash{Symbol=>String})

    Options to pass on to the hypervisor



14
15
16
17
18
19
20
21
22
# File 'lib/beaker/hypervisor/hcloud.rb', line 14

def initialize(hosts, options) # rubocop:disable Lint/MissingSuper
  @options = options
  @logger = options[:logger] || Beaker::Logger.new
  @hosts = hosts

  raise 'You need to pass a token as BEAKER_HCLOUD_TOKEN environment variable' unless ENV['BEAKER_HCLOUD_TOKEN']

  @client = ::Hcloud::Client.new(token: ENV.fetch('BEAKER_HCLOUD_TOKEN'))
end

Instance Method Details

#cleanupObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/beaker/hypervisor/hcloud.rb', line 33

def cleanup
  @logger.notify 'Cleaning up hcloud'
  @hosts.each do |host|
    @logger.debug("Deleting hcloud server #{host.name}")
    @client.servers.find(host[:hcloud_id]).destroy
  end
  @logger.notify 'Deleting hcloud SSH key'
  @client.ssh_keys.find(@options[:ssh][:hcloud_id]).destroy
  File.unlink(@key_file.path)
  @logger.notify 'Done cleaning up hcloud'
end

#provisionObject



24
25
26
27
28
29
30
31
# File 'lib/beaker/hypervisor/hcloud.rb', line 24

def provision
  @logger.notify 'Provisioning hcloud'
  create_ssh_key
  @hosts.each do |host|
    create_server(host)
  end
  @logger.notify 'Done provisioning hcloud'
end