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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/kitchen/driver/lxd_cli.rb', line 53

def create(state)
  @@instance_name = get_or_create_unique_instance_name
  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
    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
  state[:username] = config[:username]
  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



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/kitchen/driver/lxd_cli.rb', line 78

def destroy(state)
  @@instance_name = get_or_create_unique_instance_name
  if exists?
    if running?
      info("Stopping container #{@@instance_name}")
      run_lxc_command("stop #{@@instance_name} --force")
    end

    publish_image if config[:publish_image_before_destroy]

    unless config[:never_destroy] && config[:never_destroy] == true
      info("Deleting container #{@@instance_name}")
      run_lxc_command("delete #{@@instance_name} --force")
      File.delete(".kitchen/#{instance.name}.lxd_unique_name") if File.exist?(".kitchen/#{instance.name}.lxd_unique_name")
    end
  end
  state.delete(:hostname)
  destroy_proxy if config[:lxd_proxy_destroy] && config[:lxd_proxy_destroy] == true
end