Class: Beaker::Abs

Inherits:
Hypervisor
  • Object
show all
Defined in:
lib/beaker/hypervisor/abs.rb

Instance Method Summary collapse

Constructor Details

#initialize(hosts, options) ⇒ Abs

Returns a new instance of Abs.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/beaker/hypervisor/abs.rb', line 6

def initialize(hosts, options)
  @options = options
  @logger = options[:logger]
  @hosts = hosts

  resource_hosts = ENV['ABS_RESOURCE_HOSTS'] || @options[:abs_resource_hosts]
  raise ArgumentError.new("ABS_RESOURCE_HOSTS must be specified when using the Beaker::Abs hypervisor") if resource_hosts.nil?
  @resource_hosts = JSON.parse(resource_hosts)
end

Instance Method Details

#cleanupObject



45
46
47
# File 'lib/beaker/hypervisor/abs.rb', line 45

def cleanup
  # nothing to do
end

#provisionObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/beaker/hypervisor/abs.rb', line 16

def provision
  type2hosts = {}

  # Each resource_host is of the form:
  # {
  #   "hostname" => "1234567890",
  #   "type"     => "centos-7-i386",
  #   "engine"   => "vmpooler",
  # }
  @resource_hosts.each do |resource_host|
    type = resource_host['type']
    type2hosts[type] ||= []
    type2hosts[type] << resource_host['hostname']
  end

  # for each host, get a vm for that template type
  @hosts.each do |host|
    template = host['template']

    raise ArgumentError.new("Failed to provision host '#{host.hostname}' because its 'template' is missing.") if template.nil?

    if provisioned_hosts = type2hosts[template]
      host['vmhostname'] = provisioned_hosts.shift
    else
      raise ArgumentError.new("Failed to provision host '#{host.hostname}', no template of type '#{host['template']}' was provided.")
    end
  end
end