vagrant-veertu 0.0.12

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 (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,18 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Errors
4
+ class VeertuError < Vagrant::Errors::VagrantError
5
+ error_namespace('vagrant_veertu.errors')
6
+ end
7
+ class VeertuUnsupported < VeertuError
8
+ error_key(:veertumanage_unsupported)
9
+ end
10
+ class VeertuManageError < VeertuError
11
+ error_key(:veertumanage_error)
12
+ end
13
+ class VeertuManageNotFoundError < VeertuManageError
14
+ error_key(:veertumanage_notfound_error)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,70 @@
1
+ module VagrantPlugins
2
+ module ProviderVeertu
3
+ module Model
4
+ # Represents a single forwarded port for VirtualBox. This has various
5
+ # helpers and defaults for a forwarded port.
6
+ class ForwardedPort
7
+ # The NAT adapter on which to attach the forwarded port.
8
+ #
9
+ # @return [Integer]
10
+ attr_reader :adapter
11
+
12
+ # If true, this port should be auto-corrected.
13
+ #
14
+ # @return [Boolean]
15
+ attr_reader :auto_correct
16
+
17
+ # The unique ID for the forwarded port.
18
+ #
19
+ # @return [String]
20
+ attr_reader :id
21
+
22
+ # The protocol to forward.
23
+ #
24
+ # @return [String]
25
+ attr_reader :protocol
26
+
27
+ # The IP that the forwarded port will connect to on the guest machine.
28
+ #
29
+ # @return [String]
30
+ attr_reader :guest_ip
31
+
32
+ # The port on the guest to be exposed on the host.
33
+ #
34
+ # @return [Integer]
35
+ attr_reader :guest_port
36
+
37
+ # The IP that the forwarded port will bind to on the host machine.
38
+ #
39
+ # @return [String]
40
+ attr_reader :host_ip
41
+
42
+ # The port on the host used to access the port on the guest.
43
+ #
44
+ # @return [Integer]
45
+ attr_reader :host_port
46
+
47
+ def initialize(id, host_port, guest_port, options)
48
+ @id = id
49
+ @guest_port = guest_port
50
+ @host_port = host_port
51
+
52
+ options ||= {}
53
+ @auto_correct = false
54
+ @auto_correct = options[:auto_correct] if options.key?(:auto_correct)
55
+ @adapter = (options[:adapter] || 1).to_i
56
+ @guest_ip = options[:guest_ip] || nil
57
+ @host_ip = options[:host_ip] || nil
58
+ @protocol = options[:protocol] || "tcp"
59
+ end
60
+
61
+ # This corrects the host port and changes it to the given new port.
62
+ #
63
+ # @param [Integer] new_port The new port
64
+ def correct_host_port(new_port)
65
+ @host_port = new_port
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,76 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module ProviderVeertu
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Veertu provider"
7
+ description <<-EOF
8
+ The Veertu provider allows Vagrant to manage and control
9
+ Veertu-based virtual machines.
10
+ EOF
11
+
12
+ provider(:veertu, priority: 6) do
13
+ require File.expand_path("../provider", __FILE__)
14
+ Provider
15
+ end
16
+
17
+ config(:veertu, :provider) do
18
+ require File.expand_path("../config", __FILE__)
19
+ Config
20
+ end
21
+
22
+ config(:veertu, :provider) do
23
+ require File.expand_path("../config", __FILE__)
24
+ setup_i18n
25
+ Config
26
+ end
27
+
28
+ synced_folder(:veertu) do
29
+ require File.expand_path("../synced_folder", __FILE__)
30
+ SyncedFolder
31
+ end
32
+
33
+ provider_capability(:veertu, :forwarded_ports) do
34
+ require_relative "cap"
35
+ Cap
36
+ end
37
+
38
+ provider_capability(:veertu, :nic_mac_addresses) do
39
+ require_relative "cap"
40
+ Cap
41
+ end
42
+
43
+ provider_capability(:veertu, :public_address) do
44
+ require_relative "cap/public_address"
45
+ Cap::PublicAddress
46
+ end
47
+
48
+ provider_capability(:veertu, :snapshot_list) do
49
+ require_relative "cap"
50
+ Cap
51
+ end
52
+
53
+ def self.setup_i18n
54
+ I18n.load_path << File.expand_path("locales/en.yml", ProviderVeertu.source_root)
55
+ I18n.reload!
56
+ end
57
+ end
58
+
59
+ autoload :Action, File.expand_path("../action", __FILE__)
60
+
61
+ # Drop some autoloads in here to optimize the performance of loading
62
+ # our drivers only when they are needed.
63
+ module Driver
64
+ autoload :Meta, File.expand_path("../driver/meta", __FILE__)
65
+ autoload :Version_5_0, File.expand_path("../driver/version_5_0", __FILE__)
66
+ end
67
+
68
+ module Model
69
+ autoload :ForwardedPort, File.expand_path("../model/forwarded_port", __FILE__)
70
+ end
71
+
72
+ module Util
73
+ autoload :CompileForwardedPorts, File.expand_path("../util/compile_forwarded_ports", __FILE__)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,121 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module ProviderVeertu
5
+ class Provider < Vagrant.plugin("2", :provider)
6
+ attr_reader :driver
7
+
8
+ def self.installed?
9
+ Driver::Meta.new
10
+ true
11
+ rescue Vagrant::Errors::VirtualBoxInvalidVersion
12
+ return false
13
+ rescue Vagrant::Errors::VirtualBoxNotDetected
14
+ return false
15
+ end
16
+
17
+ def self.usable?(raise_error=false)
18
+ # Instantiate the driver, which will determine the VirtualBox
19
+ # version and all that, which checks for VirtualBox being present
20
+ Driver::Meta.new
21
+ true
22
+ rescue Vagrant::Errors::VirtualBoxInvalidVersion
23
+ raise if raise_error
24
+ return false
25
+ rescue Vagrant::Errors::VirtualBoxNotDetected
26
+ raise if raise_error
27
+ return false
28
+ end
29
+
30
+ def initialize(machine)
31
+ @logger = Log4r::Logger.new("vagrant::provider::veertu")
32
+ @machine = machine
33
+
34
+ # This method will load in our driver, so we call it now to
35
+ # initialize it.
36
+ machine_id_changed
37
+ end
38
+
39
+ # @see Vagrant::Plugin::V1::Provider#action
40
+ def action(name)
41
+ # Attempt to get the action method from the Action class if it
42
+ # exists, otherwise return nil to show that we don't support the
43
+ # given action.
44
+ action_method = "action_#{name}"
45
+ return Action.send(action_method) if Action.respond_to?(action_method)
46
+ nil
47
+ end
48
+
49
+ # If the machine ID changed, then we need to rebuild our underlying
50
+ # driver.
51
+ def machine_id_changed
52
+ id = @machine.id
53
+
54
+ begin
55
+ @logger.debug("Instantiating the driver for machine ID: #{@machine.id.inspect}")
56
+ @driver = Driver::Meta.new(id)
57
+ rescue Driver::Meta::VMNotFound
58
+ # The virtual machine doesn't exist, so we probably have a stale
59
+ # ID. Just clear the id out of the machine and reload it.
60
+ @logger.debug("VM not found! Clearing saved machine ID and reloading.")
61
+ id = nil
62
+ retry
63
+ end
64
+ end
65
+
66
+ # Returns the SSH info for accessing the VirtualBox VM.
67
+ def ssh_info
68
+ # If the VM is not running that we can't possibly SSH into it
69
+ return nil if state.id != :running
70
+ local_port = @driver.ssh_port(@machine.config.ssh.guest_port)
71
+ return {
72
+ host: "127.0.0.1",
73
+ port: local_port
74
+ }
75
+ end
76
+
77
+ # Return the state of Veertu virtual machine by actually
78
+ # querying VeertuManage.
79
+ #
80
+ # @return [Symbol]
81
+ def state
82
+ #puts caller
83
+ # We have to check if the UID matches to avoid issues with
84
+ # VirtualBox.
85
+ uid = @machine.uid
86
+ if uid && uid.to_s != Process.uid.to_s
87
+ raise Vagrant::Errors::VirtualBoxUserMismatch,
88
+ original_uid: uid.to_s,
89
+ uid: Process.uid.to_s
90
+ end
91
+ # Determine the ID of the state here.
92
+ state_id = nil
93
+ state_id = :not_created if !@driver.uuid
94
+ state_id = @driver.read_state if !state_id
95
+ state_id = :unknown if !state_id
96
+
97
+ # Translate into short/long descriptions
98
+ short = state_id.to_s.gsub("_", " ")
99
+ long = I18n.t("vagrant.commands.status.#{state_id}")
100
+
101
+ # If we're not created, then specify the special ID flag
102
+ if state_id == :not_created
103
+ state_id = Vagrant::MachineState::NOT_CREATED_ID
104
+ end
105
+ # Return the state
106
+ state_to_ret = Vagrant::MachineState.new(state_id, short, long)
107
+ return state_to_ret
108
+ end
109
+
110
+ # Returns a human-friendly string version of this provider which
111
+ # includes the machine's ID that this provider represents, if it
112
+ # has one.
113
+ #
114
+ # @return [String]
115
+ def to_s
116
+ id = @machine.id ? @machine.id : "new VM"
117
+ "VirtualBox (#{id})"
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,120 @@
1
+ require "vagrant/util/platform"
2
+
3
+ module VagrantPlugins
4
+ module ProviderVeertu
5
+ class SyncedFolder < Vagrant.plugin("2", :synced_folder)
6
+ def usable?(machine, raise_errors=false)
7
+ # These synced folders only work if the provider if VirtualBox
8
+ return false if machine.provider_name != :virtualbox
9
+
10
+ # This only happens with `vagrant package --base`. Sigh.
11
+ return true if !machine.provider_config
12
+
13
+ machine.provider_config.functional_vboxsf
14
+ end
15
+
16
+ def prepare(machine, folders, _opts)
17
+ share_folders(machine, folders, false)
18
+ end
19
+
20
+ def enable(machine, folders, _opts)
21
+ share_folders(machine, folders, true)
22
+
23
+ # short guestpaths first, so we don't step on ourselves
24
+ folders = folders.sort_by do |id, data|
25
+ if data[:guestpath]
26
+ data[:guestpath].length
27
+ else
28
+ # A long enough path to just do this at the end.
29
+ 10000
30
+ end
31
+ end
32
+
33
+ # Go through each folder and mount
34
+ machine.ui.output(I18n.t("vagrant.actions.vm.share_folders.mounting"))
35
+ folders.each do |id, data|
36
+ if data[:guestpath]
37
+ # Guest path specified, so mount the folder to specified point
38
+ machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
39
+ guestpath: data[:guestpath],
40
+ hostpath: data[:hostpath]))
41
+
42
+ # Dup the data so we can pass it to the guest API
43
+ data = data.dup
44
+
45
+ # Calculate the owner and group
46
+ ssh_info = machine.ssh_info
47
+ data[:owner] ||= ssh_info[:username]
48
+ data[:group] ||= ssh_info[:username]
49
+
50
+ # Mount the actual folder
51
+ machine.guest.capability(
52
+ :mount_virtualbox_shared_folder,
53
+ os_friendly_id(id), data[:guestpath], data)
54
+ else
55
+ # If no guest path is specified, then automounting is disabled
56
+ machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.nomount_entry",
57
+ hostpath: data[:hostpath]))
58
+ end
59
+ end
60
+ end
61
+
62
+ def disable(machine, folders, _opts)
63
+ if machine.guest.capability?(:unmount_virtualbox_shared_folder)
64
+ folders.each do |id, data|
65
+ machine.guest.capability(
66
+ :unmount_virtualbox_shared_folder,
67
+ data[:guestpath], data)
68
+ end
69
+ end
70
+
71
+ # Remove the shared folders from the VM metadata
72
+ names = folders.map { |id, _data| os_friendly_id(id) }
73
+ driver(machine).unshare_folders(names)
74
+ end
75
+
76
+ def cleanup(machine, opts)
77
+ driver(machine).clear_shared_folders if machine.id && machine.id != ""
78
+ end
79
+
80
+ protected
81
+
82
+ # This is here so that we can stub it for tests
83
+ def driver(machine)
84
+ machine.provider.driver
85
+ end
86
+
87
+ def os_friendly_id(id)
88
+ id.gsub(/[\/]/,'_').sub(/^_/, '')
89
+ end
90
+
91
+ # share_folders sets up the shared folder definitions on the
92
+ # VirtualBox VM.
93
+ #
94
+ # The transient parameter determines if we're FORCING transient
95
+ # or not. If this is false, then any shared folders will be
96
+ # shared as non-transient unless they've specifically asked for
97
+ # transient.
98
+ def share_folders(machine, folders, transient)
99
+ defs = []
100
+ folders.each do |id, data|
101
+ hostpath = data[:hostpath]
102
+ if !data[:hostpath_exact]
103
+ hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath)
104
+ end
105
+
106
+ # Only setup the shared folders that match our transient level
107
+ if (!!data[:transient]) == transient
108
+ defs << {
109
+ name: os_friendly_id(id),
110
+ hostpath: hostpath.to_s,
111
+ transient: transient,
112
+ }
113
+ end
114
+ end
115
+
116
+ driver(machine).share_folders(defs)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,35 @@
1
+ require "vagrant/util/scoped_hash_override"
2
+
3
+ module VagrantPlugins
4
+ module ProviderVeertu
5
+ module Util
6
+ module CompileForwardedPorts
7
+ include Vagrant::Util::ScopedHashOverride
8
+
9
+ # This method compiles the forwarded ports into {ForwardedPort}
10
+ # models.
11
+ def compile_forwarded_ports(config)
12
+ mappings = {}
13
+
14
+ config.vm.networks.each do |type, options|
15
+ if type == :forwarded_port
16
+ guest_port = options[:guest]
17
+ host_port = options[:host]
18
+ protocol = options[:protocol] || "tcp"
19
+ options = scoped_hash_override(options, :veertu)
20
+ id = options[:id]
21
+
22
+ # If the forwarded port was marked as disabled, ignore.
23
+ next if options[:disabled]
24
+
25
+ mappings[host_port.to_s + protocol.to_s] =
26
+ Model::ForwardedPort.new(id, host_port, guest_port, options)
27
+ end
28
+ end
29
+
30
+ mappings.values
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Veertu
3
+ VERSION = "0.0.12"
4
+ end
5
+ end