Module: BeakerHostGenerator::Hypervisor

Defined in:
lib/beaker-hostgenerator/hypervisor.rb,
lib/beaker-hostgenerator/hypervisor/abs.rb,
lib/beaker-hostgenerator/hypervisor/docker.rb,
lib/beaker-hostgenerator/hypervisor/unknown.rb,
lib/beaker-hostgenerator/hypervisor/vagrant.rb,
lib/beaker-hostgenerator/hypervisor/vmpooler.rb

Overview

Defines an Interface for the implementation of a hypervisor, and provides a static module function ‘create(node_info, options)` for instantiating the appropriate hypervisor implementation.

New hypervisor implementations must define the methods in the Interface class, and add a new element to the ‘builtin_hypervisors` map.

Any number of hypervisors are used by a single Generator during host generation in the ‘BeakerHostGenerator::Generator#generate` method. Whenever a host specifies a specific hypervisor implementation, the Generator will instantiate the appropriate hypervisor via `BeakerHostGenerator::Hypervisor.create`.

Defined Under Namespace

Classes: ABS, Docker, Interface, Unknown, Vagrant, Vmpooler

Class Method Summary collapse

Class Method Details

.builtin_hypervisorsObject

Returns a map of all built-in hypervisor implementations, where the keys are the string names and the values are the implementation classes.

The string names are part of the beaker-hostgenerator API as they are used for specifying the default or per-host hypervisor in the layout specification input string.



42
43
44
45
46
47
48
49
50
# File 'lib/beaker-hostgenerator/hypervisor.rb', line 42

def self.builtin_hypervisors()
  {
    'vmpooler' => BeakerHostGenerator::Hypervisor::Vmpooler,
    'vagrant' => BeakerHostGenerator::Hypervisor::Vagrant,
    'vagrant_libvirt' => BeakerHostGenerator::Hypervisor::Vagrant,
    'docker' => BeakerHostGenerator::Hypervisor::Docker,
    'abs' => BeakerHostGenerator::Hypervisor::ABS
  }
end

.create(node_info, options) ⇒ Object

Static factory method to instantiate the appropriate hypervisor for the given node. If no hypervisor is specified in the node info, then the hypervisor specified in the options will be created. If the hypervisor is not a built-in implementation, then an ‘Unknown` instance will be used.

Parameters:

  • node_info (Hash{String=>Object})

    Node data parsed from the input spec string.

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :hypervisor (String)

    The string name of the hypervisor to create.



27
28
29
30
31
# File 'lib/beaker-hostgenerator/hypervisor.rb', line 27

def self.create(node_info, options)
  name = node_info['host_settings']['hypervisor'] || options[:hypervisor]
  hypervisor = builtin_hypervisors[name] || BeakerHostGenerator::Hypervisor::Unknown
  hypervisor.new(name)
end