Class: Beaker::NetworkManager
- Inherits:
-
Object
- Object
- Beaker::NetworkManager
- Defined in:
- lib/beaker/network_manager.rb
Constant Summary collapse
- HYPERVISOR_TYPES =
['solaris', 'blimpy', 'vsphere', 'fusion', 'aix', 'vcloud', 'vagrant']
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(options, logger) ⇒ NetworkManager
constructor
A new instance of NetworkManager.
- #provision ⇒ Object
- #provision?(options, host) ⇒ Boolean
Constructor Details
#initialize(options, logger) ⇒ NetworkManager
Returns a new instance of NetworkManager.
24 25 26 27 28 29 30 |
# File 'lib/beaker/network_manager.rb', line 24 def initialize(, logger) @logger = logger @options = @hosts = [] @virtual_machines = {} @noprovision_machines = [] end |
Instance Method Details
#cleanup ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/beaker/network_manager.rb', line 66 def cleanup #shut down connections @hosts.each {|host| host.close } if @provisioned_set @provisioned_set.each_key do |type| if @provisioned_set[type] @provisioned_set[type].cleanup end end end end |
#provision ⇒ Object
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 64 |
# File 'lib/beaker/network_manager.rb', line 32 def provision #sort hosts into those to be provisioned and those to use non-provisioned @options['HOSTS'].each_key do |name| host = @options['HOSTS'][name] hypervisor = host['hypervisor'] if provision?(@options, host) raise "Invalid hypervisor: #{hypervisor} (#{name})" unless HYPERVISOR_TYPES.include? hypervisor @logger.debug "Hypervisor for #{name} is #{hypervisor}" @virtual_machines[hypervisor] = [] unless @virtual_machines[hypervisor] @virtual_machines[hypervisor] << name else #this is a non-provisioned machine, deal with it without hypervisors @logger.debug "No hypervisor for #{name}, connecting to host without provisioning" @noprovision_machines << name end end @provisioned_set = {} @virtual_machines.each do |type, names| hosts_for_type = [] #set up host objects for provisioned provisioned_set names.each do |name| host = Beaker::Host.create(name, @options) hosts_for_type << host end @provisioned_set[type] = Beaker::Hypervisor.create(type, hosts_for_type, @options) @hosts << hosts_for_type end @noprovision_machines.each do |name| @hosts << Beaker::Host.create(name, @options) end @hosts = @hosts.flatten @hosts end |
#provision?(options, host) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/beaker/network_manager.rb', line 13 def provision? , host #provision this box # - 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) 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 |