Class: Kraaken::Cloud::Hetzner

Inherits:
Kraaken::Cloud show all
Defined in:
lib/kraaken/cloud/hetzner.rb

Instance Method Summary collapse

Methods inherited from Kraaken::Cloud

#initialize, #prepare

Constructor Details

This class inherits a constructor from Kraaken::Cloud

Instance Method Details

#provision(name, groups:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kraaken/cloud/hetzner.rb', line 6

def provision(name, groups:)
  logger.with_progress(total: 100) do
    logger.info "Provisioning server #{name}"
    keys = client.ssh_keys
    user_data = config.load_template("cloud-config.yml", keys:)
    options = {
      name:,
      server_type: "cax41",
      image: "ubuntu-22.04",
      labels: {group: groups.join(".")},
      location: "nbg1",
      networks: [client.networks.first.id],
      ssh_keys: keys.map(&:id),
      user_data:
    }
    logger.increment_progress by: 5
    logger.info "Creating server"
    action, server = client.servers.create(**options)
    await_action action
    logger.increment_progress by: 10
    server = await_startup server
    logger.info "Server started #{server.public_net.dig("ipv4", "ip")}"
    logger.increment_progress by: 10
    logger.info "Regenrating ssh config"
    config.ssh.regenerate_config
    logger.increment_progress by: 5
    sleep 10
    logger.increment_progress by: 10
    logger.info "Rebooting server after applying cloud-config"
    await_action server.reboot
    logger.increment_progress by: 10
    prepare name
  end
end

#serversObject



41
42
43
# File 'lib/kraaken/cloud/hetzner.rb', line 41

def servers
  client.servers.map { Kraaken::Cloud::Server.new(name: _1.name, ip: _1.private_net.first&.ip, public_ip: _1.public_net.dig("ipv4", "ip"), status: _1.status) }
end