Class: Beaker::NetworkManager

Inherits:
Object
  • Object
show all
Defined in:
lib/beaker/network_manager.rb

Constant Summary collapse

HYPERVISOR_TYPES =
['solaris', 'blimpy', 'vsphere', 'fusion', 'aix', 'vcloud', 'vagrant']

Instance Method Summary collapse

Constructor Details

#initialize(config, options, logger) ⇒ NetworkManager



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/beaker/network_manager.rb', line 13

def initialize(config, options, logger)
  @logger = logger
  @options = options
  @hosts = []
  @config = config
  @virtual_machines = {}
  @noprovision_machines = []
  @config['HOSTS'].each_key do |name|
    host_info = @config['HOSTS'][name]
    #check to see if this host has a hypervisor 
    hypervisor = host_info['hypervisor'] 
    #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
    if @options[:provision] && hypervisor && (host_info.has_key?('provision') ? host_info['provision'] : true) #obey config file provision, defaults to provisioning vms
      raise "Invalid hypervisor: #{hypervisor} (#{name})" unless HYPERVISOR_TYPES.include? hypervisor
      @logger.debug "Hypervisor for #{name} is #{host_info['hypervisor'] || 'default' }, and I'm going to use #{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
end

Instance Method Details

#cleanupObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/beaker/network_manager.rb', line 60

def cleanup
  #only cleanup if we aren't preserving hosts
  #shut down connections
  @hosts.each {|host| host.close }

  if not @options[:preserve_hosts]
    @provisioned_set.each_key do |type|
      @provisioned_set[type].cleanup
    end
  end
end

#provisionObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/beaker/network_manager.rb', line 41

def provision
  @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, @config)
      hosts_for_type << host
    end
    @provisioned_set[type] = Beaker::Hypervisor.create(type, hosts_for_type, @options, @config)
    @hosts << hosts_for_type
  end
  @noprovision_machines.each do |name|
    @hosts << Beaker::Host.create(name, @options, @config)
  end
  @hosts = @hosts.flatten
  @hosts
end