Skip to content

Commit

Permalink
refactor create_server method for easier testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Nov 1, 2023
1 parent bbbbed6 commit 05cf004
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lib/beaker/hypervisor/hcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
**{

Check failure on line 101 in lib/beaker/hypervisor/hcloud.rb

View workflow job for this annotation

GitHub Actions / rubocop

Style/RedundantDoubleSplatHashBraces: Remove the redundant double splat and braces, use keyword arguments directly.
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
Expand Down

0 comments on commit 05cf004

Please sign in to comment.