vagrant-veertu 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +31 -0
  5. data/Rakefile +5 -0
  6. data/lib/vagrant-veertu.rb +18 -0
  7. data/lib/vagrant-veertu/action.rb +330 -0
  8. data/lib/vagrant-veertu/action/boot.rb +21 -0
  9. data/lib/vagrant-veertu/action/check_accessible.rb +22 -0
  10. data/lib/vagrant-veertu/action/check_created.rb +21 -0
  11. data/lib/vagrant-veertu/action/check_running.rb +21 -0
  12. data/lib/vagrant-veertu/action/check_veertu.rb +22 -0
  13. data/lib/vagrant-veertu/action/clear_forwarded_ports.rb +20 -0
  14. data/lib/vagrant-veertu/action/clear_network_interfaces.rb +31 -0
  15. data/lib/vagrant-veertu/action/created.rb +20 -0
  16. data/lib/vagrant-veertu/action/customize.rb +44 -0
  17. data/lib/vagrant-veertu/action/destroy.rb +19 -0
  18. data/lib/vagrant-veertu/action/discard_state.rb +20 -0
  19. data/lib/vagrant-veertu/action/export.rb +41 -0
  20. data/lib/vagrant-veertu/action/forced_halt.rb +25 -0
  21. data/lib/vagrant-veertu/action/forward_ports.rb +91 -0
  22. data/lib/vagrant-veertu/action/import.rb +96 -0
  23. data/lib/vagrant-veertu/action/is_paused.rb +20 -0
  24. data/lib/vagrant-veertu/action/is_running.rb +20 -0
  25. data/lib/vagrant-veertu/action/is_saved.rb +20 -0
  26. data/lib/vagrant-veertu/action/message_already_running.rb +16 -0
  27. data/lib/vagrant-veertu/action/message_not_created.rb +16 -0
  28. data/lib/vagrant-veertu/action/message_not_running.rb +16 -0
  29. data/lib/vagrant-veertu/action/message_will_not_destroy.rb +17 -0
  30. data/lib/vagrant-veertu/action/network.rb +556 -0
  31. data/lib/vagrant-veertu/action/network_fix_ipv6.rb +81 -0
  32. data/lib/vagrant-veertu/action/package.rb +44 -0
  33. data/lib/vagrant-veertu/action/package_vagrantfile.rb +33 -0
  34. data/lib/vagrant-veertu/action/prepare_forwarded_port_collision_params.rb +35 -0
  35. data/lib/vagrant-veertu/action/prepare_nfs_settings.rb +119 -0
  36. data/lib/vagrant-veertu/action/prepare_nfs_valid_ids.rb +17 -0
  37. data/lib/vagrant-veertu/action/resume.rb +21 -0
  38. data/lib/vagrant-veertu/action/sane_defaults.rb +89 -0
  39. data/lib/vagrant-veertu/action/set_name.rb +55 -0
  40. data/lib/vagrant-veertu/action/setup_package_files.rb +51 -0
  41. data/lib/vagrant-veertu/action/snapshot_delete.rb +32 -0
  42. data/lib/vagrant-veertu/action/snapshot_restore.rb +28 -0
  43. data/lib/vagrant-veertu/action/snapshot_save.rb +25 -0
  44. data/lib/vagrant-veertu/action/suspend.rb +20 -0
  45. data/lib/vagrant-veertu/cap.rb +23 -0
  46. data/lib/vagrant-veertu/cap/public_address.rb +15 -0
  47. data/lib/vagrant-veertu/config.rb +199 -0
  48. data/lib/vagrant-veertu/driver/base.rb +240 -0
  49. data/lib/vagrant-veertu/driver/meta.rb +143 -0
  50. data/lib/vagrant-veertu/driver/version_5_0.rb +284 -0
  51. data/lib/vagrant-veertu/errors.rb +18 -0
  52. data/lib/vagrant-veertu/model/forwarded_port.rb +70 -0
  53. data/lib/vagrant-veertu/plugin.rb +76 -0
  54. data/lib/vagrant-veertu/provider.rb +121 -0
  55. data/lib/vagrant-veertu/synced_folder.rb +120 -0
  56. data/lib/vagrant-veertu/util/compile_forwarded_ports.rb +35 -0
  57. data/lib/vagrant-veertu/version.rb +5 -0
  58. data/locales/en.yml +19 -0
  59. data/vagrant-veertu.gemspec +22 -0
  60. metadata +130 -0
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class CheckAccessible
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env[:machine].state.id == :inaccessible
11
+ # The VM we are attempting to manipulate is inaccessible. This
12
+ # is a very bad situation and can only be fixed by the user. It
13
+ # also prohibits us from actually doing anything with the virtual
14
+ # machine, so we raise an error.
15
+ raise Vagrant::Errors::VMInaccessible
16
+ end
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ # This middleware checks that the VM is created, and raises an exception
5
+ # if it is not, notifying the user that creation is required.
6
+ class CheckCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ if env[:machine].state.id == :not_created
13
+ raise Vagrant::Errors::VMNotCreatedError
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ # This middleware checks that the VM is running, and raises an exception
5
+ # if it is not, notifying the user that the VM must be running.
6
+ class CheckRunning
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ if env[:machine].state.id != :running
13
+ raise Vagrant::Errors::VMNotRunningError
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ # Checks that VirtualBox is installed and ready to be used.
5
+ class CheckVeertu
6
+ def initialize(app, env)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ # This verifies that VirtualBox is installed and the driver is
12
+ # ready to function. If not, then an exception will be raised
13
+ # which will break us out of execution of the middleware sequence.
14
+ Driver::Meta.new.verify!
15
+
16
+ # Carry on.
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class ClearForwardedPorts
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if !env[:machine].provider.driver.read_forwarded_ports.empty?
11
+ env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting")
12
+ env[:machine].provider.driver.clear_forwarded_ports
13
+ end
14
+
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class ClearNetworkInterfaces
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ # Create the adapters array to make all adapters nothing.
11
+ # We do adapters 2 to 8 because that is every built-in adapter
12
+ # excluding the NAT adapter on port 1 which Vagrant always
13
+ # expects to exist.
14
+ adapters = []
15
+ 2.upto(env[:machine].provider.driver.max_network_adapters).each do |i|
16
+ adapters << {
17
+ adapter: i,
18
+ type: :none
19
+ }
20
+ end
21
+
22
+ # "Enable" all the adapters we setup.
23
+ env[:ui].info I18n.t("vagrant.actions.vm.clear_network_interfaces.deleting")
24
+ #env[:machine].provider.driver.enable_adapters(adapters)
25
+
26
+ @app.call(env)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class Created
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ # Set the result to be true if the machine is created.
11
+ env[:result] = env[:machine].state.id != :not_created
12
+
13
+ # Call the next if we have one (but we shouldn't, since this
14
+ # middleware is built to run with the Call-type middlewares)
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class Customize
5
+ def initialize(app, env, event)
6
+ @app = app
7
+ @event = event
8
+ end
9
+
10
+ def call(env)
11
+ puts 'running customize'
12
+
13
+ customizations = []
14
+ env[:machine].provider_config.customizations.each do |event, command|
15
+ if event == @event
16
+ customizations << command
17
+ end
18
+ end
19
+ if !customizations.empty?
20
+ env[:ui].info I18n.t("vagrant.actions.vm.customize.running", event: @event)
21
+ # Execute each customization command.
22
+ customizations.each do |command|
23
+ processed_command = command.collect do |arg|
24
+ arg = env[:machine].id if arg == :id
25
+ arg.to_s
26
+ end
27
+
28
+ begin
29
+ env[:machine].provider.driver.execute_command(
30
+ processed_command + [retryable: true])
31
+ rescue Vagrant::Errors::VBoxManageError => e
32
+ raise Vagrant::Errors::VMCustomizationFailed, {
33
+ command: command,
34
+ error: e.inspect
35
+ }
36
+ end
37
+ end
38
+ end
39
+ @app.call(env)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class Destroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
11
+ env[:machine].provider.driver.delete
12
+ env[:machine].id = nil
13
+
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class DiscardState
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env[:machine].state.id == :saved
11
+ env[:ui].info I18n.t("vagrant.actions.vm.discard_state.discarding")
12
+ env[:machine].provider.driver.discard_saved_state
13
+ end
14
+
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,41 @@
1
+ require "fileutils"
2
+
3
+ module VagrantPlugins
4
+ module ProviderVeertu
5
+ module Action
6
+ class Export
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @env = env
13
+
14
+ #env[:ui].output(@env[:machine].state.id)
15
+ raise Vagrant::Errors::VMPowerOffToPackage if \
16
+ @env[:machine].state.id != :stopped
17
+
18
+ export
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ def export
24
+ @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
25
+ @env[:machine].provider.driver.export(ovf_path) do |progress|
26
+ @env[:ui].clear_line
27
+ @env[:ui].report_progress(progress.percent, 100, false)
28
+ end
29
+
30
+ # Clear the line a final time so the next data can appear
31
+ # alone on the line.
32
+ @env[:ui].clear_line
33
+ end
34
+
35
+ def ovf_path
36
+ File.join(@env["export.temp_dir"], "box.ovf")
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class ForcedHalt
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ current_state = env[:machine].state.id
11
+ if current_state == :running || current_state == :gurumeditation
12
+ env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
13
+ env[:machine].provider.driver.halt
14
+ end
15
+
16
+ # Sleep for a second to verify that the VM properly
17
+ # cleans itself up. Silly VirtualBox.
18
+ sleep 1 if !env["vagrant.test"]
19
+
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,91 @@
1
+ require 'log4r'
2
+ module VagrantPlugins
3
+ module ProviderVeertu
4
+ module Action
5
+ class ForwardPorts
6
+ include Util::CompileForwardedPorts
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant::provider::veertu_5_0")
11
+ end
12
+
13
+ #--------------------------------------------------------------
14
+ # Execution
15
+ #--------------------------------------------------------------
16
+ def call(env)
17
+ @env = env
18
+
19
+ # Get the ports we're forwarding
20
+ env[:forwarded_ports] ||= compile_forwarded_ports(env[:machine].config)
21
+
22
+ # Warn if we're port forwarding to any privileged ports...
23
+ env[:forwarded_ports].each do |fp|
24
+ if fp.host_port <= 1024
25
+ env[:ui].warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
26
+ break
27
+ end
28
+ end
29
+
30
+ env[:ui].output(I18n.t("vagrant.actions.vm.forward_ports.forwarding"))
31
+ forward_ports
32
+
33
+ @app.call(env)
34
+ end
35
+
36
+ def forward_ports
37
+ ports = []
38
+
39
+ #interfaces = @env[:machine].provider.driver.read_network_interfaces
40
+
41
+ @env[:forwarded_ports].each do |fp|
42
+ message_attributes = {
43
+ adapter: fp.adapter,
44
+ guest_port: fp.guest_port,
45
+ host_port: fp.host_port
46
+ }
47
+
48
+ # Assuming the only reason to establish port forwarding is
49
+ # because the VM is using Virtualbox NAT networking. Host-only
50
+ # bridged networking don't require port-forwarding and establishing
51
+ # forwarded ports on these attachment types has uncertain behaviour.
52
+ @env[:ui].detail(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
53
+ message_attributes))
54
+ @logger.debug(YAML::dump(fp))
55
+ # Verify we have the network interface to attach to
56
+ #if !interfaces[fp.adapter]
57
+ # raise Vagrant::Errors::ForwardPortAdapterNotFound,
58
+ # adapter: fp.adapter.to_s,
59
+ # guest: fp.guest_port.to_s,
60
+ # host: fp.host_port.to_s
61
+ #end
62
+ #
63
+ ## Port forwarding requires the network interface to be a NAT interface,
64
+ ## so verify that that is the case.
65
+ #if interfaces[fp.adapter][:type] != :nat
66
+ # @env[:ui].detail(I18n.t("vagrant.actions.vm.forward_ports.non_nat",
67
+ # message_attributes))
68
+ # next
69
+ #end
70
+
71
+ # Add the options to the ports array to send to the driver later
72
+ ports << {
73
+ adapter: fp.adapter,
74
+ guestip: fp.guest_ip,
75
+ guestport: fp.guest_port,
76
+ hostip: fp.host_ip,
77
+ hostport: fp.host_port,
78
+ name: fp.id,
79
+ protocol: fp.protocol
80
+ }
81
+ end
82
+
83
+ if !ports.empty?
84
+ # We only need to forward ports if there are any to forward
85
+ @env[:machine].provider.driver.forward_ports(ports)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,96 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Action
4
+ class Import
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env[:clone_id]
11
+ clone(env)
12
+ else
13
+ import(env)
14
+ end
15
+ end
16
+
17
+ def clone(env)
18
+ # Do the actual clone
19
+ env[:ui].info I18n.t("vagrant.actions.vm.clone.creating")
20
+ env[:machine].id = env[:machine].provider.driver.clonevm(
21
+ env[:clone_id], env[:clone_snapshot]) do |progress|
22
+ env[:ui].clear_line
23
+ env[:ui].report_progress(progress, 100, false)
24
+ end
25
+
26
+ # Clear the line one last time since the progress meter doesn't
27
+ # disappear immediately.
28
+ env[:ui].clear_line
29
+
30
+ # Flag as erroneous and return if clone failed
31
+ raise Vagrant::Errors::VMCloneFailure if !env[:machine].id
32
+
33
+ # Copy the SSH key from the clone machine if we can
34
+ if env[:clone_machine]
35
+ key_path = env[:clone_machine].data_dir.join("private_key")
36
+ if key_path.file?
37
+ FileUtils.cp(
38
+ key_path,
39
+ env[:machine].data_dir.join("private_key"))
40
+ end
41
+ end
42
+
43
+ # Continue
44
+ @app.call(env)
45
+ end
46
+
47
+ def import(env)
48
+ env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
49
+ name: env[:machine].box.name)
50
+
51
+ # Import the virtual machine
52
+ ovf_file = env[:machine].box.directory.join("box.vmz").to_s
53
+ id = env[:machine].provider.driver.import(ovf_file) do |progress|
54
+ env[:ui].clear_line
55
+ env[:ui].report_progress(progress, 100, false)
56
+ end
57
+
58
+ # Set the machine ID
59
+ env[:machine_id] = id
60
+ env[:machine].id = id if !env[:skip_machine]
61
+
62
+ # Clear the line one last time since the progress meter doesn't disappear
63
+ # immediately.
64
+ env[:ui].clear_line
65
+
66
+ # If we got interrupted, then the import could have been
67
+ # interrupted and its not a big deal. Just return out.
68
+ return if env[:interrupted]
69
+
70
+ # Flag as erroneous and return if import failed
71
+ raise Vagrant::Errors::VMImportFailure if !id
72
+
73
+ # Import completed successfully. Continue the chain
74
+ @app.call(env)
75
+ end
76
+
77
+ def recover(env)
78
+ if env[:machine] && env[:machine].state.id != :not_created
79
+ return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
80
+
81
+ # If we're not supposed to destroy on error then just return
82
+ return if !env[:destroy_on_error]
83
+
84
+ # Interrupted, destroy the VM. We note that we don't want to
85
+ # validate the configuration here, and we don't want to confirm
86
+ # we want to destroy.
87
+ destroy_env = env.clone
88
+ destroy_env[:config_validate] = false
89
+ destroy_env[:force_confirm_destroy] = true
90
+ env[:action_runner].run(Action.action_destroy, destroy_env)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end