vagrant-parallels 0.2.1 → 0.2.2.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -13
  3. data/.travis.yml +1 -0
  4. data/README.md +43 -54
  5. data/config/i18n-tasks.yml.erb +1 -1
  6. data/debug.log +941 -0
  7. data/lib/vagrant-parallels/action.rb +0 -7
  8. data/lib/vagrant-parallels/action/check_accessible.rb +1 -1
  9. data/lib/vagrant-parallels/action/check_guest_tools.rb +10 -2
  10. data/lib/vagrant-parallels/action/clear_network_interfaces.rb +1 -1
  11. data/lib/vagrant-parallels/action/customize.rb +6 -4
  12. data/lib/vagrant-parallels/action/export.rb +56 -12
  13. data/lib/vagrant-parallels/action/import.rb +49 -30
  14. data/lib/vagrant-parallels/action/network.rb +137 -48
  15. data/lib/vagrant-parallels/action/package_config_files.rb +0 -12
  16. data/lib/vagrant-parallels/action/prepare_nfs_valid_ids.rb +1 -1
  17. data/lib/vagrant-parallels/action/set_name.rb +2 -2
  18. data/lib/vagrant-parallels/config.rb +11 -2
  19. data/lib/vagrant-parallels/driver/base.rb +281 -0
  20. data/lib/vagrant-parallels/driver/meta.rb +138 -0
  21. data/lib/vagrant-parallels/driver/{prl_ctl.rb → pd_8.rb} +116 -256
  22. data/lib/vagrant-parallels/driver/pd_9.rb +417 -0
  23. data/lib/vagrant-parallels/errors.rb +15 -7
  24. data/lib/vagrant-parallels/plugin.rb +7 -7
  25. data/lib/vagrant-parallels/provider.rb +33 -3
  26. data/lib/vagrant-parallels/version.rb +1 -1
  27. data/locales/en.yml +30 -16
  28. data/test/unit/base.rb +1 -5
  29. data/test/unit/config_test.rb +13 -2
  30. data/test/unit/driver/pd_8_test.rb +196 -0
  31. data/test/unit/driver/pd_9_test.rb +196 -0
  32. data/test/unit/locales/locales_test.rb +1 -1
  33. data/test/unit/support/shared/parallels_context.rb +2 -2
  34. data/test/unit/support/shared/pd_driver_examples.rb +243 -0
  35. data/test/unit/synced_folder_test.rb +37 -0
  36. data/vagrant-parallels.gemspec +5 -5
  37. metadata +39 -32
  38. data/lib/vagrant-parallels/action/match_mac_address.rb +0 -28
  39. data/lib/vagrant-parallels/action/register_template.rb +0 -24
  40. data/lib/vagrant-parallels/action/unregister_template.rb +0 -26
  41. data/test/support/isolated_environment.rb +0 -46
  42. data/test/support/tempdir.rb +0 -43
  43. data/test/unit/driver/prl_ctl_test.rb +0 -148
