vagrantup 0.4.3.dev → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/config/default.rb +6 -6
  4. data/lib/vagrant.rb +6 -3
  5. data/lib/vagrant/action.rb +77 -0
  6. data/lib/vagrant/action/action_exception.rb +16 -0
  7. data/lib/vagrant/action/box/destroy.rb +19 -0
  8. data/lib/vagrant/action/box/download.rb +78 -0
  9. data/lib/vagrant/action/box/unpackage.rb +58 -0
  10. data/lib/vagrant/action/box/verify.rb +23 -0
  11. data/lib/vagrant/action/builder.rb +151 -0
  12. data/lib/vagrant/action/builtin.rb +114 -0
  13. data/lib/vagrant/action/env/error_halt.rb +16 -0
  14. data/lib/vagrant/action/env/set.rb +18 -0
  15. data/lib/vagrant/action/environment.rb +98 -0
  16. data/lib/vagrant/action/exception_catcher.rb +14 -0
  17. data/lib/vagrant/action/vm/boot.rb +54 -0
  18. data/lib/vagrant/action/vm/check_box.rb +27 -0
  19. data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
  20. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  21. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  22. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  23. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  24. data/lib/vagrant/action/vm/customize.rb +21 -0
  25. data/lib/vagrant/action/vm/destroy.rb +20 -0
  26. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
  27. data/lib/vagrant/action/vm/disable_networks.rb +26 -0
  28. data/lib/vagrant/action/vm/export.rb +53 -0
  29. data/lib/vagrant/action/vm/forward_ports.rb +121 -0
  30. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  31. data/lib/vagrant/action/vm/halt.rb +34 -0
  32. data/lib/vagrant/action/vm/import.rb +33 -0
  33. data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
  34. data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
  35. data/lib/vagrant/action/vm/nfs.rb +161 -0
  36. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  37. data/lib/vagrant/action/vm/package.rb +99 -0
  38. data/lib/vagrant/action/vm/persist.rb +22 -0
  39. data/lib/vagrant/action/vm/provision.rb +50 -0
  40. data/lib/vagrant/action/vm/resume.rb +20 -0
  41. data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
  42. data/lib/vagrant/action/vm/suspend.rb +20 -0
  43. data/lib/vagrant/box.rb +3 -7
  44. data/lib/vagrant/commands/base.rb +1 -3
  45. data/lib/vagrant/commands/package.rb +4 -9
  46. data/lib/vagrant/commands/up.rb +0 -2
  47. data/lib/vagrant/config.rb +15 -1
  48. data/lib/vagrant/downloaders/file.rb +1 -1
  49. data/lib/vagrant/downloaders/http.rb +2 -1
  50. data/lib/vagrant/environment.rb +18 -14
  51. data/lib/vagrant/hosts/base.rb +77 -0
  52. data/lib/vagrant/hosts/bsd.rb +53 -0
  53. data/lib/vagrant/hosts/linux.rb +52 -0
  54. data/lib/vagrant/provisioners/base.rb +17 -9
  55. data/lib/vagrant/provisioners/chef.rb +1 -1
  56. data/lib/vagrant/provisioners/chef_server.rb +4 -8
  57. data/lib/vagrant/provisioners/chef_solo.rb +1 -2
  58. data/lib/vagrant/ssh.rb +12 -4
  59. data/lib/vagrant/systems/base.rb +4 -0
  60. data/lib/vagrant/systems/linux.rb +12 -1
  61. data/lib/vagrant/util.rb +16 -0
  62. data/lib/vagrant/util/busy.rb +59 -0
  63. data/lib/vagrant/util/plain_logger.rb +11 -0
  64. data/lib/vagrant/util/platform.rb +18 -0
  65. data/lib/vagrant/util/resource_logger.rb +128 -0
  66. data/lib/vagrant/version.rb +6 -0
  67. data/lib/vagrant/vm.rb +10 -12
  68. data/templates/chef_solo_solo.erb +2 -1
  69. data/templates/nfs/exports.erb +3 -0
  70. data/templates/nfs/exports_linux.erb +3 -0
  71. data/templates/strings.yml +23 -3
  72. metadata +121 -196
  73. data/.gitignore +0 -11
  74. data/Gemfile +0 -18
  75. data/Rakefile +0 -41
  76. data/VERSION +0 -1
  77. data/bin/.gitignore +0 -0
  78. data/lib/vagrant/actions/base.rb +0 -130
  79. data/lib/vagrant/actions/box/add.rb +0 -23
  80. data/lib/vagrant/actions/box/destroy.rb +0 -14
  81. data/lib/vagrant/actions/box/download.rb +0 -67
  82. data/lib/vagrant/actions/box/unpackage.rb +0 -42
  83. data/lib/vagrant/actions/box/verify.rb +0 -32
  84. data/lib/vagrant/actions/collection.rb +0 -36
  85. data/lib/vagrant/actions/runner.rb +0 -131
  86. data/lib/vagrant/actions/vm/boot.rb +0 -43
  87. data/lib/vagrant/actions/vm/customize.rb +0 -19
  88. data/lib/vagrant/actions/vm/destroy.rb +0 -24
  89. data/lib/vagrant/actions/vm/down.rb +0 -22
  90. data/lib/vagrant/actions/vm/export.rb +0 -45
  91. data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
  92. data/lib/vagrant/actions/vm/halt.rb +0 -24
  93. data/lib/vagrant/actions/vm/import.rb +0 -23
  94. data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
  95. data/lib/vagrant/actions/vm/package.rb +0 -94
  96. data/lib/vagrant/actions/vm/provision.rb +0 -49
  97. data/lib/vagrant/actions/vm/reload.rb +0 -17
  98. data/lib/vagrant/actions/vm/resume.rb +0 -16
  99. data/lib/vagrant/actions/vm/start.rb +0 -26
  100. data/lib/vagrant/actions/vm/suspend.rb +0 -16
  101. data/lib/vagrant/actions/vm/up.rb +0 -53
  102. data/lib/vagrant/busy.rb +0 -79
  103. data/lib/vagrant/resource_logger.rb +0 -126
  104. data/lib/vagrant/util/error_helper.rb +0 -13
  105. data/lib/vagrant/util/output_helper.rb +0 -9
  106. data/test/test_helper.rb +0 -149
  107. data/test/vagrant/actions/base_test.rb +0 -32
  108. data/test/vagrant/actions/box/add_test.rb +0 -36
  109. data/test/vagrant/actions/box/destroy_test.rb +0 -17
  110. data/test/vagrant/actions/box/download_test.rb +0 -137
  111. data/test/vagrant/actions/box/unpackage_test.rb +0 -99
  112. data/test/vagrant/actions/box/verify_test.rb +0 -44
  113. data/test/vagrant/actions/collection_test.rb +0 -113
  114. data/test/vagrant/actions/runner_test.rb +0 -268
  115. data/test/vagrant/actions/vm/boot_test.rb +0 -49
  116. data/test/vagrant/actions/vm/customize_test.rb +0 -21
  117. data/test/vagrant/actions/vm/destroy_test.rb +0 -37
  118. data/test/vagrant/actions/vm/down_test.rb +0 -39
  119. data/test/vagrant/actions/vm/export_test.rb +0 -88
  120. data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
  121. data/test/vagrant/actions/vm/halt_test.rb +0 -65
  122. data/test/vagrant/actions/vm/import_test.rb +0 -45
  123. data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
  124. data/test/vagrant/actions/vm/network_test.rb +0 -291
  125. data/test/vagrant/actions/vm/package_test.rb +0 -254
  126. data/test/vagrant/actions/vm/provision_test.rb +0 -99
  127. data/test/vagrant/actions/vm/reload_test.rb +0 -46
  128. data/test/vagrant/actions/vm/resume_test.rb +0 -26
  129. data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
  130. data/test/vagrant/actions/vm/start_test.rb +0 -73
  131. data/test/vagrant/actions/vm/suspend_test.rb +0 -26
  132. data/test/vagrant/actions/vm/up_test.rb +0 -96
  133. data/test/vagrant/active_list_test.rb +0 -173
  134. data/test/vagrant/box_test.rb +0 -154
  135. data/test/vagrant/busy_test.rb +0 -78
  136. data/test/vagrant/command_test.rb +0 -53
  137. data/test/vagrant/commands/base_test.rb +0 -139
  138. data/test/vagrant/commands/box/add_test.rb +0 -34
  139. data/test/vagrant/commands/box/list_test.rb +0 -32
  140. data/test/vagrant/commands/box/remove_test.rb +0 -41
  141. data/test/vagrant/commands/destroy_test.rb +0 -44
  142. data/test/vagrant/commands/halt_test.rb +0 -50
  143. data/test/vagrant/commands/init_test.rb +0 -55
  144. data/test/vagrant/commands/package_test.rb +0 -104
  145. data/test/vagrant/commands/provision_test.rb +0 -60
  146. data/test/vagrant/commands/reload_test.rb +0 -44
  147. data/test/vagrant/commands/resume_test.rb +0 -44
  148. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  149. data/test/vagrant/commands/ssh_test.rb +0 -129
  150. data/test/vagrant/commands/status_test.rb +0 -40
  151. data/test/vagrant/commands/suspend_test.rb +0 -44
  152. data/test/vagrant/commands/up_test.rb +0 -47
  153. data/test/vagrant/config_test.rb +0 -287
  154. data/test/vagrant/downloaders/base_test.rb +0 -28
  155. data/test/vagrant/downloaders/file_test.rb +0 -33
  156. data/test/vagrant/downloaders/http_test.rb +0 -62
  157. data/test/vagrant/environment_test.rb +0 -770
  158. data/test/vagrant/provisioners/base_test.rb +0 -33
  159. data/test/vagrant/provisioners/chef_server_test.rb +0 -176
  160. data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
  161. data/test/vagrant/provisioners/chef_test.rb +0 -175
  162. data/test/vagrant/resource_logger_test.rb +0 -145
  163. data/test/vagrant/ssh_session_test.rb +0 -46
  164. data/test/vagrant/ssh_test.rb +0 -296
  165. data/test/vagrant/systems/linux_test.rb +0 -179
  166. data/test/vagrant/util/error_helper_test.rb +0 -5
  167. data/test/vagrant/util/output_helper_test.rb +0 -5
  168. data/test/vagrant/util/plain_logger_test.rb +0 -17
  169. data/test/vagrant/util/platform_test.rb +0 -18
  170. data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
  171. data/test/vagrant/util/template_renderer_test.rb +0 -144
  172. data/test/vagrant/util/translator_test.rb +0 -61
  173. data/test/vagrant/util_test.rb +0 -27
  174. data/test/vagrant/vm_test.rb +0 -235
  175. data/vagrant.gemspec +0 -291
