Class: Beaker::Hypervisor

Inherits:
Object
  • Object
show all
Includes:
HostPrebuiltSteps
Defined in:
lib/beaker/hypervisor.rb

Overview

The Beaker class that interacts to all the supported hypervisors

Constant Summary collapse

CHARMAP =

Generates an array with all letters a thru z and numbers 0 thru 9

('a'..'z').to_a + ('0'..'9').to_a

Constants included from HostPrebuiltSteps

Beaker::HostPrebuiltSteps::APT_CFG, Beaker::HostPrebuiltSteps::ETC_HOSTS_PATH, Beaker::HostPrebuiltSteps::ETC_HOSTS_PATH_SOLARIS, Beaker::HostPrebuiltSteps::IPS_PKG_REPO, Beaker::HostPrebuiltSteps::NTPSERVER, Beaker::HostPrebuiltSteps::ROOT_KEYS_SCRIPT, Beaker::HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD, Beaker::HostPrebuiltSteps::SLEEPWAIT, Beaker::HostPrebuiltSteps::SLES_PACKAGES, Beaker::HostPrebuiltSteps::TRIES, Beaker::HostPrebuiltSteps::UNIX_PACKAGES, Beaker::HostPrebuiltSteps::WINDOWS_PACKAGES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HostPrebuiltSteps

#add_el_extras, #apt_get_update, #copy_file_to_remote, #copy_ssh_to_root, #disable_iptables, #disable_se_linux, #enable_root_login, #epel_info_for!, #get_domain_name, #get_ip, #hack_etc_hosts, #package_proxy, #proxy_config, #set_etc_hosts, #sync_root_keys, #timesync, #validate_host

Constructor Details

#initialize(hosts, options) ⇒ Hypervisor

Returns a new instance of Hypervisor.



65
66
67
68
# File 'lib/beaker/hypervisor.rb', line 65

def initialize(hosts, options)
  @hosts = hosts
  @options = options
end

Class Method Details

.create(type, hosts_to_provision, options) ⇒ Object

Hypervisor creator method. Creates the appropriate hypervisor class object based upon the provided hypervisor type selected, then provisions hosts with hypervisor.

Parameters:

  • type (String)

    The type of hypervisor to create - one of aix, solaris, vsphere, fusion, blimpy, vcloud or vagrant

  • hosts_to_provision (Array<Host>)

    The hosts to be provisioned with the selected hypervisor

  • options (Hash)

    options Options to alter execution



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/beaker/hypervisor.rb', line 19

def self.create(type, hosts_to_provision, options)
  @logger = options[:logger]
  @logger.notify("Beaker::Hypervisor, found some #{type} boxes to create")
  hyper_class = case type
    when /aix/
      Beaker::Aixer
    when /solaris/
      Beaker::Solaris
    when /vsphere/
      Beaker::Vsphere
    when /fusion/
      Beaker::Fusion
    when /blimpy/
      Beaker::Blimper
    when /ec2/
      Beaker::AwsSdk
    when /vcloud/
      if options['pooling_api']
        Beaker::VcloudPooled
      else
        Beaker::Vcloud
      end
    when /vagrant/
      Beaker::Vagrant
    when /google/
      Beaker::GoogleCompute
    when /docker/
      Beaker::Docker
    when /none/
      Beaker::Hypervisor
    else
      # Custom hypervisor
      begin
        require "beaker/hypervisor/#{type}"
      rescue LoadError
        raise "Invalid hypervisor: #{type}"
      end
      const_get("Beaker::#{type.capitalize}")
    end

  hypervisor = hyper_class.new(hosts_to_provision, options)
  hypervisor.provision

  hypervisor
end

Instance Method Details

#cleanupObject

Cleanup steps to be run for a given hypervisor. Default is nil.



76
77
78
# File 'lib/beaker/hypervisor.rb', line 76

def cleanup
  nil
end

#configureObject

Default configuration steps to be run for a given hypervisor



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/beaker/hypervisor.rb', line 81

def configure
  if @options[:timesync]
    timesync(@hosts, @options)
  end
  if @options[:root_keys]
    sync_root_keys(@hosts, @options)
  end
  if @options[:add_el_extras]
    add_el_extras(@hosts, @options)
  end
  if @options[:package_proxy]
    package_proxy(@hosts, @options)
  end
end

#generate_host_nameObject

Generate a random string composted of letter and numbers



104
105
106
# File 'lib/beaker/hypervisor.rb', line 104

def generate_host_name
  CHARMAP[rand(25)] + (0...14).map{CHARMAP[rand(CHARMAP.length)]}.join
end

#provisionObject

Provisioning steps for be run for a given hypervisor. Default is nil.



71
72
73
# File 'lib/beaker/hypervisor.rb', line 71

def provision
  nil
end

#validateObject

Default validation steps to be run for a given hypervisor



97
98
99
100
101
# File 'lib/beaker/hypervisor.rb', line 97

def validate
  if @options[:validate]
    validate_host(@hosts, @options)
  end
end