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
|
# File 'lib/vbox/export.rb', line 5
def self.vagrant(boxname,boxdir,definition)
vm=VirtualBox::VM.find(boxname)
if vm.nil?
puts "#{boxname} is not found, maybe you need to build first?"
exit
end
if vm.running?
puts "Vagrant requires the box to be shutdown, before it can export"
puts "Sudo also needs to work for user #{definition[:ssh_user]}"
puts "Performing a clean shutdown now."
ssh_options={ :user => definition[:ssh_user], :port => definition[:ssh_host_port], :password => definition[:ssh_password],
:timeout => definition[:ssh_timeout]}
Vbox::Ssh.execute("localhost","sudo #{definition[:shutdown_cmd]}",ssh_options)
while (vm.running?) do
print '.'
sleep 1
end
puts
puts "Machine #{boxname} is powered off cleanly"
end
boxdir=Pathname.new(Dir.pwd)
full_path=File.join(boxdir,boxname+".box")
path1=Pathname.new(full_path)
path2=Pathname.new(Dir.pwd)
box_path=path1.relative_path_from(path2).to_s
if File.exists?("#{box_path}")
puts "box #{boxname}.box already exists"
exit
end
puts "Excuting vagrant voodoo:"
export_command="vagrant package --base '#{boxname}' --output '#{box_path}'"
puts "#{export_command}"
Vbox::Shell.execute("#{export_command}") puts
puts "To import it into vagrant type:"
puts "vagrant box add '#{boxname}' '#{box_path}'"
puts ""
puts "To use it:"
puts "vagrant init '#{boxname}'"
puts "vagrant up"
puts "vagrant ssh"
end
|