Method: Beaker::OpenStack#initialize

Defined in:
lib/beaker/hypervisor/openstack.rb

#initialize(openstack_hosts, options) ⇒ OpenStack

Create a new instance of the OpenStack hypervisor object

Parameters:

  • openstack_hosts (<Host>)

    The array of OpenStack hosts to provision

  • options (Hash{Symbol=>String})

    The options hash containing configuration values

Options Hash (options):

  • :openstack_api_key (String)

    The key to access the OpenStack instance with (required)

  • :openstack_username (String)

    The username to access the OpenStack instance with (required)

  • :openstack_auth_url (String)

    The URL to access the OpenStack instance with (required)

  • :openstack_tenant (String)

    The tenant to access the OpenStack instance with (required)

  • :openstack_region (String)

    The region that each OpenStack instance should be provisioned on (optional)

  • :openstack_network (String)

    The network that each OpenStack instance should be contacted through (required)

  • :openstack_keyname (String)

    The name of an existing key pair that should be auto-loaded onto each

  • :security_group (Hash)

    An array of security groups to associate with the instance OpenStack instance (optional)

  • :jenkins_build_url (String)

    Added as metadata to each OpenStack instance

  • :department (String)

    Added as metadata to each OpenStack instance

  • :project (String)

    Added as metadata to each OpenStack instance

  • :timeout (Integer)

    The amount of time to attempt execution before quiting and exiting with failure



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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/beaker/hypervisor/openstack.rb', line 25

def initialize(openstack_hosts, options)
  require 'fog'
  @options = options
  @logger = options[:logger]
  @hosts = openstack_hosts
  @vms = []

  raise 'You must specify an Openstack API key (:openstack_api_key) for OpenStack instances!' unless @options[:openstack_api_key]
  raise 'You must specify an Openstack username (:openstack_username) for OpenStack instances!' unless @options[:openstack_username]
  raise 'You must specify an Openstack auth URL (:openstack_auth_url) for OpenStack instances!' unless @options[:openstack_auth_url]
  raise 'You must specify an Openstack tenant (:openstack_tenant) for OpenStack instances!' unless @options[:openstack_tenant]
  raise 'You must specify an Openstack network (:openstack_network) for OpenStack instances!' unless @options[:openstack_network]

  optionhash = {}
  optionhash[:provider]           = :openstack
  optionhash[:openstack_api_key]  = @options[:openstack_api_key]
  optionhash[:openstack_username] = @options[:openstack_username]
  optionhash[:openstack_auth_url] = @options[:openstack_auth_url]
  optionhash[:openstack_tenant]   = @options[:openstack_tenant]
  optionhash[:openstack_region]   = @options[:openstack_region] if @options[:openstack_region]

  @compute_client ||= Fog::Compute.new(optionhash)

  if not @compute_client
    raise "Unable to create OpenStack Compute instance (api key: #{@options[:openstack_api_key]}, username: #{@options[:openstack_username]}, auth_url: #{@options[:openstack_auth_url]}, tenant: #{@options[:openstack_tenant]})"
  end

  networkoptionhash = {}
  networkoptionhash[:provider]           = :openstack
  networkoptionhash[:openstack_api_key]  = @options[:openstack_api_key]
  networkoptionhash[:openstack_username] = @options[:openstack_username]
  networkoptionhash[:openstack_auth_url] = @options[:openstack_auth_url]
  networkoptionhash[:openstack_tenant]   = @options[:openstack_tenant]
  networkoptionhash[:openstack_region]   = @options[:openstack_region] if @options[:openstack_region]

  @network_client ||= Fog::Network.new(networkoptionhash)

  if not @network_client
    raise "Unable to create OpenStack Network instance (api_key: #{@options[:openstack_api_key]}, username: #{@options[:openstack_username]}, auth_url: #{@options[:openstack_auth_url]}, tenant: #{@options[:openstack_tenant]})"
  end

end