@@ -1,28 +0,0 @@
1
- module VagrantPlugins
2
- module Parallels
3
- module Action
4
- class MatchMACAddress
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- raise Vagrant::Errors::VMBaseMacNotSpecified if !env[:machine].config.vm.base_mac
11
-
12
- env[:ui].info I18n.t("vagrant_parallels.actions.vm.match_mac.matching")
13
-
14
- base_mac = env[:machine].config.vm.base_mac
15
- # Generate new base mac if the specified address is already in use
16
- if env[:machine].provider.driver.mac_in_use?(base_mac)
17
- env[:ui].info I18n.t("vagrant_parallels.actions.vm.match_mac.generate")
18
- env[:machine].provider.driver.set_mac_address('auto')
19
- else
20
- env[:machine].provider.driver.set_mac_address(base_mac)
21
- end
22
-
23
- @app.call(env)
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,24 +0,0 @@
1
- module VagrantPlugins
2
- module Parallels
3
- module Action
4
- class RegisterTemplate
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- pvm_glob = Pathname.glob(env[:machine].box.directory.join('*.pvm')).first
11
- # TODO: Handle error cases better, throw a Vagrant error and not a stack trace etc.
12
- pvm_file = File.realpath pvm_glob.to_s
13
-
14
- unless env[:machine].provider.driver.registered?(pvm_file)
15
- env[:machine].provider.driver.register(pvm_file.to_s)
16
- end
17
- # Call the next if we have one (but we shouldn't, since this
18
- # middleware is built to run with the Call-type middlewares)
19
- @app.call(env)
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,26 +0,0 @@
1
- module VagrantPlugins
2
- module Parallels
3
- module Action
4
- class UnregisterTemplate
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- template_path = File.realpath(Pathname.glob(
11
- env[:machine].box.directory.join('*.pvm')
12
- ).first)
13
-
14
- template_uuid = env[:machine].provider.driver.read_all_paths[template_path]
15
-
16
- if env[:machine].provider.driver.registered?(template_path)
17
- env[:machine].provider.driver.unregister(template_uuid)
18
- end
19
- # Call the next if we have one (but we shouldn't, since this
20
- # middleware is built to run with the Call-type middlewares)
21
- @app.call(env)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,46 +0,0 @@
1
- require "fileutils"
2
- require "pathname"
3
-
4
- require "log4r"
5
-
6
- require "support/tempdir"
7
-
8
- # This class manages an isolated environment for Vagrant to
9
- # run in. It creates a temporary directory to act as the
10
- # working directory as well as sets a custom home directory.
11
- #
12
- # This class also provides various helpers to create Vagrantfiles,
13
- # boxes, etc.
14
- class IsolatedEnvironment
15
- attr_reader :homedir
16
- attr_reader :workdir
17
-
18
- # Initializes an isolated environment. You can pass in some
19
- # options here to configure runing custom applications in place
20
- # of others as well as specifying environmental variables.
21
- #
22
- # @param [Hash] apps A mapping of application name (such as "vagrant")
23
- # to an alternate full path to the binary to run.
24
- # @param [Hash] env Additional environmental variables to inject
25
- # into the execution environments.
26
- def initialize
27
- @logger = Log4r::Logger.new("test::isolated_environment")
28
-
29
- # Create a temporary directory for our work
30
- @tempdir = Tempdir.new("vagrant")
31
- @logger.info("Initialize isolated environment: #{@tempdir.path}")
32
-
33
- # Setup the home and working directories
34
- @homedir = Pathname.new(File.join(@tempdir.path, "home"))
35
- @workdir = Pathname.new(File.join(@tempdir.path, "work"))
36
-
37
- @homedir.mkdir
38
- @workdir.mkdir
39
- end
40
-
41
- # This closes the environment by cleaning it up.
42
- def close
43
- @logger.info("Removing isolated environment: #{@tempdir.path}")
44
- FileUtils.rm_rf(@tempdir.path)
45
- end
46
- end
@@ -1,43 +0,0 @@
1
- require 'fileutils'
2
- require 'tempfile'
3
-
4
- # This class provides an easy way of creating a temporary
5
- # directory and having it removed when the application exits.
6
- class Tempdir
7
- attr_reader :path
8
-
9
- def initialize(basename="vagrant")
10
- @path = nil
11
-
12
- # Loop and attempt to create a temporary directory until
13
- # it succeeds.
14
- while @path.nil?
15
- file = Tempfile.new(basename)
16
- @path = file.path
17
- file.unlink
18
-
19
- begin
20
- Dir.mkdir(@path)
21
- rescue
22
- @path = nil
23
- end
24
- end
25
-
26
- # Setup a finalizer to delete the directory. This is the same way
27
- # that Tempfile and friends do this...
28
- @cleanup_proc = lambda do
29
- FileUtils.rm_rf(@path) if File.directory?(@path)
30
- end
31
-
32
- ObjectSpace.define_finalizer(self, @cleanup_proc)
33
- end
34
-
35
- # This deletes the temporary directory.
36
- def unlink
37
- # Delete the directory
38
- @cleanup_proc.call
39
-
40
- # Undefine the finalizer since we're all cleaned up
41
- ObjectSpace.undefine_finalizer(self)
42
- end
43
- end
@@ -1,148 +0,0 @@
1
- require_relative "../base"
2
-
3
- describe VagrantPlugins::Parallels::Driver::PrlCtl do
4
- include_context "parallels"
5
-
6
- subject { VagrantPlugins::Parallels::Driver::PrlCtl.new(uuid) }
7
-
8
- describe "compact" do
9
- it "compacts the VM disk images" do
10
- pending "Should have possibility to compact more than one hdd"
11
- end
12
- end
13
-
14
- describe "create_host_only_network" do
15
- it "creates host-only NIC"
16
- end
17
-
18
- describe "export" do
19
- tpl_name = "new_template_name"
20
- tpl_uuid = "12345-hfgs-3456-hste"
21
-
22
- it "exports VM to template" do
23
- subject.stub(:read_settings).with(tpl_name).
24
- and_return({"ID" => tpl_uuid})
25
-
26
- subprocess.should_receive(:execute).
27
- with("prlctl", "clone", uuid, "--name", an_instance_of(String), "--template", "--dst",
28
- an_instance_of(String), an_instance_of(Hash)).
29
- and_return(subprocess_result(stdout: "The VM has been successfully cloned"))
30
- subject.export("/path/to/template", tpl_name).should == tpl_uuid
31
- end
32
- end
33
-
34
- describe "clear_shared_folders" do
35
- shf_hash = {"enabled" => true, "shf_name_1" => {}, "shf_name_2" => {}}
36
- it "deletes every shared folder assigned to the VM" do
37
- subject.stub(:read_settings).and_return({"Host Shared Folders" => shf_hash})
38
-
39
- subprocess.should_receive(:execute).exactly(2).times.
40
- with("prlctl", "set", uuid, "--shf-host-del", an_instance_of(String), an_instance_of(Hash)).
41
- and_return(subprocess_result(stdout: "Shared folder deleted"))
42
- subject.clear_shared_folders
43
- end
44
- end
45
-
46
- describe "halt" do
47
- it "stops the VM" do
48
- subprocess.should_receive(:execute).
49
- with("prlctl", "stop", uuid, an_instance_of(Hash)).
50
- and_return(subprocess_result(stdout: "VM has been halted gracefully"))
51
- subject.halt
52
- end
53
-
54
- it "stops the VM force" do
55
- subprocess.should_receive(:execute).
56
- with("prlctl", "stop", uuid, "--kill", an_instance_of(Hash)).
57
- and_return(subprocess_result(stdout: "VM has been halted forcibly"))
58
- subject.halt(force=true)
59
- end
60
- end
61
-
62
- describe "mac_in_use?" do
63
- vm_1 = {
64
- 'Hardware' => {
65
- 'net0' => {'mac' => '001C42BB5901'},
66
- 'net1' => {'mac' => '001C42BB5902'},
67
- }
68
- }
69
- vm_2 = {
70
- 'Hardware' => {
71
- 'net0' => {'mac' => '001C42BB5903'},
72
- 'net1' => {'mac' => '001C42BB5904'},
73
- }
74
- }
75
-
76
- it "checks the MAC address is already in use" do
77
- subject.stub(:read_all_info).and_return([vm_1, vm_2])
78
-
79
- subject.mac_in_use?('00:1c:42:bb:59:01').should be_true
80
- subject.mac_in_use?('00:1c:42:bb:59:02').should be_false
81
- subject.mac_in_use?('00:1c:42:bb:59:03').should be_true
82
- subject.mac_in_use?('00:1c:42:bb:59:04').should be_false
83
- end
84
- end
85
-
86
- describe "set_name" do
87
- it "sets new name for the VM" do
88
- subprocess.should_receive(:execute).
89
- with("prlctl", "set", uuid, '--name', an_instance_of(String), an_instance_of(Hash)).
90
- and_return(subprocess_result(stdout: "Settings applied"))
91
-
92
- subject.set_name('new_vm_name')
93
- end
94
- end
95
-
96
- describe "set_mac_address" do
97
- it "sets base MAC address to the Shared network adapter" do
98
- subprocess.should_receive(:execute).exactly(2).times.
99
- with("prlctl", "set", uuid, '--device-set', 'net0', '--type', 'shared', '--mac',
100
- an_instance_of(String), an_instance_of(Hash)).
101
- and_return(subprocess_result(stdout: "Settings applied"))
102
-
103
- subject.set_mac_address('001C42DD5902')
104
- subject.set_mac_address('auto')
105
- end
106
- end
107
-
108
- describe "start" do
109
- it "starts the VM" do
110
- subprocess.should_receive(:execute).
111
- with("prlctl", "start", uuid, an_instance_of(Hash)).
112
- and_return(subprocess_result(stdout: "VM started"))
113
- subject.start
114
- end
115
- end
116
-
117
- describe "suspend" do
118
- it "suspends the VM" do
119
- subprocess.should_receive(:execute).
120
- with("prlctl", "suspend", uuid, an_instance_of(Hash)).
121
- and_return(subprocess_result(stdout: "VM suspended"))
122
- subject.suspend
123
- end
124
- end
125
-
126
- describe "unregister" do
127
- it "suspends the VM" do
128
- subprocess.should_receive(:execute).
129
- with("prlctl", "unregister", an_instance_of(String), an_instance_of(Hash)).
130
- and_return(subprocess_result(stdout: "Specified VM unregistered"))
131
- subject.unregister("template_or_vm_uuid")
132
- end
133
- end
134
-
135
- describe "version" do
136
- it "parses the version from output" do
137
- subject.version.should match(/(#{parallels_version}[\d\.]+)/)
138
- end
139
-
140
- it "rises ParallelsInstallIncomplete exception when output is invalid" do
141
- subprocess.should_receive(:execute).
142
- with("prlctl", "--version", an_instance_of(Hash)).
143
- and_return(subprocess_result(stdout: "Some incorrect value has been returned!"))
144
- expect { subject.version }.
145
- to raise_error(VagrantPlugins::Parallels::Errors::ParallelsInstallIncomplete)
146
- end
147
- end
148
- end