Class: Beaker::NetworkManager
- Inherits:
-
Object
- Object
- Beaker::NetworkManager
- Defined in:
- lib/beaker/network_manager.rb
Overview
Object that holds all the provisioned and non-provisioned virtual machines. Controls provisioning, configuration, validation and cleanup of those virtual machines.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Shut down network connections and revert all provisioned virtual machines.
-
#configure ⇒ Object
Configure all provisioned machines, adding any packages or settings required for SUTs.
-
#initialize(options, logger) ⇒ NetworkManager
constructor
A new instance of NetworkManager.
-
#provision ⇒ Object
Provision all virtual machines.
-
#provision?(options, host) ⇒ Boolean
Determine if a given host should be provisioned.
-
#proxy_package_manager ⇒ Object
configure proxy on all provioned machines.
-
#validate ⇒ Object
Validate all provisioned machines, ensure that required packages are installed - if they are missing attempt to add them.
Constructor Details
#initialize(options, logger) ⇒ NetworkManager
Returns a new instance of NetworkManager.
22 23 24 25 26 27 28 |
# File 'lib/beaker/network_manager.rb', line 22 def initialize(, logger) @logger = logger @options = @hosts = [] @machines = {} @hypervisors = nil end |
Instance Method Details
#cleanup ⇒ Object
Shut down network connections and revert all provisioned virtual machines
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/beaker/network_manager.rb', line 87 def cleanup #shut down connections @hosts.each {|host| host.close } if @hypervisors @hypervisors.each_key do |type| @hypervisors[type].cleanup end end @hypervisors = nil end |
#configure ⇒ Object
Configure all provisioned machines, adding any packages or settings required for SUTs
68 69 70 71 72 73 74 |
# File 'lib/beaker/network_manager.rb', line 68 def configure if @hypervisors @hypervisors.each_key do |type| @hypervisors[type].configure end end end |
#provision ⇒ Object
Provision all virtual machines. Provision machines according to their set hypervisor, if no hypervisor is selected assume that the described hosts are already up and reachable and do no provisioning.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/beaker/network_manager.rb', line 32 def provision if @hypervisors cleanup end @hypervisors = {} #sort hosts by their hypervisor, use hypervisor 'none' if no hypervisor is specified @options['HOSTS'].each_key do |name| host = @options['HOSTS'][name] hypervisor = host['hypervisor'] hypervisor = provision?(@options, host) ? host['hypervisor'] : 'none' @logger.debug "Hypervisor for #{name} is #{hypervisor}" @machines[hypervisor] = [] unless @machines[hypervisor] @machines[hypervisor] << Beaker::Host.create(name, @options) end @machines.each_key do |type| @hypervisors[type] = Beaker::Hypervisor.create(type, @machines[type], @options) @hosts << @machines[type] end @hosts = @hosts.flatten @hosts end |
#provision?(options, host) ⇒ Boolean
Determine if a given host should be provisioned. Provision if:
-
only if we are running with —provision
-
only if we have a hypervisor
-
only if either the specific hosts has no specification or has ‘provision’ in its config
-
always if it is a vagrant box (vagrant boxes are always provisioned as they always need ssh key hacking)
16 17 18 19 20 |
# File 'lib/beaker/network_manager.rb', line 16 def provision? , host command_line_says = [:provision] host_says = host['hypervisor'] && (host.has_key?('provision') ? host['provision'] : true) (command_line_says && host_says) or (host['hypervisor'] =~/vagrant/) end |
#proxy_package_manager ⇒ Object
configure proxy on all provioned machines
78 79 80 81 82 83 84 |
# File 'lib/beaker/network_manager.rb', line 78 def proxy_package_manager if @hypervisors @hypervisors.each_key do |type| @hypervisors[type].proxy_package_manager end end end |
#validate ⇒ Object
Validate all provisioned machines, ensure that required packages are installed - if they are missing attempt to add them.
58 59 60 61 62 63 64 |
# File 'lib/beaker/network_manager.rb', line 58 def validate if @hypervisors @hypervisors.each_key do |type| @hypervisors[type].validate end end end |