vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. data/test/vagrant/env_test.rb +0 -418
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "manage boxes"
17
- banner <<-EOS
18
- Usage:
19
-
20
- #{command.full_name} add name uri
21
- #{command.full_name} remove name
22
-
23
- Add and remove vagrant boxes.
24
-
25
- EOS
26
-
27
- run do |command|
28
- begin
29
- Vagrant::Commands.box(command.argv)
30
- rescue ArgumentError
31
- educate
32
- end
33
- end
34
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "destroys the vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Destroys the vagrant environment.
21
-
22
- EOS
23
-
24
- run do |command|
25
- Vagrant::Commands.down
26
- end
27
- end
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "forcibly halts the vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Forcibly halts the vagrant environment. This is the equivalent
21
- of pulling the power on your computer.
22
-
23
- EOS
24
-
25
- run do |command|
26
- Vagrant::Commands.halt
27
- end
28
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "initializes directory for vagrant use"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Creates the initial files required for using vagrant.
21
-
22
- EOS
23
-
24
- run do |command|
25
- Vagrant::Commands.init
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "package the current vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Package the current vagrant environment into a box.
21
-
22
- EOS
23
-
24
- opt :include, "files to include in the package", :type => :strings
25
-
26
- run do |command|
27
- Vagrant::Commands.package(command.argv[0], command.opts[:include])
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "reload the vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Reloads the vagrant environment. This forces a shutdown of the VM,
21
- updates the metadata (forwarded ports, shared folders, etc.), restarts
22
- the VM, and reruns the chef recipes.
23
-
24
- EOS
25
-
26
- run do |command|
27
- Vagrant::Commands.reload
28
- end
29
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "resumes the vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Resumes the vagrant environment.
21
-
22
- EOS
23
-
24
- run do |command|
25
- Vagrant::Commands.resume
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "opens an SSH connection into the VM"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Opens an SSH connection into the created VM.
21
-
22
- EOS
23
-
24
- run do |command|
25
- Vagrant::Commands.ssh
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "Outputs the status of the current environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- This command outputs the status of the current environment. This command
21
- tells you whether the environment is created, running, suspended,
22
- etc.
23
-
24
- EOS
25
-
26
- run do |command|
27
- Vagrant::Commands.status
28
- end
29
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "suspends the vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Suspends the vagrant environment.
21
-
22
- EOS
23
-
24
- run do |command|
25
- Vagrant::Commands.suspend
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require File.expand_path('../../.bundle/environment', __FILE__)
4
- rescue LoadError
5
- # Fallback on rubygems
6
- require "rubygems"
7
- end
8
-
9
- require 'git-style-binary/command'
10
-
11
- # Get library
12
- libdir = File.join(File.dirname(__FILE__), '..', 'lib')
13
- require File.expand_path('vagrant', libdir)
14
-
15
- GitStyleBinary.command do
16
- short_desc "create the vagrant environment"
17
- banner <<-EOS
18
- Usage: #{command.full_name} #{all_options_string}
19
-
20
- Create the vagrant environment if it doesn't exist,
21
- otherwise start the vagrant environment if its not
22
- already running.
23
-
24
- EOS
25
-
26
- run do |command|
27
- Vagrant::Commands.up
28
- end
29
- end
@@ -1,234 +0,0 @@
1
- module Vagrant
2
- # Contains all the command-line commands invoked by the
3
- # binaries. Having them all in one location assists with
4
- # documentation and also takes the commands out of some of
5
- # the other classes.
6
- class Commands
7
- extend Vagrant::Util
8
-
9
- class << self
10
- # Initializes a directory for use with vagrant. This command copies an
11
- # initial `Vagrantfile` into the current working directory so you can
12
- # begin using vagrant. The configuration file contains some documentation
13
- # to get you started.
14
- def init
15
- rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
16
- if File.exist?(rootfile_path)
17
- error_and_exit(<<-error)
18
- It looks like this directory is already setup for vagrant! (A #{Env::ROOTFILE_NAME}
19
- already exists.)
20
- error
21
- end
22
-
23
- # Copy over the rootfile template into this directory
24
- FileUtils.cp(File.join(PROJECT_ROOT, "templates", Env::ROOTFILE_NAME), rootfile_path)
25
- end
26
-
27
- # Outputs the status of the current environment. This command outputs
28
- # useful information such as whether or not the environment is created
29
- # and if its running, suspended, etc.
30
- def status
31
- Env.load!
32
-
33
- wrap_output do
34
- if !Env.persisted_vm
35
- puts <<-msg
36
- The environment has not yet been created. Run `vagrant up` to create the
37
- environment.
38
- msg
39
- else
40
- additional_msg = ""
41
- if Env.persisted_vm.vm.running?
42
- additional_msg = <<-msg
43
- To stop this VM, you can run `vagrant halt` to shut it down forcefully,
44
- or you can run `vagrant suspend` to simply suspend the virtual machine.
45
- In either case, to restart it again, simply run a `vagrant up`.
46
- msg
47
- elsif Env.persisted_vm.vm.saved?
48
- additional_msg = <<-msg
49
- To resume this VM, simply run `vagrant up`.
50
- msg
51
- elsif Env.persisted_vm.vm.powered_off?
52
- additional_msg = <<-msg
53
- To restart this VM, simply run `vagrant up`.
54
- msg
55
- end
56
-
57
- if !additional_msg.empty?
58
- additional_msg.chomp!
59
- additional_msg = "\n\n#{additional_msg}"
60
- end
61
-
62
- puts <<-msg
63
- The environment has been created. The status of the current environment's
64
- virtual machine is: "#{Env.persisted_vm.vm.state}."#{additional_msg}
65
- msg
66
- end
67
- end
68
- end
69
-
70
- # Bring up a vagrant instance. This handles everything from importing
71
- # the base VM, setting up shared folders, forwarded ports, etc to
72
- # provisioning the instance with chef. {up} also starts the instance,
73
- # running it in the background.
74
- def up
75
- Env.load!
76
-
77
- if Env.persisted_vm
78
- logger.info "VM already created. Starting VM if its not already running..."
79
- Env.persisted_vm.start
80
- else
81
- Env.require_box
82
- VM.execute!(Actions::VM::Up)
83
- end
84
- end
85
-
86
- # Tear down a vagrant instance. This not only shuts down the instance
87
- # (if its running), but also deletes it from the system, including the
88
- # hard disks associated with it.
89
- #
90
- # This command requires that an instance already be brought up with
91
- # `vagrant up`.
92
- def down
93
- Env.load!
94
- Env.require_persisted_vm
95
- Env.persisted_vm.destroy
96
- end
97
-
98
- # Reload the environment. This is almost equivalent to the {up} command
99
- # except that it doesn't import the VM and do the initialize bootstrapping
100
- # of the instance. Instead, it forces a shutdown (if its running) of the
101
- # VM, updates the metadata (shared folders, forwarded ports), restarts
102
- # the VM, and then reruns the provisioning if enabled.
103
- def reload
104
- Env.load!
105
- Env.require_persisted_vm
106
- Env.persisted_vm.execute!(Actions::VM::Reload)
107
- end
108
-
109
- # SSH into the vagrant instance. This will setup an SSH connection into
110
- # the vagrant instance, replacing the running ruby process with the SSH
111
- # connection.
112
- #
113
- # This command requires that an instance already be brought up with
114
- # `vagrant up`.
115
- def ssh
116
- Env.load!
117
- Env.require_persisted_vm
118
- SSH.connect
119
- end
120
-
121
- # Halts a running vagrant instance. This forcibly halts the instance;
122
- # it is the equivalent of pulling the power on a machine. The instance
123
- # can be restarted again with {up}.
124
- #
125
- # This command requires than an instance already be brought up with
126
- # `vagrant up`.
127
- def halt
128
- Env.load!
129
- Env.require_persisted_vm
130
- Env.persisted_vm.execute!(Actions::VM::Halt)
131
- end
132
-
133
- # Suspend a running vagrant instance. This suspends the instance, saving
134
- # the state of the VM and "pausing" it. The instance can be resumed
135
- # again with {resume}.
136
- #
137
- # This command requires that an instance already be brought up with
138
- # `vagrant up`.
139
- def suspend
140
- Env.load!
141
- Env.require_persisted_vm
142
- Env.persisted_vm.suspend
143
- end
144
-
145
- # Resume a running vagrant instance. This resumes an already suspended
146
- # instance (from {suspend}).
147
- #
148
- # This command requires that an instance already be brought up with
149
- # `vagrant up`.
150
- def resume
151
- Env.load!
152
- Env.require_persisted_vm
153
- Env.persisted_vm.resume
154
- end
155
-
156
- # Export and package the current vm
157
- #
158
- # This command requires that an instance be powered off
159
- def package(out_path=nil, include_files=[])
160
- Env.load!
161
- Env.require_persisted_vm
162
- error_and_exit(<<-error) unless Env.persisted_vm.powered_off?
163
- The vagrant virtual environment you are trying to package must be powered off
164
- error
165
-
166
- Env.persisted_vm.package(out_path, include_files)
167
- end
168
-
169
- # Manages the `vagrant box` command, allowing the user to add
170
- # and remove boxes. This single command, given an array, determines
171
- # which action to take and calls the respective action method
172
- # (see {box_add} and {box_remove})
173
- def box(argv)
174
- Env.load!
175
-
176
- sub_commands = ["list", "add", "remove"]
177
-
178
- if !sub_commands.include?(argv[0])
179
- error_and_exit(<<-error)
180
- Please specify a valid action to take on the boxes, either
181
- `add` or `remove`. Examples:
182
-
183
- vagrant box add name uri
184
- vagrant box remove name
185
- vagrant box list
186
- error
187
- end
188
-
189
- send("box_#{argv[0]}", *argv[1..-1])
190
- end
191
-
192
- # Lists all added boxes
193
- def box_list
194
- boxes = Box.all.sort
195
-
196
- wrap_output do
197
- if !boxes.empty?
198
- puts "Installed Vagrant Boxes:\n\n"
199
- boxes.each do |box|
200
- puts box
201
- end
202
- else
203
- puts "No Vagrant Boxes Added!"
204
- end
205
- end
206
- end
207
-
208
- # Adds a box to the local filesystem, given a URI.
209
- def box_add(name, path)
210
- Box.add(name, path)
211
- end
212
-
213
- # Removes a box.
214
- def box_remove(name)
215
- box = Box.find(name)
216
- if box.nil?
217
- error_and_exit(<<-error)
218
- The box you're attempting to remove does not exist!
219
- error
220
- return # for tests
221
- end
222
-
223
- box.destroy
224
- end
225
-
226
- private
227
-
228
- def act_on_vm(&block)
229
- yield Env.persisted_vm
230
- Env.persisted_vm.execute!
231
- end
232
- end
233
- end
234
- end