diff --git a/Gemfile b/Gemfile index b44e960..3fe53b6 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,8 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' +gem 'hcloud', git: 'https://github.com/bastelfreak/hcloud-ruby', branch: 'dep' + gemspec group :coverage, optional: ENV['COVERAGE'] != 'yes' do diff --git a/beaker-hcloud.gemspec b/beaker-hcloud.gemspec index 45c3a3a..f45b52f 100644 --- a/beaker-hcloud.gemspec +++ b/beaker-hcloud.gemspec @@ -24,6 +24,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'bcrypt_pbkdf', '~> 1.0' s.add_runtime_dependency 'beaker', '~> 5.4' s.add_runtime_dependency 'ed25519', '~> 1.2' - s.add_runtime_dependency 'hcloud', '~> 1.1' + s.add_runtime_dependency 'hcloud', '~> 1.2' s.add_runtime_dependency 'ssh_data', '~> 1.3' end diff --git a/lib/beaker/hypervisor/hcloud.rb b/lib/beaker/hypervisor/hcloud.rb index 6b5832d..332d979 100644 --- a/lib/beaker/hypervisor/hcloud.rb +++ b/lib/beaker/hypervisor/hcloud.rb @@ -81,11 +81,23 @@ 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 = @client.servers.create( + server = create_hcloud_server( + @client, name: host.hostname, location: location, server_type: server_type, @@ -93,13 +105,8 @@ def create_server(host) 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'] + 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 host.options[:ssh][:keys] = [@key_file.path] server diff --git a/spec/beaker/hypervisor/hcloud_spec.rb b/spec/beaker/hypervisor/hcloud_spec.rb index ac3b86a..de56470 100644 --- a/spec/beaker/hypervisor/hcloud_spec.rb +++ b/spec/beaker/hypervisor/hcloud_spec.rb @@ -42,7 +42,12 @@ public_net: { 'ipv4' => { 'ip' => '192.168.0.1', - 'dns_ptr' => 'server1.example.com', + 'dns_ptr' => [ + { + 'ip' => '192.168.0.1', + 'dns_ptr' => 'server1.example.com', + }, + ], }, }, destroy: true, @@ -54,7 +59,12 @@ public_net: { 'ipv4' => { 'ip' => '192.168.0.2', - 'dns_ptr' => 'server2.example.com', + 'dns_ptr' => [ + { + 'ip' => '192.168.0.2', + 'dns_ptr' => 'server2.example.com', + }, + ], }, }, destroy: true,