vagrant-skytap 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -0
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +0 -3
  5. data/lib/vagrant-skytap/action/compose_environment.rb +0 -3
  6. data/lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb +0 -1
  7. data/lib/vagrant-skytap/action/prepare_nfs_valid_ids.rb +3 -2
  8. data/lib/vagrant-skytap/action/wait_for_communicator.rb +0 -1
  9. data/lib/vagrant-skytap/action.rb +0 -1
  10. data/lib/vagrant-skytap/api/busyable.rb +1 -1
  11. data/lib/vagrant-skytap/api/client.rb +0 -1
  12. data/lib/vagrant-skytap/api/interface.rb +0 -1
  13. data/lib/vagrant-skytap/api/public_ip.rb +1 -2
  14. data/lib/vagrant-skytap/api/published_service.rb +2 -3
  15. data/lib/vagrant-skytap/api/vpn.rb +1 -2
  16. data/lib/vagrant-skytap/command/publish_url/root.rb +1 -1
  17. data/lib/vagrant-skytap/command/up.rb +10 -4
  18. data/lib/vagrant-skytap/core_ext/object/blank.rb +0 -22
  19. data/lib/vagrant-skytap/core_ext/try.rb +0 -22
  20. data/lib/vagrant-skytap/hosts/common/cap/ssh_tunnel.rb +0 -1
  21. data/lib/vagrant-skytap/plugin.rb +1 -1
  22. data/lib/vagrant-skytap/util/compile_forwarded_ports.rb +1 -1
  23. data/lib/vagrant-skytap/version.rb +1 -1
  24. data/lib/vagrant-skytap.rb +0 -2
  25. data/spec/unit/actions/compose_environment_spec.rb +0 -3
  26. data/spec/unit/actions/update_hardware_spec.rb +0 -1
  27. data/spec/unit/base.rb +1 -8
  28. data/spec/unit/config_spec.rb +0 -4
  29. data/spec/unit/environment_spec.rb +14 -23
  30. data/spec/unit/forwarded_port_spec.rb +0 -2
  31. data/spec/unit/prepare_collision_params_spec.rb +0 -14
  32. data/spec/unit/publish_set_spec.rb +7 -15
  33. data/spec/unit/setup_helper_spec.rb +28 -48
  34. data/spec/unit/support/api_responses/empty_environment.json +1 -1
  35. data/spec/unit/support/shared/rest_api_context.rb +3 -0
  36. data/spec/unit/support/shared/skytap_context.rb +14 -0
  37. data/spec/unit/vm_spec.rb +8 -15
  38. data/vagrant-skytap.gemspec +4 -4
  39. metadata +7 -20
  40. data/.hgignore +0 -22
  41. data/.project +0 -11
  42. data/.rspec +0 -1
  43. data/spec/acceptance/base.rb +0 -24
  44. data/spec/acceptance/provider/halt_spec.rb +0 -25
  45. data/spec/acceptance/provider/up_spec.rb +0 -62
  46. data/spec/acceptance/shared/context_skytap.rb +0 -25
  47. data/spec/support/isolated_environment.rb +0 -67
  48. data/spec/unit/support/dummy_communicator.rb +0 -105
  49. data/spec/unit/support/dummy_provider.rb +0 -63
  50. data/spec/unit/support/isolated_environment.rb +0 -239
  51. data/spec/unit/support/shared/action_synced_folders_context.rb +0 -37
  52. data/spec/unit/support/shared/base_context.rb +0 -138
  53. data/spec/unit/support/shared/capability_helpers_context.rb +0 -51
  54. data/spec/unit/support/shared/plugin_command_context.rb +0 -34
  55. data/vagrant-spec.config.rb +0 -32
