lib/kitchen/driver/vz.rb in kitchen-vz-0.1.1 vs lib/kitchen/driver/vz.rb in kitchen-vz-0.1.2

- old
+ new

@@ -41,10 +41,11 @@ default_config :ct_hostname do |driver| driver.instance.name end def create(state) + return if state[:ct_id] state[:ct_id] = SecureRandom.uuid generate_keys state[:ssh_key] = config[:ssh_key] = config[:private_key] create_ct(state) set_ct_network(state) @@ -73,11 +74,11 @@ end def generate_keys if !File.exist?(config[:public_key]) || !File.exist?(config[:private_key]) private_key = OpenSSL::PKey::RSA.new(2048) - blobbed_key = Base64.encode64(private_key.to_blob) + blobbed_key = Base64.encode64(private_key.to_blob).gsub("\n", '') public_key = "ssh-rsa #{blobbed_key} kitchen_key" File.open(config[:private_key], 'w') do |file| file.write(private_key) file.chmod(0600) end @@ -133,18 +134,19 @@ "chmod 700 /home/#{config[:username]}/.ssh", "echo '#{File.open(config[:public_key]).read}' > /home/#{config[:username]}/.ssh/authorized_keys", "chown #{config[:username]}: /home/#{config[:username]}/.ssh/authorized_keys", "chmod 600 /home/#{config[:username]}/.ssh/authorized_keys", 'mkdir -p /etc/sudoers.d', + "echo '#includedir /etc/sudoers.d' >> /etc/sudoers", "echo '#{config[:username]} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/#{config[:username]}", "chmod 0440 /etc/sudoers.d/#{config[:username]}"].each do |command| execute_command("#{prlctl} exec #{state[:ct_id]} \"#{command}\"") end end def ct_ip(state) ip = nil - 1..10.times do + 1..30.times do output = execute_command("#{vzctl} exec #{state[:ct_id]} \"/sbin/ip -o -f inet addr show dev eth0\"") result = %r{(([0-9]{1,3}\.){3}[0-9]{1,3})\/[0-9]{1,2}}.match(output) ip = result[1] if result break if ip sleep(1)