6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/vmreverter/hypervisor/vsphere.rb', line 6
def initialize(vsphere_hosts, options, config)
@options = options
@config = config
@logger = options[:logger]
@vsphere_hosts = vsphere_hosts
require 'yaml' unless defined?(YAML)
vsphere_credentials = VsphereHelper.load_config options[:auth]
@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]}" + " with credentials for #{vsphere_credentials[:user]}"
@vsphere_helper = VsphereHelper.new( vsphere_credentials )
@vsphere_vms = {}
@vsphere_hosts.each do |host|
@vsphere_vms[host] = config['HOSTS'][host]['snapshot']
end
vms = @vsphere_helper.find_vms(@vsphere_vms.keys)
@vsphere_vms.each_pair do |name, snap|
report_and_raise(@logger, RuntimeError.new("Couldn't find VM #{name} in vSphere!"), "VSphere::initialize") unless vm = vms[name]
report_and_raise(@logger, RuntimeError.new("Could not find snapshot '#{snap}' for VM #{vm.name}!"), "VSphere::initialize") unless @vsphere_helper.find_snapshot(vm, snap)
end
return self
end
|