Class: Kitchen::Driver::Openstack

Inherits:
Base
  • Object
show all
Includes:
Clouds, Config, Helpers, Networking, ServerHelper
Defined in:
lib/kitchen/driver/openstack.rb,
lib/kitchen/driver/openstack/clouds.rb,
lib/kitchen/driver/openstack/config.rb,
lib/kitchen/driver/openstack/volume.rb,
lib/kitchen/driver/openstack/helpers.rb,
lib/kitchen/driver/openstack/networking.rb,
lib/kitchen/driver/openstack/server_helper.rb

Overview

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

Defined Under Namespace

Modules: Clouds, Config, Helpers, Networking, ServerHelper Classes: Volume

Constant Summary collapse

FOG_STRING_SETTINGS =
%i{
  openstack_username
  openstack_api_key
  openstack_auth_url
  openstack_project_name
  openstack_project_id
  openstack_user_domain
  openstack_user_domain_id
  openstack_project_domain
  openstack_project_domain_id
  openstack_domain_id
  openstack_domain_name
  openstack_region
  openstack_endpoint_type
  openstack_identity_api_version
  openstack_application_credential_id
  openstack_application_credential_secret
  openstack_tenant
  openstack_tenant_id
}.freeze

Constants included from Networking

Networking::IP_POOL_LOCK

Constants included from Clouds

Clouds::CLOUDS_YAML_AUTH_MAP, Clouds::CLOUDS_YAML_TOP_MAP, Clouds::ENV_VAR_MAP, Clouds::STRING_CONFIG_KEYS

Instance Method Summary collapse

Methods included from Config

#config_server_name

Instance Method Details

#create(state) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/kitchen/driver/openstack.rb', line 106

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

  # this is due to the glance_caching issues. Annoying yes, but necessary.
  debug "Waiting for a max time of:#{config[:glance_cache_wait_timeout]} seconds for OpenStack server to be in ACTIVE state"
  server.wait_for(config[:glance_cache_wait_timeout]) do
    sleep(1)
    if failed?
      raise(Kitchen::InstanceFailure,
        "OpenStack server ID <#{state[:server_id]}> build failed to ERROR state")
    end

    ready?
  end
  info "OpenStack server ID <#{state[:server_id]}> created"

  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)
  add_ohai_hint(state)
rescue Fog::Errors::Error, Excon::Errors::Error => e
  raise ActionFailed, e.message
end

#destroy(state) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/kitchen/driver/openstack.rb', line 141

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

  disable_ssl_validation if config[:disable_ssl_validation]
  server = compute.servers.get(state[:server_id])

  unless server.nil?
    if config[:floating_ip_pool] && config[:allocate_floating_ip]
      info "Retrieve the floating IP"
      pub, priv = get_public_private_ips(server)
      pub, = parse_ips(pub, priv)
      pub_ip = pub[config[:public_ip_order].to_i] || nil
      if pub_ip
        info "Retrieve the ID of floating IP <#{pub_ip}>"
        floating_ip_id = network.list_floating_ips(floating_ip_address: pub_ip).body["floatingips"][0]["id"]
        network.delete_floating_ip(floating_ip_id)
        info "OpenStack Floating IP <#{pub_ip}> released."
      end
    end
    server.destroy
  end
  info "OpenStack instance <#{state[:server_id]}> destroyed."
  state.delete(:server_id)
  state.delete(:hostname)
end

#finalize_config!(instance) ⇒ Object

Merge clouds.yaml values into config so they are visible in ‘kitchen diagnose` and available to all driver methods.



75
76
77
78
79
# File 'lib/kitchen/driver/openstack.rb', line 75

def finalize_config!(instance)
  super
  apply_clouds_config
  self
end