@@ -1,71 +1,43 @@
1
1
  module Vagrant
2
- module Actions
2
+ class Action
3
3
  module VM
4
- class Network < Base
5
- def prepare
6
- # Verify that the given network options are valid
7
- runner.env.config.vm.network_options.compact.each do |network_options|
8
- verify_no_bridge_collision(network_options)
9
- end
10
- end
11
-
12
- def before_destroy
13
- # We need to check if the host only network specified by any
14
- # of the adapters would not have any more clients if it was
15
- # destroyed. And if so, then destroy the host only network
16
- # itself.
17
- interfaces = runner.vm.network_adapters.collect do |adapter|
18
- adapter.host_interface_object
19
- end
20
-
21
- interfaces.compact.uniq.each do |interface|
22
- # Destroy the network interface if there is only one
23
- # attached VM (which must be this VM)
24
- if interface.attached_vms.length == 1
25
- logger.info "Destroying unused network interface..."
26
- interface.destroy
4
+ # Networking middleware for Vagrant. This enables host only
5
+ # networking on VMs if configured as such.
6
+ class Network
7
+ include ExceptionCatcher
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @env = env
12
+
13
+ env["config"].vm.network_options.compact.each do |network_options|
14
+ if !verify_no_bridge_collision(network_options)
15
+ env.error!(:network_collides)
16
+ return
27
17
  end
