Class: VagrantPlugins::VBoxManage::Command::Root
- Inherits:
-
Object
- Object
- VagrantPlugins::VBoxManage::Command::Root
- Defined in:
- lib/vagrant-vboxmanage/commands/root.rb
Instance Method Summary collapse
- #execute ⇒ Object
- #vboxmanage_commands_all ⇒ Object
-
#vboxmanage_commands_special ⇒ Object
not of form ‘VBoxManage showvminfo uuid|name …`.
-
#vboxmanage_commands_standard ⇒ Object
of form ‘VBoxManage showvminfo uuid|name …`.
Instance Method Details
#execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vagrant-vboxmanage/commands/root.rb', line 6 def execute = {} opts = OptionParser.new do |opts| opts. = "Usage: vagrant vboxmanage [vm-name] [--] <vboxmanage-cmd> [UUID] [cmd-args]..." end if split_index = @argv.index('--') # of form `vagrant vboxmanage [vm-name] -- showvminfo ...` [:command] = @argv[split_index + 1] [:extra_args] = @argv.drop(split_index + 2) @argv = @argv.take(split_index) elsif command_index = @argv.index { |x| vboxmanage_commands_all.include?(x)} # of form `vagrant vboxmanage [vm-name] showvminfo...` [:command] = @argv[command_index] [:extra_args] = @argv.drop(command_index + 1) @argv = @argv.take(command_index) else @env.ui.error opts @env.ui.error "No valid VBoxManage subcommand detected." return 1 end @logger.debug "Parsing options:" + .merge({"argv" => @argv}).to_yaml argv = (opts) return if argv.length > 1 with_target_vms(argv, single_target: true) do |machine| if machine.state.id == :not_created machine.env.ui.error("Target machine is not created, unable to run VBoxManage.") return 1 end if vboxmanage_commands_standard.include?([:command]) @logger.debug("Performing UUID insertion for standard vboxmanage command: #{[:command]}") args = [[:command], machine.id] + [:extra_args] else @logger.debug("Skipping UUID insertion for special vboxmanage command: #{[:command]}") # TODO: handle substitution for commands like `usbfilter add 0 --target <uuid|name>` # [VM_UUID] is an optiona literal token `VM_UUID`, which will be replaced by the UUID of the VM referenced by Vagrant args = [[:command]] + [:extra_args] end @logger.debug("Executing: VBoxManage " + args.join(" ")) machine.provider.driver.execute(*args) do |type, data| colors = { :stdout => :green, :stderr => :red } machine.env.ui.info(data, :color => colors[type]) end end end |
#vboxmanage_commands_all ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/vagrant-vboxmanage/commands/root.rb', line 58 def vboxmanage_commands_all # derived as follows: `VBoxManage | sed '1,/Commands/d' | grep '^ [a-z]' | awk '{ print $1; }' | sort -u` return %w{adoptstate bandwidthctl clonehd clonevm closemedium controlvm convertfromraw createhd createvm debugvm dhcpserver discardstate export extpack getextradata guestcontrol guestproperty hostonlyif import list metrics modifyhd modifyvm registervm setextradata setproperty sharedfolder showhdinfo showvminfo snapshot startvm storageattach storagectl unregistervm usbfilter} end |
#vboxmanage_commands_special ⇒ Object
not of form ‘VBoxManage showvminfo uuid|name …`
69 70 71 72 73 74 |
# File 'lib/vagrant-vboxmanage/commands/root.rb', line 69 def vboxmanage_commands_special # derived by manual inspection of `VBoxManage`; see SPECIAL_COMMANDS.md return %w{list registervm createvm import export closemedium createhd clonehd convertfromraw getextradata setextradata setproperty usbfilter sharedfolder guestproperty metrics hostonlyif dhcpserver extpack} end |
#vboxmanage_commands_standard ⇒ Object
of form ‘VBoxManage showvminfo uuid|name …`
77 78 79 |
# File 'lib/vagrant-vboxmanage/commands/root.rb', line 77 def vboxmanage_commands_standard return vboxmanage_commands_all - vboxmanage_commands_special end |