@@ -1,25 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- shared_examples 'provider/halt' do |provider, options|
24
-
25
- end
@@ -1,62 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- # This tests that an instance can be upped correctly
24
- shared_examples 'provider/up' do |provider, options|
25
- if !options[:box]
26
- raise ArgumentError,
27
- "box option must be specified for provider: #{provider}"
28
- end
29
-
30
- include_context 'acceptance'
31
-
32
- before do
33
- environment.skeleton('generic')
34
- #assert_execute('vagrant', 'box', 'add', 'basic', options[:box])
35
- end
36
-
37
- after do
38
- assert_execute('vagrant', 'destroy', '--force')
39
- end
40
-
41
- it 'should bring up the machine and halt it' do
42
- status("Test: machine can be brought up, parallel by default")
43
- up_result = execute("vagrant", "up")
44
- expect(up_result).to exit_with(0)
45
-
46
- status("Test: machine is running after up")
47
- echo_result = execute("vagrant", "ssh", "-c", "echo foo")
48
- expect(echo_result).to exit_with(0)
49
- expect(echo_result.stdout).to match(/foo\n$/)
50
- end
51
-
52
- it 'should bring up the machine and halt it' do
53
- status("Test: machine can be brought up no parallel")
54
- up_result = execute("vagrant", "up", "--no-parallel")
55
- expect(up_result).to exit_with(0)
56
-
57
- status("Test: machine is running after up")
58
- echo_result = execute("vagrant", "ssh", "-c", "echo foo")
59
- expect(echo_result).to exit_with(0)
60
- expect(echo_result.stdout).to match(/foo\n$/)
61
- end
62
- end
@@ -1,25 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- shared_context "provider-context/skytap" do
24
-
25
- end
@@ -1,67 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- require "fileutils"
24
- require "pathname"
25
- require "tmpdir"
26
-
27
- require "log4r"
28
-
29
- # This class manages an isolated environment for Vagrant to
30
- # run in. It creates a temporary directory to act as the
31
- # working directory as well as sets a custom home directory.
32
- #
33
- # This class also provides various helpers to create Vagrantfiles,
34
- # boxes, etc.
35
- class IsolatedEnvironment
36
- attr_reader :homedir
37
- attr_reader :workdir
38
-
39
- # Initializes an isolated environment. You can pass in some
40
- # options here to configure runing custom applications in place
41
- # of others as well as specifying environmental variables.
42
- #
43
- # @param [Hash] apps A mapping of application name (such as "vagrant")
44
- # to an alternate full path to the binary to run.
45
- # @param [Hash] env Additional environmental variables to inject
46
- # into the execution environments.
47
- def initialize
48
- @logger = Log4r::Logger.new("test::isolated_environment")
49
-
50
- # Create a temporary directory for our work
51
- @tempdir = Dir.mktmpdir("vagrant")
52
- @logger.info("Initialize isolated environment: #{@tempdir}")
53
-
54
- # Setup the home and working directories
55
- @homedir = Pathname.new(File.join(@tempdir, "home"))
56
- @workdir = Pathname.new(File.join(@tempdir, "work"))
57
-
58
- @homedir.mkdir
59
- @workdir.mkdir
60
- end
61
-
62
- # This closes the environment by cleaning it up.
63
- def close
64
- @logger.info("Removing isolated environment: #{@tempdir}")
65
- FileUtils.rm_rf(@tempdir)
66
- end
67
- end
@@ -1,105 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- module VagrantTests
24
- module DummyCommunicator
25
- class Communicator < Vagrant.plugin("2", :communicator)
26
- def ready?
27
- true
28
- end
29
-
30
- attr_reader :known_commands
31
-
32
- def initialize(machine)
33
- @known_commands = Hash.new do |hash, key|
34
- hash[key] = { expected: 0, received: 0, response: nil }
35
- end
36
- end
37
-
38
- def expected_commands
39
- known_commands.select do |command, info|
40
- info[:expected] > 0
41
- end
42
- end
43
-
44
- def received_commands
45
- known_commands.select do |command, info|
46
- info[:received] > 0
47
- end.keys
48
- end
49
-
50
- def stub_command(command, response)
51
- known_commands[command][:response] = response
52
- end
53
-
54
- def expect_command(command)
55
- known_commands[command][:expected] += 1
56
- end
57
-
58
- def received_summary
59
- received_commands.map { |cmd| " - #{cmd}" }.unshift('received:').join("\n")
60
- end
61
-
62
- def verify_expectations!
63
- expected_commands.each do |command, info|
64
- if info[:expected] != info[:received]
65
- fail([
66
- "expected to receive '#{command}' #{info[:expected]} times",
67
- "got #{info[:received]} times instead",
68
- received_summary
69
- ].join("\n"))
70
- end
71
- end
72
- end
73
-
74
- def execute(command, opts=nil)
75
- known = known_commands[command]
76
- known[:received] += 1
77
- response = known[:response]
78
- return unless response
79
-
80
- if block_given?
81
- [:stdout, :stderr].each do |type|
82
- Array(response[type]).each do |line|
83
- yield type, line
84
- end
85
- end
86
- end
87
-
88
- if response[:raise]
89
- raise response[:raise]
90
- end
91
-
92
- response[:exit_code]
93
- end
94
-
95
- def sudo(command, opts=nil, &block)
96
- execute(command, opts, &block)
97
- end
98
-
99
- def test(command, opts=nil)
100
- execute(command, opts) == 0
101
- end
102
- end
103
- end
104
- end
105
-
@@ -1,63 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- module VagrantTests
24
- class DummyProviderPlugin < Vagrant.plugin("2")
25
- name "Dummy Provider"
26
- description <<-EOF
27
- This creates a provider named "dummy" which does nothing, so that
28
- the unit tests aren't reliant on VirtualBox (or any other real
29
- provider for that matter).
30
- EOF
31
-
32
- provider(:dummy) { DummyProvider }
33
- end
34
-
35
- class DummyProvider < Vagrant.plugin("2", :provider)
36
- def initialize(machine)
37
- @machine = machine
38
- end
39
-
40
- def state=(id)
41
- state_file.open("w+") do |f|
42
- f.write(id.to_s)
43
- end
44
- end
45
-
46
- def state
47
- if !state_file.file?
48
- new_state = @machine.id
49
- new_state = Vagrant::MachineState::NOT_CREATED_ID if !new_state
50
- self.state = new_state
51
- end
52
-
53
- state_id = state_file.read.to_sym
54
- Vagrant::MachineState.new(state_id, state_id.to_s, state_id.to_s)
55
- end
56
-
57
- protected
58
-
59
- def state_file
60
- @machine.data_dir.join("dummy_state")
61
- end
62
- end
63
- end
@@ -1,239 +0,0 @@
1
- # Copyright (c) 2014-2016 Skytap, Inc.
2
- #
3
- # The MIT License (MIT)
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
- # DEALINGS IN THE SOFTWARE.
22
-
23
- require "fileutils"
24
- require "pathname"
25
- require "tempfile"
26
- require "tmpdir"
27
-
28
- require "json"
29
- require "log4r"
30
-
31
- require "vagrant/util/platform"
32
- require "vagrant/util/subprocess"
33
-
34
- require "support/isolated_environment"
35
-
36
- module Unit
37
- class IsolatedEnvironment < ::IsolatedEnvironment
38
- def create_vagrant_env(options=nil)
39
- options = {
40
- cwd: @workdir,
41
- home_path: @homedir
42
- }.merge(options || {})
43
-
44
- Vagrant::Environment.new(options)
45
- end
46
-
47
- # This creates a file in the isolated environment. By default this file
48
- # will be created in the working directory of the isolated environment.
49
- def file(name, contents)
50
- @workdir.join(name).open("w+") do |f|
51
- f.write(contents)
52
- end
53
- end
54
-
55
- def vagrantfile(contents, root=nil)
56
- root ||= @workdir
57
- root.join("Vagrantfile").open("w+") do |f|
58
- f.write(contents)
59
- end
60
- end
61
-
62
- def box(name, vagrantfile_contents="")
63
- # Create the box directory
64
- box_dir = boxes_dir.join(name)
65
- box_dir.mkpath
66
-
67
- # Create the "box.ovf" file because that is how Vagrant heuristically
68
- # determines a box is a V1 box.
69
- box_dir.join("box.ovf").open("w") { |f| f.write("") }
70
-
71
- # Populate the vagrantfile
72
- vagrantfile(vagrantfile_contents, box_dir)
73
-
74
- # Return the directory
75
- box_dir
76
- end
77
-
78
- # Create an alias because "box" makes a V1 box, so "box1"
79
- alias :box1 :box
80
-
81
- # Creates a fake box to exist in this environment.
82
- #
83
- # @param [String] name Name of the box
84
- # @param [Symbol] provider Provider the box was built for.
85
- # @return [Pathname] Path to the box directory.
86
- def box2(name, provider, options=nil)
87
- # Default options
88
- options = {
89
- vagrantfile: ""
90
- }.merge(options || {})
91
-
92
- # Make the box directory
93
- box_dir = boxes_dir.join(name, provider.to_s)
94
- box_dir.mkpath
95
-
96
- # Create a metadata.json file
97
- box_metadata_file = box_dir.join("metadata.json")
98
- box_metadata_file.open("w") do |f|
99
- f.write(JSON.generate({
100
- provider: provider.to_s
101
- }))
102
- end
103
-
104
- # Create a Vagrantfile
105
- box_vagrantfile = box_dir.join("Vagrantfile")
106
- box_vagrantfile.open("w") do |f|
107
- f.write(options[:vagrantfile])
108
- end
109
-
110
- # Return the box directory
111
- box_dir
112
- end
113
-
114
- # Creates a fake box to exist in this environment according
115
- # to the "gen-3" box format.
116
- #
117
- # @param [String] name
118
- # @param [String] version
119
- # @param [String] provider
120
- # @return [Pathname]
121
- def box3(name, version, provider, **opts)
122
- # Create the directory for the box
123
- box_dir = boxes_dir.join(name, version, provider.to_s)
124
- box_dir.mkpath
125
-
126
- # Create the metadata.json for it
127
- box_metadata_file = box_dir.join("metadata.json")
128
- box_metadata_file.open("w") do |f|
129
- f.write(JSON.generate({
130
- provider: provider.to_s
131
- }))
132
- end
133
-
134
- # Create a Vagrantfile
135
- if opts[:vagrantfile]
136
- box_vagrantfile = box_dir.join("Vagrantfile")
137
- box_vagrantfile.open("w") do |f|
138
- f.write(opts[:vagrantfile])
139
- end
140
- end
141
-
142
- # Create the metadata URL
143
- if opts[:metadata_url]
144
- boxes_dir.join(name, "metadata_url").open("w") do |f|
145
- f.write(opts[:metadata_url])
146
- end
147
- end
148
-
149
- box_dir
150
- end
151
-
152
- # This creates a "box" file that is a valid V1 box.
153
- #
154
- # @return [Pathname] Path to the newly created box.
155
- def box1_file
156
- # Create a temporary directory to store our data we will tar up
157
- td_source = Dir.mktmpdir
158
- td_dest = Dir.mktmpdir
159
-
160
- # Store the temporary directory so it is not deleted until
161
- # this instance is garbage collected.
162
- @_box2_file_temp ||= []
163
- @_box2_file_temp << td_dest
164
-
165
- # The source as a Pathname, which is easier to work with
166
- source = Pathname.new(td_source)
167
-
168
- # The destination file
169
- result = Pathname.new(td_dest).join("temporary.box")
170
-
171
- # Put a "box.ovf" in there.
172
- source.join("box.ovf").open("w") do |f|
173
- f.write("FOO!")
174
- end
175
-
176
- Dir.chdir(source) do
177
- # Find all the files in our current directory and tar it up!
178
- files = Dir.glob(File.join(".", "**", "*"))
179
-
180
- # Package!
181
- Vagrant::Util::Subprocess.execute("bsdtar", "-czf", result.to_s, *files)
182
- end
183
-
184
- # Resulting box
185
- result
186
- end
187
-
188
- # This creates a "box" file with the given provider.
189
- #
190
- # @param [Symbol] provider Provider for the box.
191
- # @return [Pathname] Path to the newly created box.
192
- def box2_file(provider, options=nil)
193
- options ||= {}
194
-
195
- # This is the metadata we want to store in our file
196
- metadata = {
197
- "type" => "v2_box",
198
- "provider" => provider
199
- }.merge(options[:metadata] || {})
200
-
201
- # Create a temporary directory to store our data we will tar up
202
- td_source = Dir.mktmpdir
203
- td_dest = Dir.mktmpdir
204
-
205
- # Store the temporary directory so it is not deleted until
206
- # this instance is garbage collected.
207
- @_box2_file_temp ||= []
208
- @_box2_file_temp << td_dest
209
-
210
- # The source as a Pathname, which is easier to work with
211
- source = Pathname.new(td_source)
212
-
213
- # The destination file
214
- result = Pathname.new(td_dest).join("temporary.box")
215
-
216
- # Put the metadata.json in here.
217
- source.join("metadata.json").open("w") do |f|
218
- f.write(JSON.generate(metadata))
219
- end
220
-
221
- Dir.chdir(source) do
222
- # Find all the files in our current directory and tar it up!
223
- files = Dir.glob(File.join(".", "**", "*"))
224
-
225
- # Package!
226
- Vagrant::Util::Subprocess.execute("bsdtar", "-czf", result.to_s, *files)
227
- end
228
-
229
- # Resulting box
230
- result
231
- end
232
-
233
- def boxes_dir
234
- dir = @homedir.join("boxes")
235
- dir.mkpath
236
- dir
237
- end
238
- end
239
- end