28
18
  end
29
19
  end
30
20
 
31
- def before_boot
21
+ def call(env)
22
+ @env = env
32
23
  assign_network if enable_network?
33
- end
34
-
35
- def after_boot
36
- if enable_network?
37
- logger.info "Enabling host only network..."
38
24
 
39
- runner.system.prepare_host_only_network
25
+ @app.call(env)
40
26
 
41
- runner.env.config.vm.network_options.compact.each do |network_options|
42
- runner.system.enable_host_only_network(network_options)
27
+ if !env.error? && enable_network?
28
+ catch_action_exception(env) do
29
+ @env.logger.info "Enabling host only network..."
30
+ @env["vm"].system.prepare_host_only_network
31
+ @env.env.config.vm.network_options.compact.each do |network_options|
32
+ @env["vm"].system.enable_host_only_network(network_options)
33
+ end
43
34
  end
44
35
  end
45
36
  end
46
37
 
47
- def enable_network?
48
- !runner.env.config.vm.network_options.compact.empty?
49
- end
50
-
51
- # Enables and assigns the host only network to the proper
52
- # adapter on the VM, and saves the adapter.
53
- def assign_network
54
- logger.info "Preparing host only network..."
55
-
56
- runner.env.config.vm.network_options.compact.each do |network_options|
57
- adapter = runner.vm.network_adapters[network_options[:adapter]]
58
- adapter.enabled = true
59
- adapter.attachment_type = :host_only
60
- adapter.host_interface = network_name(network_options)
61
- adapter.save
62
- end
63
- end
64
-
65
38
  # Verifies that there is no collision with a bridged network interface
