Class: Kitchen::Driver::Gogetkitchen

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

Overview

Gogetkitchen driver for Kitchen.

Author:

Instance Method Summary collapse

Instance Method Details

#choose_provider(provider) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/kitchen/driver/gogetkitchen.rb', line 81

def choose_provider(provider)
  case provider
  when 'lxd'
    Gogetit.lxd
  when 'kvm'
    # let's call it kvm externally but libvirt internally
    # because gogetit actually handles libvirtd
    Gogetit.libvirt
  end
end

#create(state) ⇒ Object



40
41
42
43
44
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/gogetkitchen.rb', line 40

def create(state)
  provider = choose_provider(config[:provider])

  case provider
  when Gogetit::GogetLibvirt

    if Gogetit.maas.machine_exists?(instance.name)
      result = provider.deploy(instance.name, config)
    else
      result = provider.create(instance.name, config)
    end

  when Gogetit::GogetLXD
    result = provider.create(instance.name, config)
  end

  domain = Gogetit.maas.get_domain
  state[:hostname]      = instance.name + '.' + domain
  state[:username]      = result[:info][:default_user]
				info 'Waiting for the new domain to be available..'
  wait_until_available(instance.name)

				info 'Waiting for SSH..'
  conn = instance.transport.connection(state)
  conn.wait_until_ready
  conn.close
end

#destroy(state) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kitchen/driver/gogetkitchen.rb', line 68

def destroy(state)
  provider = choose_provider(config[:provider])

  case provider
  when Gogetit::GogetLibvirt
    provider.release(instance.name)
  when Gogetit::GogetLXD
    provider.destroy(instance.name)
  end

  instance.transport.connection(state).close
end

#wait_until_available(hostname) ⇒ Object



92
93
94
95
96
# File 'lib/kitchen/driver/gogetkitchen.rb', line 92

def wait_until_available(hostname)
  until Gogetit.maas.domain_name_exists?(hostname)
    sleep 3
  end
end