Class: Kitchen::Driver::Openstack

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/openstack.rb,
lib/kitchen/driver/openstack/volume.rb

Overview

This takes from the Base Class and creates the OpenStack driver.

Defined Under Namespace

Classes: Volume

Constant Summary collapse

@@ip_pool_lock =

rubocop:disable Metrics/ClassLength, Metrics/LineLength

Mutex.new

Instance Method Summary collapse

Instance Method Details

#config_server_nameObject

Set the proper server name in the config



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kitchen/driver/openstack.rb', line 78

def config_server_name
  return if config[:server_name]

  if config[:server_name_prefix]
    config[:server_name] = server_name_prefix(
      config[:server_name_prefix]
    )
  else
    config[:server_name] = default_name
  end
end

#create(state) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/kitchen/driver/openstack.rb', line 90

def create(state)
  config_server_name
  if state[:server_id]
    info "#{config[:server_name]} (#{state[:server_id]}) already exists."
    return
  end
  disable_ssl_validation if config[:disable_ssl_validation]
  server = create_server
  state[:server_id] = server.id
  info "OpenStack instance with ID of <#{state[:server_id]}> is ready." # rubocop:disable Metrics/LineLength

  # this is due to the glance_caching issues. Annoying yes, but necessary.
  debug "Waiting for VM to be in ACTIVE state for a max time of:#{config[:glance_cache_wait_timeout]} seconds" # rubocop:disable Metrics/LineLength
  server.wait_for(config[:glance_cache_wait_timeout]) do
    sleep(1)
    ready?
  end

  if config[:floating_ip]
    attach_ip(server, config[:floating_ip])
  elsif config[:floating_ip_pool]
    attach_ip_from_pool(server, config[:floating_ip_pool])
  end
  state[:hostname] = get_ip(server)
  wait_for_server(state)
  setup_ssh(server, state) if bourne_shell?
  add_ohai_hint(state)
rescue Fog::Errors::Error, Excon::Errors::Error => ex
  raise ActionFailed, ex.message
end

#destroy(state) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/kitchen/driver/openstack.rb', line 121

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

  disable_ssl_validation if config[: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