Class: Kitchen::Driver::LxdCli

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/lxd_cli.rb

Overview

LxdCli driver for Kitchen.

Author:

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/kitchen/driver/lxd_cli.rb', line 45

def create(state)
  install_proxy if config[:lxd_proxy_install] && config[:lxd_proxy_install] == true

  unless exists?
    image_name = create_image_if_missing
    profile_args = setup_profile_args if config[:profile]
    config_args = setup_config_args if config[:config]
    info("Initializing container #{instance.name}")
    run_lxc_command("init #{image_name} #{instance.name} #{profile_args} #{config_args}")
  end

  config_and_start_container unless running?
  configure_dns
  lxc_ip = wait_for_ip_address
  state[:hostname] = lxc_ip
  setup_ssh_access
  (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 [ ! -L '/tmp/verifier' ]; then ln -s #{config[:verifier_path]} /tmp/verifier; fi")
  end if config[:verifier_path] && config[:verifier_path].length > 0
end

#destroy(state) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kitchen/driver/lxd_cli.rb', line 68

def destroy(state)
  if exists?
    if running?
      info("Stopping container #{instance.name}")
      run_lxc_command("stop #{instance.name}")
    end
    
    publish_image if config[:publish_image_before_destroy]

    unless config[:never_destroy]
      info("Deleting container #{instance.name}")
      run_lxc_command("delete #{instance.name}") unless config[:never_destroy] && config[:never_destroy] == true
    end
  end
  state.delete(:hostname)
  destroy_proxy if config[:lxd_proxy_destroy] && config[:lxd_proxy_destroy] == true
end