Class: Kitchen::Driver::Openstack

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

Overview

Openstack driver for Kitchen.

Constant Summary collapse

@@ip_pool_lock =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kitchen/driver/openstack.rb', line 57

def create(state)
  config[:server_name] ||= generate_name(instance.name)
  config[:disable_ssl_validation] and disable_ssl_validation
  server = create_server
  state[:server_id] = server.id
  info "OpenStack instance <#{state[:server_id]}> created."
  server.wait_for { print '.'; ready? } ; info "\n(server ready)"
  if config[:floating_ip_pool]
    attach_ip_from_pool(server, config[:floating_ip_pool])
  elsif config[:floating_ip]
    attach_ip(server, config[:floating_ip])
  end
  state[:hostname] = get_ip(server)
  state[:ssh_key] = config[:private_key_path]
  wait_for_sshd(state[:hostname], config[:username],
    { :port => config[:port] }) ; info '(ssh ready)'
  if config[:key_name]
    info "Using OpenStack keypair <#{config[:key_name]}>"
  end
  info "Using public SSH key <#{config[:public_key_path]}>"
  info "Using private SSH key <#{config[:private_key_path]}>"
  unless config[:key_name]
    do_ssh_setup(state, config, server)
  end
rescue Fog::Errors::Error, Excon::Errors::Error => ex
  raise ActionFailed, ex.message
end

#destroy(state) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/kitchen/driver/openstack.rb', line 85

def destroy(state)
  return if state[:server_id].nil?

  config[:disable_ssl_validation] and disable_ssl_validation
  server = compute.servers.get(state[:server_id])
  server.destroy unless server.nil?
  info "OpenStack instance <#{state[:server_id]}> destroyed."
  state.delete(:server_id)
  state.delete(:hostname)
end