Class: Kitchen::Driver::Lxc

Inherits:
SSHBase
  • Object
show all
Defined in:
lib/kitchen/driver/lxc.rb

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kitchen/driver/lxc.rb', line 18

def create(state)
  name = instance.platform.name.gsub(/[_\-.]/, '')
  names = Dir.glob(instance.driver.config.fetch(:lxc_directory, '/var/lib/lxc/*')).map do |path|
    if(File.directory?(path))
      File.basename(path)
    end
  end.compact.sort
  config[:original] = names.detect{|n| n.gsub(/[_\-.]/, '').start_with?(name)}

  container = ::Lxc::Ephemeral.new(config.to_hash)
  container.create!

  state[:container_name] = container.name

  lxc = ::Lxc.new(state[:container_name])
  lxc.start

  state[:hostname] = lxc.container_ip(10, true)
  wait_for_sshd(state[:hostname])
end

#destroy(state) ⇒ Object



39
40
41
42
43
44
# File 'lib/kitchen/driver/lxc.rb', line 39

def destroy(state)
  if state[:container_name]
    lxc = ::Lxc.new(state[:container_name])
    lxc.stop
  end
end