diff --git a/lib/beaker/hypervisor/hcloud.rb b/lib/beaker/hypervisor/hcloud.rb index 6843549..10f9d8e 100644 --- a/lib/beaker/hypervisor/hcloud.rb +++ b/lib/beaker/hypervisor/hcloud.rb @@ -81,23 +81,32 @@ def vm_deletion_date date end + def create_hcloud_server(client, **kwargs) + action, server, _password, _next_action = client.servers.create(**kwargs) + + while action.status == 'running' + sleep 5 + action = client.actions.find(action.id) + end + + server + end + def create_server(host) @logger.notify "provisioning #{host.name}" location = host[:location] || 'nbg1' server_type = host[:server_type] || 'cx11' - action, server, _password, _next_action = @client.servers.create( - name: host.hostname, - location: location, - server_type: server_type, - image: host[:image], - ssh_keys: [ssh_key_name], - labels: { delete_vm_after: vm_deletion_date }, + server = create_hcloud_server( + @client, + **{ + name: host.hostname, + location: location, + server_type: server_type, + image: host[:image], + ssh_keys: [ssh_key_name], + labels: { delete_vm_after: vm_deletion_date }, + }, ) - while action.status == 'running' - sleep 5 - action = @client.actions.find(action.id) - server = @client.servers.find(server.id) - end host[:ip] = server.public_net['ipv4'].ip host[:vmhostname] = server.public_net['ipv4'].dns_ptr.find { |hash| hash['ip'] == host[:ip] }['dns_ptr'] host[:hcloud_id] = server.id