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



74
75
76
# File 'lib/beaker/hypervisor/abs.rb', line 74

def cleanup
  # nothing to do
end

#connection_preference(host) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/beaker/hypervisor/abs.rb', line 16

def connection_preference(host)
  vmhostname = host[:vmhostname]
  if vmhostname && host[:hypervisor] == 'abs'
    @resource_hosts.each do |resource_host|
      if resource_host['hostname'] == vmhostname
        engine = resource_host['engine']
        case engine
        when /^(vmpooler|nspooler)$/
          # putting ip last as its not set by ABS
          return [:vmhostname, :hostname, :ip]
        else
          super
        end
      end
    end
  end
  super
end

#provisionObject



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
67
68
69
70
71
72
# File 'lib/beaker/hypervisor/abs.rb', line 35

def provision
  type2hosts = {}

  # Each resource_host is of the form:
  # {
  #   "hostname" => "mkbx0m6dnnntgz1.delivery.puppetlabs.net",
  #   "type"     => "centos-7-i386",
  #   "engine"   => "vmpooler",
  # }
  # {
  #   "hostname" => "sol10-1.delivery.puppetlabs.net",
  #   "type"     => "solaris-10-sparc",
  #   "engine"   => "nspooler",
  # }
  @resource_hosts.each do |resource_host|
    type = resource_host['type']
    type2hosts[type] ||= []
    type2hosts[type] << resource_host['hostname']
    type2hosts[type] << resource_host['ip']
  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
      host['ip'] = provisioned_hosts.shift
    else
      raise ArgumentError.new("Failed to provision host '#{host.hostname}', no template of type '#{host['template']}' was provided.")
    end
  end
  if Beaker::Hypervisor.respond_to?(:set_ssh_connection_preference)
    Beaker::Hypervisor.set_ssh_connection_preference(@hosts, self)
  end
end