66
39
  # for the given network options.
67
40
  def verify_no_bridge_collision(net_options)
68
- # First try to find a matching network
69
41
  interfaces = VirtualBox::Global.global.host.network_interfaces
70
42
  interfaces.each do |ni|
71
43
  next if ni.interface_type == :host_only
@@ -76,7 +48,27 @@ module Vagrant
76
48
  true if matching_network?(ni, net_options)
77
49
  end
78
50
 
79
- raise ActionException.new(:network_collides) if result
51
+ return false if result
52
+ end
53
+
54
+ true
55
+ end
56
+
57
+ def enable_network?
58
+ !@env.env.config.vm.network_options.compact.empty?
59
+ end
60
+
61
+ # Enables and assigns the host only network to the proper
62
+ # adapter on the VM, and saves the adapter.
63
+ def assign_network
64
+ @env.logger.info "Preparing host only network..."
65
+
66
+ @env.env.config.vm.network_options.compact.each do |network_options|
67
+ adapter = @env["vm"].vm.network_adapters[network_options[:adapter]]
68
+ adapter.enabled = true
69
+ adapter.attachment_type = :host_only
70
+ adapter.host_interface = network_name(network_options)
71
+ adapter.save
80
72
  end
81
73
  end
82
74
 
@@ -98,10 +90,10 @@ module Vagrant
98
90
  end
99
91
  end
100
92
 
101
- raise ActionException.new(:network_not_found, :name => net_options[:name]) if net_options[:name]
93
+ return @env.error!(:network_not_found, :name => net_options[:name]) if net_options[:name]
102
94
 
103
95
  # One doesn't exist, create it.
104
- logger.info "Creating new host only network for environment..."
96
+ @env.logger.info "Creating new host only network for environment..."
105
97
 
106
98
  ni = interfaces.create
