vagrantup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/vagrant +5 -13
- data/config/default.rb +1 -0
- data/keys/README.md +8 -1
- data/keys/vagrant.ppk +26 -0
- data/lib/vagrant.rb +3 -3
- data/lib/vagrant/actions/base.rb +15 -4
- data/lib/vagrant/actions/box/add.rb +1 -1
- data/lib/vagrant/actions/box/download.rb +72 -66
- data/lib/vagrant/actions/box/unpackage.rb +1 -4
- data/lib/vagrant/actions/runner.rb +1 -1
- data/lib/vagrant/actions/vm/boot.rb +5 -7
- data/lib/vagrant/actions/vm/customize.rb +2 -2
- data/lib/vagrant/actions/vm/destroy.rb +2 -2
- data/lib/vagrant/actions/vm/down.rb +7 -0
- data/lib/vagrant/actions/vm/export.rb +10 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
- data/lib/vagrant/actions/vm/halt.rb +5 -3
- data/lib/vagrant/actions/vm/import.rb +10 -3
- data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
- data/lib/vagrant/actions/vm/package.rb +33 -10
- data/lib/vagrant/actions/vm/provision.rb +4 -4
- data/lib/vagrant/actions/vm/reload.rb +1 -1
- data/lib/vagrant/actions/vm/resume.rb +1 -1
- data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
- data/lib/vagrant/actions/vm/start.rb +3 -2
- data/lib/vagrant/actions/vm/suspend.rb +2 -2
- data/lib/vagrant/actions/vm/up.rb +7 -17
- data/lib/vagrant/active_list.rb +52 -45
- data/lib/vagrant/box.rb +18 -11
- data/lib/vagrant/busy.rb +7 -0
- data/lib/vagrant/command.rb +27 -0
- data/lib/vagrant/commands/base.rb +163 -0
- data/lib/vagrant/commands/box.rb +16 -0
- data/lib/vagrant/commands/box/add.rb +24 -0
- data/lib/vagrant/commands/box/list.rb +30 -0
- data/lib/vagrant/commands/box/remove.rb +31 -0
- data/lib/vagrant/commands/destroy.rb +23 -0
- data/lib/vagrant/commands/down.rb +16 -0
- data/lib/vagrant/commands/halt.rb +23 -0
- data/lib/vagrant/commands/init.rb +32 -0
- data/lib/vagrant/commands/package.rb +46 -0
- data/lib/vagrant/commands/reload.rb +22 -0
- data/lib/vagrant/commands/resume.rb +22 -0
- data/lib/vagrant/commands/ssh.rb +22 -0
- data/lib/vagrant/commands/ssh_config.rb +30 -0
- data/lib/vagrant/commands/status.rb +58 -0
- data/lib/vagrant/commands/suspend.rb +23 -0
- data/lib/vagrant/commands/up.rb +26 -0
- data/lib/vagrant/config.rb +21 -11
- data/lib/vagrant/downloaders/file.rb +5 -5
- data/lib/vagrant/downloaders/http.rb +10 -15
- data/lib/vagrant/environment.rb +259 -0
- data/lib/vagrant/provisioners/base.rb +7 -0
- data/lib/vagrant/provisioners/chef.rb +24 -9
- data/lib/vagrant/provisioners/chef_server.rb +23 -48
- data/lib/vagrant/provisioners/chef_solo.rb +48 -22
- data/lib/vagrant/ssh.rb +95 -46
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/platform.rb +12 -0
- data/lib/vagrant/util/progress_meter.rb +33 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +1 -0
- data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
- data/templates/chef_server_client.erb +16 -0
- data/templates/chef_solo_solo.erb +4 -0
- data/templates/errors.yml +157 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +7 -0
- data/test/test_helper.rb +12 -15
- data/test/vagrant/actions/box/add_test.rb +1 -2
- data/test/vagrant/actions/box/destroy_test.rb +0 -1
- data/test/vagrant/actions/box/download_test.rb +40 -15
- data/test/vagrant/actions/box/unpackage_test.rb +2 -3
- data/test/vagrant/actions/collection_test.rb +8 -5
- data/test/vagrant/actions/runner_test.rb +8 -6
- data/test/vagrant/actions/vm/boot_test.rb +12 -11
- data/test/vagrant/actions/vm/customize_test.rb +2 -3
- data/test/vagrant/actions/vm/destroy_test.rb +2 -3
- data/test/vagrant/actions/vm/down_test.rb +16 -3
- data/test/vagrant/actions/vm/export_test.rb +4 -5
- data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
- data/test/vagrant/actions/vm/halt_test.rb +8 -2
- data/test/vagrant/actions/vm/import_test.rb +5 -5
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
- data/test/vagrant/actions/vm/package_test.rb +60 -22
- data/test/vagrant/actions/vm/provision_test.rb +7 -16
- data/test/vagrant/actions/vm/reload_test.rb +3 -2
- data/test/vagrant/actions/vm/resume_test.rb +0 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
- data/test/vagrant/actions/vm/start_test.rb +10 -3
- data/test/vagrant/actions/vm/suspend_test.rb +1 -2
- data/test/vagrant/actions/vm/up_test.rb +19 -11
- data/test/vagrant/active_list_test.rb +148 -129
- data/test/vagrant/box_test.rb +26 -14
- data/test/vagrant/busy_test.rb +15 -6
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +118 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/destroy_test.rb +32 -0
- data/test/vagrant/commands/down_test.rb +17 -0
- data/test/vagrant/commands/halt_test.rb +28 -0
- data/test/vagrant/commands/init_test.rb +55 -0
- data/test/vagrant/commands/package_test.rb +84 -0
- data/test/vagrant/commands/reload_test.rb +28 -0
- data/test/vagrant/commands/resume_test.rb +33 -0
- data/test/vagrant/commands/ssh_config_test.rb +54 -0
- data/test/vagrant/commands/ssh_test.rb +32 -0
- data/test/vagrant/commands/status_test.rb +20 -0
- data/test/vagrant/commands/suspend_test.rb +33 -0
- data/test/vagrant/commands/up_test.rb +41 -0
- data/test/vagrant/config_test.rb +42 -17
- data/test/vagrant/downloaders/file_test.rb +7 -0
- data/test/vagrant/downloaders/http_test.rb +12 -0
- data/test/vagrant/environment_test.rb +595 -0
- data/test/vagrant/provisioners/base_test.rb +7 -1
- data/test/vagrant/provisioners/chef_server_test.rb +41 -51
- data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
- data/test/vagrant/provisioners/chef_test.rb +61 -15
- data/test/vagrant/ssh_test.rb +166 -38
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/progress_meter_test.rb +33 -0
- data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/vm_test.rb +3 -2
- data/vagrant.gemspec +88 -33
- metadata +92 -49
- data/bin/vagrant-box +0 -34
- data/bin/vagrant-down +0 -27
- data/bin/vagrant-halt +0 -28
- data/bin/vagrant-init +0 -27
- data/bin/vagrant-package +0 -29
- data/bin/vagrant-reload +0 -29
- data/bin/vagrant-resume +0 -27
- data/bin/vagrant-ssh +0 -27
- data/bin/vagrant-status +0 -29
- data/bin/vagrant-suspend +0 -27
- data/bin/vagrant-up +0 -29
- data/lib/vagrant/commands.rb +0 -234
- data/lib/vagrant/env.rb +0 -189
- data/lib/vagrant/stacked_proc_runner.rb +0 -33
- data/test/vagrant/commands_test.rb +0 -269
- data/test/vagrant/env_test.rb +0 -418
@@ -7,19 +7,9 @@ module Vagrant
|
|
7
7
|
next if !vm.running? || vm.uuid == @runner.uuid
|
8
8
|
|
9
9
|
vm.forwarded_ports.each do |fp|
|
10
|
-
|
10
|
+
@runner.env.config.vm.forwarded_ports.each do |name, options|
|
11
11
|
if fp.hostport.to_s == options[:hostport].to_s
|
12
|
-
raise ActionException.new(
|
13
|
-
Vagrant cannot forward the specified ports on this VM, since they
|
14
|
-
would collide with another VirtualBox virtual machine's forwarded
|
15
|
-
ports! The "#{name}" forwarded port (#{fp.hostport}) is already in use on the host
|
16
|
-
machine.
|
17
|
-
|
18
|
-
To fix this, modify your current projects Vagrantfile to use another
|
19
|
-
port. Example, where '1234' would be replaced by a unique host port:
|
20
|
-
|
21
|
-
config.vm.forward_port("#{name}", #{options[:guestport]}, 1234)
|
22
|
-
msg
|
12
|
+
raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s)
|
23
13
|
end
|
24
14
|
end
|
25
15
|
end
|
@@ -33,13 +23,13 @@ msg
|
|
33
23
|
|
34
24
|
def clear
|
35
25
|
logger.info "Deleting any previously set forwarded ports..."
|
36
|
-
@runner.vm.forwarded_ports.collect { |p| p.destroy
|
26
|
+
@runner.vm.forwarded_ports.collect { |p| p.destroy }
|
37
27
|
end
|
38
28
|
|
39
29
|
def forward_ports
|
40
30
|
logger.info "Forwarding ports..."
|
41
31
|
|
42
|
-
|
32
|
+
@runner.env.config.vm.forwarded_ports.each do |name, options|
|
43
33
|
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
44
34
|
port = VirtualBox::ForwardedPort.new
|
45
35
|
port.name = name
|
@@ -48,7 +38,7 @@ msg
|
|
48
38
|
@runner.vm.forwarded_ports << port
|
49
39
|
end
|
50
40
|
|
51
|
-
@runner.vm.save
|
41
|
+
@runner.vm.save
|
52
42
|
end
|
53
43
|
end
|
54
44
|
end
|
@@ -3,10 +3,12 @@ module Vagrant
|
|
3
3
|
module VM
|
4
4
|
class Halt < Base
|
5
5
|
def execute!
|
6
|
-
raise ActionException.new(
|
6
|
+
raise ActionException.new(:vm_not_running) unless @runner.vm.running?
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
@runner.invoke_around_callback(:halt) do
|
9
|
+
logger.info "Forcing shutdown of VM..."
|
10
|
+
@runner.vm.stop
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -2,13 +2,20 @@ module Vagrant
|
|
2
2
|
module Actions
|
3
3
|
module VM
|
4
4
|
class Import < Base
|
5
|
+
include Util::ProgressMeter
|
6
|
+
|
5
7
|
def execute!
|
6
8
|
@runner.invoke_around_callback(:import) do
|
7
9
|
Busy.busy do
|
8
|
-
logger.info "Importing base VM (#{
|
10
|
+
logger.info "Importing base VM (#{@runner.env.box.ovf_file})..."
|
9
11
|
# Use the first argument passed to the action
|
10
|
-
@runner.vm = VirtualBox::VM.import(
|
11
|
-
|
12
|
+
@runner.vm = VirtualBox::VM.import(@runner.env.box.ovf_file) do |progress|
|
13
|
+
update_progress(progress, 100, false)
|
14
|
+
end
|
15
|
+
|
16
|
+
complete_progress
|
17
|
+
|
18
|
+
raise ActionException.new(:virtualbox_import_failure) unless @runner.vm
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
@@ -16,12 +16,12 @@ module Vagrant
|
|
16
16
|
def prepare
|
17
17
|
# Verify the existance of all the additional files, if any
|
18
18
|
@include_files.each do |file|
|
19
|
-
raise ActionException.new(
|
19
|
+
raise ActionException.new(:package_include_file_doesnt_exist, :filename => file) unless File.exists?(file)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Get the export action and store a reference to it
|
23
23
|
@export_action = @runner.find_action(Export)
|
24
|
-
raise ActionException.new(
|
24
|
+
raise ActionException.new(:packaged_requires_export) unless @export_action
|
25
25
|
end
|
26
26
|
|
27
27
|
def execute!
|
@@ -29,28 +29,51 @@ module Vagrant
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def tar_path
|
32
|
-
File.join(FileUtils.pwd, "#{out_path}#{
|
32
|
+
File.join(FileUtils.pwd, "#{out_path}#{@runner.env.config.package.extension}")
|
33
33
|
end
|
34
34
|
|
35
35
|
def temp_path
|
36
36
|
export_action.temp_dir
|
37
37
|
end
|
38
38
|
|
39
|
+
# This method copies the include files (passed in via command line)
|
40
|
+
# to the temporary directory so they are included in a sub-folder within
|
41
|
+
# the actual box
|
42
|
+
def copy_include_files
|
43
|
+
if include_files.length > 0
|
44
|
+
include_dir = File.join(temp_path, "include")
|
45
|
+
FileUtils.mkdir_p(include_dir)
|
46
|
+
|
47
|
+
include_files.each do |f|
|
48
|
+
logger.info "Packaging additional file: #{f}"
|
49
|
+
FileUtils.cp(f, include_dir)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# This method creates the auto-generated Vagrantfile at the root of the
|
55
|
+
# box. This Vagrantfile contains the MAC address so that the user doesn't
|
56
|
+
# have to worry about it.
|
57
|
+
def create_vagrantfile
|
58
|
+
File.open(File.join(temp_path, "Vagrantfile"), "w") do |f|
|
59
|
+
f.write(TemplateRenderer.render("package_Vagrantfile", {
|
60
|
+
:base_mac => @runner.vm.network_adapters.first.mac_address
|
61
|
+
}))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
39
65
|
def compress
|
40
|
-
logger.info "Packaging VM into #{tar_path}
|
66
|
+
logger.info "Packaging VM into #{tar_path}..."
|
41
67
|
File.open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar|
|
42
68
|
Archive::Tar::Minitar::Output.open(tar) do |output|
|
43
69
|
begin
|
44
70
|
current_dir = FileUtils.pwd
|
45
71
|
|
46
|
-
|
47
|
-
|
48
|
-
Archive::Tar::Minitar.pack_file(f, output)
|
49
|
-
end
|
72
|
+
copy_include_files
|
73
|
+
create_vagrantfile
|
50
74
|
|
51
75
|
FileUtils.cd(temp_path)
|
52
|
-
|
53
|
-
Dir.glob(File.join(".", "*")).each do |entry|
|
76
|
+
Dir.glob(File.join(".", "**", "*")).each do |entry|
|
54
77
|
Archive::Tar::Minitar.pack_file(entry, output)
|
55
78
|
end
|
56
79
|
ensure
|
@@ -19,8 +19,8 @@ module Vagrant
|
|
19
19
|
end
|
20
20
|
|
21
21
|
if provisioner.is_a?(Class)
|
22
|
-
@provisioner = provisioner.new
|
23
|
-
raise ActionException.new(
|
22
|
+
@provisioner = provisioner.new(@runner.env)
|
23
|
+
raise ActionException.new(:provisioner_invalid_class) unless @provisioner.is_a?(Provisioners::Base)
|
24
24
|
elsif provisioner.is_a?(Symbol)
|
25
25
|
# We have a few hard coded provisioners for built-ins
|
26
26
|
mapping = {
|
@@ -29,8 +29,8 @@ module Vagrant
|
|
29
29
|
}
|
30
30
|
|
31
31
|
provisioner_klass = mapping[provisioner]
|
32
|
-
raise ActionException.new(
|
33
|
-
@provisioner = provisioner_klass.new
|
32
|
+
raise ActionException.new(:provisioner_unknown_type, :provisioner => provisioner.to_s) if provisioner_klass.nil?
|
33
|
+
@provisioner = provisioner_klass.new(@runner.env)
|
34
34
|
end
|
35
35
|
|
36
36
|
logger.info "Provisioning enabled with #{@provisioner.class}"
|
@@ -5,7 +5,7 @@ module Vagrant
|
|
5
5
|
def prepare
|
6
6
|
steps = [Customize, ForwardPorts, SharedFolders, Boot]
|
7
7
|
steps.unshift(Halt) if @runner.vm.running?
|
8
|
-
steps << Provision if
|
8
|
+
steps << Provision if !@runner.env.config.vm.provisioner.nil?
|
9
9
|
|
10
10
|
steps.each do |action_klass|
|
11
11
|
@runner.add_action(action_klass)
|
@@ -4,7 +4,7 @@ module Vagrant
|
|
4
4
|
class Resume < Base
|
5
5
|
def execute!
|
6
6
|
if !@runner.vm.saved?
|
7
|
-
raise ActionException.new(
|
7
|
+
raise ActionException.new(:vm_not_suspended)
|
8
8
|
end
|
9
9
|
|
10
10
|
logger.info "Resuming suspended VM..."
|
@@ -3,7 +3,7 @@ module Vagrant
|
|
3
3
|
module VM
|
4
4
|
class SharedFolders < Base
|
5
5
|
def shared_folders
|
6
|
-
|
6
|
+
@runner.env.config.vm.shared_folders.inject([]) do |acc, data|
|
7
7
|
name, value = data
|
8
8
|
acc << [name, File.expand_path(value[:hostpath]), value[:guestpath]]
|
9
9
|
end
|
@@ -17,7 +17,7 @@ module Vagrant
|
|
17
17
|
def after_boot
|
18
18
|
logger.info "Mounting shared folders..."
|
19
19
|
|
20
|
-
|
20
|
+
@runner.env.ssh.execute do |ssh|
|
21
21
|
shared_folders.each do |name, hostpath, guestpath|
|
22
22
|
logger.info "-- #{name}: #{guestpath}"
|
23
23
|
ssh.exec!("sudo mkdir -p #{guestpath}")
|
@@ -43,11 +43,11 @@ module Vagrant
|
|
43
43
|
shared_folders.each do |name, hostpath, guestpath|
|
44
44
|
folder = VirtualBox::SharedFolder.new
|
45
45
|
folder.name = name
|
46
|
-
folder.
|
46
|
+
folder.host_path = hostpath
|
47
47
|
@runner.vm.shared_folders << folder
|
48
48
|
end
|
49
49
|
|
50
|
-
@runner.vm.save
|
50
|
+
@runner.vm.save
|
51
51
|
end
|
52
52
|
|
53
53
|
def mount_folder(ssh, name, guestpath, sleeptime=5)
|
@@ -57,8 +57,8 @@ module Vagrant
|
|
57
57
|
|
58
58
|
# Determine the permission string to attach to the mount command
|
59
59
|
perms = []
|
60
|
-
perms << "uid=#{
|
61
|
-
perms << "gid=#{
|
60
|
+
perms << "uid=#{@runner.env.config.vm.shared_folder_uid}"
|
61
|
+
perms << "gid=#{@runner.env.config.vm.shared_folder_gid}"
|
62
62
|
perms = " -o #{perms.join(",")}" if !perms.empty?
|
63
63
|
|
64
64
|
attempts = 0
|
@@ -71,7 +71,7 @@ module Vagrant
|
|
71
71
|
break unless result
|
72
72
|
|
73
73
|
attempts += 1
|
74
|
-
raise ActionException.new(
|
74
|
+
raise ActionException.new(:vm_mount_fail) if attempts >= 10
|
75
75
|
sleep sleeptime
|
76
76
|
end
|
77
77
|
end
|
@@ -5,9 +5,10 @@ module Vagrant
|
|
5
5
|
def prepare
|
6
6
|
# Start is a "meta-action" so it really just queues up a bunch
|
7
7
|
# of other actions in its place:
|
8
|
-
steps = [
|
8
|
+
steps = [Boot]
|
9
|
+
steps.unshift([Customize, ForwardPorts, SharedFolders]) unless @runner.vm.saved?
|
9
10
|
|
10
|
-
steps.each do |action_klass|
|
11
|
+
steps.flatten.each do |action_klass|
|
11
12
|
@runner.add_action(action_klass)
|
12
13
|
end
|
13
14
|
end
|
@@ -4,11 +4,11 @@ module Vagrant
|
|
4
4
|
class Suspend < Base
|
5
5
|
def execute!
|
6
6
|
if !@runner.vm.running?
|
7
|
-
raise ActionException.new(
|
7
|
+
raise ActionException.new(:vm_not_running_for_suspend)
|
8
8
|
end
|
9
9
|
|
10
10
|
logger.info "Saving VM state and suspending execution..."
|
11
|
-
@runner.vm.save_state
|
11
|
+
@runner.vm.save_state
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -4,25 +4,15 @@ module Vagrant
|
|
4
4
|
class Up < Base
|
5
5
|
def prepare
|
6
6
|
# If the dotfile is not a file, raise error
|
7
|
-
if File.exist?(
|
8
|
-
raise ActionException.new(
|
9
|
-
The dotfile which Vagrant uses to store the UUID of the project's
|
10
|
-
virtual machine already exists and is not a file! The dotfile is
|
11
|
-
currently configured to be `#{Env.dotfile_path}`
|
12
|
-
|
13
|
-
To change this value, please see `config.vagrant.dotfile_name`
|
14
|
-
|
15
|
-
This often exists if you're trying to create a Vagrant virtual
|
16
|
-
environment from your home directory. To resolve this, you can either
|
17
|
-
modify the configuration a bit, or simply use a different directory.
|
18
|
-
msg
|
7
|
+
if File.exist?(@runner.env.dotfile_path) && !File.file?(@runner.env.dotfile_path)
|
8
|
+
raise ActionException.new(:dotfile_error, :env => @runner.env)
|
19
9
|
end
|
20
10
|
|
21
11
|
# Up is a "meta-action" so it really just queues up a bunch
|
22
12
|
# of other actions in its place:
|
23
13
|
steps = [Import, Customize, ForwardPorts, SharedFolders, Boot]
|
24
|
-
steps << Provision if
|
25
|
-
steps.insert(0, MoveHardDrive) if
|
14
|
+
steps << Provision if !@runner.env.config.vm.provisioner.nil?
|
15
|
+
steps.insert(0, MoveHardDrive) if @runner.env.config.vm.hd_location
|
26
16
|
|
27
17
|
steps.each do |action_klass|
|
28
18
|
@runner.add_action(action_klass)
|
@@ -36,13 +26,13 @@ msg
|
|
36
26
|
|
37
27
|
def persist
|
38
28
|
logger.info "Persisting the VM UUID (#{@runner.uuid})..."
|
39
|
-
|
29
|
+
@runner.env.persist_vm
|
40
30
|
end
|
41
31
|
|
42
32
|
def setup_mac_address
|
43
33
|
logger.info "Matching MAC addresses..."
|
44
|
-
@runner.vm.
|
45
|
-
@runner.vm.save
|
34
|
+
@runner.vm.network_adapters.first.mac_address = @runner.env.config.vm.base_mac
|
35
|
+
@runner.vm.save
|
46
36
|
end
|
47
37
|
end
|
48
38
|
end
|
data/lib/vagrant/active_list.rb
CHANGED
@@ -6,61 +6,68 @@ module Vagrant
|
|
6
6
|
|
7
7
|
@@list = nil
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# JSON file. This will cache the result, which can be reloaded
|
12
|
-
# by setting the `reload` parameter to true.
|
13
|
-
#
|
14
|
-
# @return [Array<String>]
|
15
|
-
def list(reload = false)
|
16
|
-
return @@list unless @@list.nil? || reload
|
9
|
+
# The environment this active list belongs to
|
10
|
+
attr_accessor :env
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
# Creates the instance of the ActiveList, with the given environment
|
13
|
+
# if specified
|
14
|
+
def initialize(env=nil)
|
15
|
+
@env = env
|
16
|
+
end
|
23
17
|
|
24
|
-
|
25
|
-
|
18
|
+
# Parses and returns the list of UUIDs from the active VM
|
19
|
+
# JSON file. This will cache the result, which can be reloaded
|
20
|
+
# by setting the `reload` parameter to true.
|
21
|
+
#
|
22
|
+
# @return [Array<String>]
|
23
|
+
def list(reload=false)
|
24
|
+
return @list unless @list.nil? || reload
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
list
|
26
|
+
@list ||= []
|
27
|
+
return @list unless File.file?(path)
|
28
|
+
File.open(path, "r") do |f|
|
29
|
+
@list = JSON.parse(f.read)
|
31
30
|
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
vms.collect { |vm| vm.uuid }
|
36
|
-
end
|
32
|
+
@list
|
33
|
+
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
35
|
+
# Returns an array of {Vagrant::VM} objects which are currently
|
36
|
+
# active.
|
37
|
+
def vms
|
38
|
+
list.collect { |uuid| Vagrant::VM.find(uuid) }.compact
|
39
|
+
end
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
save
|
50
|
-
end
|
41
|
+
# Returns an array of UUIDs filtered so each is verified to exist.
|
42
|
+
def filtered_list
|
43
|
+
vms.collect { |vm| vm.uuid }
|
44
|
+
end
|
51
45
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
# Adds a virtual environment to the list of active virtual machines
|
47
|
+
def add(vm)
|
48
|
+
list << vm.uuid
|
49
|
+
list.uniq!
|
50
|
+
save
|
51
|
+
end
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
# Remove a virtual environment from the list of active virtual machines
|
54
|
+
def remove(vm)
|
55
|
+
vm = vm.uuid if vm.is_a?(Vagrant::VM)
|
56
|
+
list.delete(vm)
|
57
|
+
save
|
58
|
+
end
|
59
|
+
|
60
|
+
# Persists the list down to the JSON file.
|
61
|
+
def save
|
62
|
+
File.open(path, "w+") do |f|
|
63
|
+
f.write(filtered_list.to_json)
|
63
64
|
end
|
64
65
|
end
|
66
|
+
|
67
|
+
# Returns the path to the JSON file which holds the UUIDs of the
|
68
|
+
# active virtual machines managed by Vagrant.
|
69
|
+
def path
|
70
|
+
File.join(env.home_path, FILENAME)
|
71
|
+
end
|
65
72
|
end
|
66
73
|
end
|