/
builder.rb
78 lines (59 loc) · 2.91 KB
/
builder.rb
1
2
3
4
5
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'veewee/builder/core/builder'
require 'veewee/builder/vmfusion/helper/validate_vmfusion'
module Veewee
module Builder
module Vmfusion
class Builder < Veewee::Builder::Core::Builder
include ::Veewee::Builder::Vmfusion::BuilderHelper
def check_requirements
unless gem_available?("fission")
raise ::Veewee::Error, "The Vmfusion Builder requires the gem 'fission' to be installed\n"+ "gem install fission"
end
end
def build_info
info=super
command="/Library/Application Support/VMware Fusion/vmrun"
output=IO.popen("#{command.shellescape}").readlines
info << {:filename => ".vmfusion_version",:content => output[1].split(/ /)[2..3].join.strip}
end
# Translate the definition ssh options to ssh options that can be passed to Net::Ssh calls
def ssh_options(definition)
ssh_options={
:user => definition.ssh_user,
:port => 22,
:password => definition.ssh_password,
:timeout => definition.ssh_login_timeout.to_i
}
return ssh_options
end
#
# Transfer information provide by the builder to the box
#
#
def transfer_buildinfo(box,definition)
super(box,definition)
# When we get here, ssh is available and no postinstall scripts have been executed yet
# So we begin by transferring the ISO file of the vmware tools
iso_image="/Library/Application Support/VMware Fusion/isoimages/linux.iso"
iso_image="/Library/Application Support/VMware Fusion/isoimages/darwin.iso" if definition.os_type_id=~/^Darwin/
iso_image="/Library/Application Support/VMware Fusion/isoimages/freebsd.iso" if definition.os_type_id=~/^Free/
iso_image="/Library/Application Support/VMware Fusion/isoimages/windows.iso" if definition.os_type_id=~/^Win/
begin
Veewee::Util::Ssh.when_ssh_login_works(box.ip_address,ssh_options(definition).merge({:timeout => definition.postinstall_timeout.to_i})) do
begin
env.logger.info "About to transfer vmware tools iso buildinfo to the box #{box.name} - #{box.ip_address} - #{ssh_options(definition)}"
Veewee::Util::Ssh.transfer_file(box.ip_address,iso_image,File.basename(iso_image),ssh_options(definition))
rescue RuntimeError => ex
env.ui.error "Error transfering vmware tools iso , possible not enough permissions to write? #{ex}"
exit -1
end
end
rescue Net::SSH::AuthenticationFailed
env.ui.error "Authentication failure"
exit -1
end
end
end #End Class
end # End Module
end # End Module
end # End Module