107
99
  ni.enable_static(network_ip(net_options[:ip], net_options[:netmask]),
@@ -0,0 +1,161 @@
1
+ require File.join(File.dirname(__FILE__), 'nfs_helpers')
2
+
3
+ module Vagrant
4
+ class Action
5
+ module VM
6
+ # Enables NFS based shared folders. `nfsd` must already be installed
7
+ # on the host machine, and NFS client must already be installed on
8
+ # the guest machine.
9
+ #
10
+ # This is a two part process:
11
+ #
12
+ # 1. Adds an entry to `/etc/exports` on the host machine using
13
+ # the host class to export the proper folder to the proper
14
+ # machine.
15
+ # 2. After boot, runs `mount` on the guest to mount the shared
16
+ # folder.
17
+ #
18
+ class NFS
19
+ include ExceptionCatcher
20
+ include NFSHelpers
21
+
22
+ def initialize(app,env)
23
+ @app = app
24
+ @env = env
25
+
26
+ verify_settings if nfs_enabled?
27
+ end
28
+
29
+ def call(env)
30
+ @env = env
31
+
32
+ extract_folders
33
+
34
+ if !folders.empty?
35
+ prepare_folders
36
+ clear_nfs_exports(env)
37
+ export_folders
38
+ end
39
+
40
+ return if env.error?
41
+
42
+ @app.call(env)
43
+
44
+ mount_folders if !folders.empty? && !env.error?
45
+ clear_nfs_exports(env) if env.error?
46
+ end
47
+
48
+ # Returns the folders which are to be synced via NFS.
49
+ def folders
50
+ @folders ||= {}
51
+ end
52
+
53
+ # Removes the NFS enabled shared folders from the configuration,
54
+ # so they will no longer be mounted by the actual shared folder
55
+ # task.
56
+ def extract_folders
57
+ # Load the NFS enabled shared folders
58
+ @folders = @env["config"].vm.shared_folders.inject({}) do |acc, data|
59
+ key, opts = data
60
+
61
+ if opts[:nfs]
62
+ # Duplicate the options, set the hostpath, and set disabled on the original
63
+ # options so the ShareFolders middleware doesn't try to mount it.
64
+ acc[key] = opts.dup
65
+ acc[key][:hostpath] = File.expand_path(opts[:hostpath], @env.env.root_path)
66
+ opts[:disabled] = true
67
+ end
68
+
69
+ acc
70
+ end
71
+ end
72
+
73
+ # Prepares the settings for the NFS folders, such as setting the
74
+ # options on the NFS folders.
75
+ def prepare_folders
76
+ @folders = @folders.inject({}) do |acc, data|
77
+ key, opts = data
78
+ opts[:nfs] = {} if !opts.is_a?(Hash)
79
+ opts[:map_uid] = prepare_permission(:uid, opts)
80
+ opts[:map_gid] = prepare_permission(:gid, opts)
81
+
82
+ acc[key] = opts
83
+ acc
84
+ end
85
+ end
86
+
87
+ # Prepares the UID/GID settings for a single folder.
88
+ def prepare_permission(perm, opts)
89
+ key = "map_#{perm}".to_sym
90
+ return nil if opts.has_key?(key) && opts[key].nil?
91
+
92
+ # The options on the hash get priority, then the default
93
+ # values
94
+ value = opts[key] || @env["config"].nfs.send(key)
95
+ return value if value != :auto
96
+
97
+ # Get UID/GID from folder if we've made it this far
98
+ # (value == :auto)
99
+ stat = File.stat(opts[:hostpath])
100
+ return stat.send(perm)
101
+ end
102
+
103
+ # Uses the host class to export the folders via NFS. This typically
104
+ # involves adding a line to `/etc/exports` for this VM, but it is
105
+ # up to the host class to define the specific behavior.
106
+ def export_folders
107
+ @env.logger.info "Exporting NFS shared folders..."
108
+
109
+ catch_action_exception(@env) do
110
+ @env["host"].nfs_export(guest_ip, folders)
111
+ end
112
+ end
113
+
114
+ # Uses the system class to mount the NFS folders.
115
+ def mount_folders
116
+ @env.logger.info "Mounting NFS shared folders..."
117
+
118
+ catch_action_exception(@env) do
119
+ @env["vm"].system.mount_nfs(host_ip, folders)
120
+ end
121
+ end
122
+
123
+ # Returns the IP address of the first host only network adapter
124
+ #
125
+ # @return [String]
126
+ def host_ip
127
+ interface = @env["vm"].vm.network_adapters.find do |adapter|
128
+ adapter.host_interface_object
129
+ end
130
+
131
+ return nil if !interface
132
+ interface.host_interface_object.ip_address
133
+ end
134
+
135
+ # Returns the IP address of the guest by looking at the first
136
+ # enabled host only network.
137
+ #
138
+ # @return [String]
139
+ def guest_ip
140
+ @env["config"].vm.network_options[1][:ip]
141
+ end
142
+
143
+ # Checks if there are any NFS enabled shared folders.
144
+ def nfs_enabled?
145
+ @env["config"].vm.shared_folders.each do |key, opts|
146
+ return true if opts[:nfs]
147
+ end
148
+
149
+ false
150
+ end
151
+
152
+ # Verifies that the host is set and supports NFS.
153
+ def verify_settings
154
+ return @env.error!(:nfs_host_required) if @env["host"].nil?
155
+ return @env.error!(:nfs_not_supported) if !@env["host"].nfs?
156
+ return @env.error!(:nfs_no_host_network) if @env["config"].vm.network_options.empty?
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,11 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ module NFSHelpers
5
+ def clear_nfs_exports(env)
6
+ env["host"].nfs_cleanup if env["host"]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,99 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Package
5
+ include Util
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @env = env
10
+ @env["package.output"] ||= env["config"].package.name
11
+ @env["package.include"] ||= []
12
+
13
+ env.error!(:box_file_exists, :output_file => tar_path) if File.exist?(tar_path)
14
+ end
15
+
16
+ def call(env)
17
+ @env = env
18
+
19
+ return env.error!(:package_requires_export) if !@env["export.temp_dir"]
20
+ return if !verify_included_files
21
+ compress
22
+
23
+ @app.call(env)
24
+
25
+ cleanup if env.error?
26
+ end
27
+
28
+ def cleanup
29
+ # Cleanup any packaged files if the packaging failed at some point.
30
+ File.delete(tar_path) if File.exist?(tar_path)
31
+ end
32
+
33
+ def verify_included_files
34
+ @env["package.include"].each do |file|
35
+ if !File.exist?(file)
36
+ @env.error!(:package_include_file_doesnt_exist, :filename => file)
37
+ return false
38
+ end
39
+ end
40
+
41
+ true
42
+ end
43
+
44
+ # This method copies the include files (passed in via command line)
45
+ # to the temporary directory so they are included in a sub-folder within
46
+ # the actual box
47
+ def copy_include_files
48
+ if @env["package.include"].length > 0
49
+ include_dir = File.join(@env["export.temp_dir"], "include")
50
+ FileUtils.mkdir_p(include_dir)
51
+
52
+ @env["package.include"].each do |f|
53
+ @env.logger.info "Packaging additional file: #{f}"
54
+ FileUtils.cp(f, include_dir)
55
+ end
56
+ end
57
+ end
58
+
59
+ # This method creates the auto-generated Vagrantfile at the root of the
60
+ # box. This Vagrantfile contains the MAC address so that the user doesn't
61
+ # have to worry about it.
62
+ def create_vagrantfile
63
+ File.open(File.join(@env["export.temp_dir"], "Vagrantfile"), "w") do |f|
64
+ f.write(TemplateRenderer.render("package_Vagrantfile", {
65
+ :base_mac => @env["vm"].vm.network_adapters.first.mac_address
66
+ }))
67
+ end
68
+ end
69
+
70
+ # Compress the exported file into a package
71
+ def compress
72
+ @env.logger.info "Packaging VM into #{tar_path}..."
73
+ File.open(tar_path, Platform.tar_file_options) do |tar|
74
+ Archive::Tar::Minitar::Output.open(tar) do |output|
75
+ begin
76
+ current_dir = FileUtils.pwd
77
+
78
+ copy_include_files
79
+ create_vagrantfile
80
+
81
+ FileUtils.cd(@env["export.temp_dir"])
82
+ Dir.glob(File.join(".", "**", "*")).each do |entry|
83
+ Archive::Tar::Minitar.pack_file(entry, output)
84
+ end
85
+ ensure
86
+ FileUtils.cd(current_dir)
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ # Path to the final box output file
93
+ def tar_path
94
+ File.join(FileUtils.pwd, @env["package.output"])
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,22 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Persist
5
+ def initialize(app, env)
6
+ @app = app
7
+
8
+ # Error the environment if the dotfile is not valid
9
+ env.error!(:dotfile_error, :env => env.env) if File.exist?(env.env.dotfile_path) &&
10
+ !File.file?(env.env.dotfile_path)
11
+ end
12
+
13
+ def call(env)
14
+ env.logger.info "Persisting the VM UUID (#{env["vm"].uuid})"
15
+ env.env.update_dotfile
16
+
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Provision
5
+ def initialize(app, env)
6
+ @app = app
7
+ @env = env
8
+
9
+ load_provisioner if provisioning_enabled?
10
+ end
11
+
12
+ def call(env)
13
+ @app.call(env)
14
+
15
+ if !env.error? && provisioning_enabled?
16
+ @env.logger.info "Beginning provisioning process..."
17
+ @provisioner.provision!
18
+ end
19
+ end
20
+
21
+ def provisioning_enabled?
22
+ !@env["config"].vm.provisioner.nil?
23
+ end
24
+
25
+ def load_provisioner
26
+ provisioner = @env["config"].vm.provisioner
27
+
28
+ if provisioner.is_a?(Class)
29
+ @provisioner = provisioner.new(@env)
30
+ return @env.error!(:provisioner_invalid_class) unless @provisioner.is_a?(Provisioners::Base)
31
+ elsif provisioner.is_a?(Symbol)
32
+ # We have a few hard coded provisioners for built-ins
33
+ mapping = {
34
+ :chef_solo => Provisioners::ChefSolo,
35
+ :chef_server => Provisioners::ChefServer
36
+ }
37
+
38
+ provisioner_klass = mapping[provisioner]
39
+ return @env.error!(:provisioner_unknown_type, :provisioner => provisioner.to_s) if provisioner_klass.nil?
40
+ @provisioner = provisioner_klass.new(@env)
41
+ end
42
+
43
+ @env.logger.info "Provisioning enabled with #{@provisioner.class}"
44
+ @provisioner.prepare
45
+ @provisioner
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end