Class: Vmreverter::VMManager

Inherits:
Object
  • Object
show all
Defined in:
lib/vmreverter/vmmanager.rb

Overview

Collection using Proxy Pattern - Proxy normalized access to specific Hypervisors such as VSphere through creation by the Hypervisor Factory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ VMManager

Returns a new instance of VMManager.



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
# File 'lib/vmreverter/vmmanager.rb', line 33

def initialize(config)
  @logger = config.logger
  @options = config.options
  @hosts = []
  @config = config
  @hypervisor_collection = {}
  @virtual_machines = {}

  @config['HOSTS'].each_key do |name|
    hypervisor = @config['HOSTS'][name]['hypervisor']
    @logger.debug "Hypervisor for #{name} is #{hypervisor}"
    @virtual_machines[hypervisor] = [] unless @virtual_machines[hypervisor]
    @virtual_machines[hypervisor] << name
  end

  ## Data Model Looks like
  # @virtual_machines.inspect
  # {"vsphere" => ["test_server01","test_server02"], "blimpy" => ["aws_test_server01","aws_test_server01"]}

  @virtual_machines.each do |type, names|
    @hypervisor_collection[type] = Vmreverter::Hypervisor.register(type, names, @config)
  end

  #return instance created
  return self
end

Instance Attribute Details

#hypervisor_collectionObject

Returns the value of attribute hypervisor_collection.



17
18
19
# File 'lib/vmreverter/vmmanager.rb', line 17

def hypervisor_collection
  @hypervisor_collection
end

Class Method Details

.execute!(config) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vmreverter/vmmanager.rb', line 20

def self.execute!(config)
  begin
    @vmmanager = Vmreverter::VMManager.new(config)
    @vmmanager.invoke
    @vmmanager.close_connection
  rescue => e
    raise e
  ensure
    FileUtils.rm config.options[:lockfile], :force => true if config.options[:lockfile]
  end
end

Instance Method Details

#close_connectionObject



67
68
69
70
71
72
# File 'lib/vmreverter/vmmanager.rb', line 67

def close_connection
  @hypervisor_collection.each do |hypervisor_type, hypervisor_instance|
    @logger.notify("Disconnecting from #{hypervisor_type}")
    hypervisor_instance.close_connection
  end
end

#invokeObject



60
61
62
63
64
65
# File 'lib/vmreverter/vmmanager.rb', line 60

def invoke
  @hypervisor_collection.each do |hypervisor_type, hypervisor_instance|
    @logger.notify("Invoking #{hypervisor_type} hosts")
    hypervisor_instance.invoke
  end
end