lib/kitchen/driver/lxd_cli.rb in kitchen-lxd_cli-2.0.1 vs lib/kitchen/driver/lxd_cli.rb in kitchen-lxd_cli-2.0.2
- old
+ new
@@ -35,11 +35,11 @@
File.expand_path('~/.ssh/id_rsa.pub'),
File.expand_path('~/.ssh/id_dsa.pub'),
File.expand_path('~/.ssh/identity.pub'),
File.expand_path('~/.ssh/id_ecdsa.pub')
].find { |path| File.exist?(path) }
-
+
raise 'Public key could not be found in the public_key_path provided. Please update the kitchen-lxd_cli config public_key_path in kitchen yaml or create a ssh key pair (e.g. `ssh-keygen -t rsa`)' unless pub_key
pub_key
end
default_config :never_destroy, false
@@ -68,11 +68,11 @@
state[:hostname] = lxc_ip
state[:username] = config[:username]
setup_ssh_access
wait_for_ssh_login(lxc_ip) if config[:enable_wait_for_ssh_login] == "true"
IO.popen("lxc exec #{@@instance_name} bash", "r+") do |p|
- p.puts("if [ ! -d '#{config[:verifier_path]}' ]; then mkdir -p #{config[:verifier_path]}; fi")
+ p.puts("if [ ! -d '#{config[:verifier_path]}' ]; then mkdir -p #{config[:verifier_path]}; fi")
p.puts("if [ ! -L '/tmp/verifier' ]; then ln -s #{config[:verifier_path]} /tmp/verifier; fi")
end if config[:verifier_path] && config[:verifier_path].length > 0
end
def destroy(state)
@@ -132,13 +132,13 @@
image_name = get_image_name
unless image_exists?(image_name)
info("Creating image #{image_name} now.")
image = get_image_info
- image_os = config[:image_os]
+ image_os = config[:image_os]
image_os ||= image[:os]
- image_release = config[:image_release]
+ image_release = config[:image_release]
image_release ||= image[:release_num]
debug("Ran command: lxc image copy #{image_os}:#{image_release} local: --alias #{image_name}")
IO.popen("lxc image copy #{image_os}:#{image_release} local: --alias #{image_name}", "w") { |pipe| puts pipe.gets rescue nil }
end
@@ -183,11 +183,11 @@
end
def get_image_name
image_name = get_publish_image_name
unless config[:use_publish_image] == true && image_exists?(image_name)
- image_name = config[:image_name]
+ image_name = config[:image_name]
image_name ||= instance.platform.name
end
debug("Image Name is #{image_name}")
return image_name
@@ -209,21 +209,26 @@
else
debug("Image #{image_name} does not exist")
return false
end
end
-
+0
def config_and_start_container
+ platform, release = instance.platform.name.split('-')
config[:ip_gateway] ||= "auto"
arg_disable_dhcp = ""
if config[:ipv4]
IO.popen("bash", "r+") do |p|
p.puts("echo -e \"lxc.network.0.ipv4 = #{config[:ipv4]}\nlxc.network.0.ipv4.gateway = #{config[:ip_gateway]}\n\" | lxc config set #{@@instance_name} raw.lxc -")
p.puts("exit")
end
- arg_disable_dhcp = "&& lxc exec #{@@instance_name} -- sed -i 's/dhcp/manual/g' /etc/network/interfaces.d/eth0.cfg"
+ if platform.downcase == "ubuntu"
+ arg_disable_dhcp = "&& lxc exec #{@@instance_name} -- sed -i 's/dhcp/manual/g' /etc/network/interfaces.d/eth0.cfg"
+ elsif platform.downcase == "centos"
+ arg_disable_dhcp = "&& lxc exec #{@@instance_name} -- sed -i 's/dhcp/none/g' /etc/sysconfig/network-scripts/ifcfg-eth0"
+ end
end
info("Starting container #{@@instance_name}")
run_lxc_command("start #{@@instance_name} #{arg_disable_dhcp}")
setup_mount_bindings if config[:mount].class == Hash
@@ -441,10 +446,10 @@
def debug_note_about_configuring_ip
debug("NOTE: Restarting seemed to be the only way I could get things to work. Tried lxc profiles, config options. Tried restart networking service but it didn't work, also tried passing command like ifconfig 10.0.3.x/24 eth0 up. Which set the ip but after container ran for a while, it would reset to dhcp address that had been assigned. Restarting container seems to be working, and is really fast. Open to better alternatives.")
end
-
+
=begin
def configure_ip_via_lxc_restart
debug("Configuring new ip address on eth0")
IO.popen("lxc exec #{@@instance_name} bash", "r+") do |p|