lib/virtualbox/vm.rb in virtualbox-0.4.2 vs lib/virtualbox/vm.rb in virtualbox-0.4.3

- old
+ new

@@ -118,11 +118,11 @@ class <<self # Returns an array of all available VMs. # # @return [Array<VM>] def all - raw = Command.vboxmanage("list vms") + raw = Command.vboxmanage("list", "vms") parse_vm_list(raw) end # Finds a VM by UUID or registered name and returns a # new VM object. If the VM doesn't exist, will return `nil`. @@ -139,11 +139,11 @@ # VM object can be used to make any modifications necessary # (RAM, cpus, etc.). # # @return [VM] The newly imported virtual machine def import(source_path) - raw = Command.vboxmanage("import #{Command.shell_escape(source_path)}") + raw = Command.vboxmanage("import", source_path) return nil unless raw find(parse_vm_name(raw)) end @@ -152,19 +152,19 @@ # # **This method typically won't be used except internally.** # # @return [String] def human_info(name) - Command.vboxmanage("showvminfo #{Command.shell_escape(name)}") + Command.vboxmanage("showvminfo", name) end # Gets the VM info (machine readable) for a given VM and returns it # as a hash. # # @return [Hash] Parsed VM info. def raw_info(name) - raw = Command.vboxmanage("showvminfo #{Command.shell_escape(name)} --machinereadable") + raw = Command.vboxmanage("showvminfo", name, "--machinereadable") parse_vm_info(raw) end # Parses the machine-readable format outputted by VBoxManage showvminfo # into a hash. Ignores lines which don't match the format. @@ -257,11 +257,11 @@ # Saves a single attribute of the virtual machine. This should **not** # be called except interally. Instead, you're probably looking for {#save}. # # **This method typically won't be used except internally.** def save_attribute(key, value) - Command.vboxmanage("modifyvm #{Command.shell_escape(@original_name)} --#{key} #{Command.shell_escape(value.to_s)}") + Command.vboxmanage("modifyvm", @original_name, "--#{key}", value) super end # Exports a virtual machine. The virtual machine will be exported # to the specified OVF file name. This directory will also have the @@ -285,16 +285,17 @@ # @option options [String] :version (nil) The version information # @option options [String] :eula (nil) License text # @option options [String] :eulafile (nil) License file def export(filename, options={}, raise_error=false) options = options.inject([]) do |acc, kv| - acc.push("--#{kv[0]} #{Command.shell_escape(kv[1])}") + acc.push("--#{kv[0]}") + acc.push(kv[1]) end - options.unshift("--vsys 0") unless options.empty? + options.unshift("0").unshift("--vsys") unless options.empty? - raw = Command.vboxmanage("export #{Command.shell_escape(@original_name)} -o #{Command.shell_escape(filename)} #{options.join(" ")}".strip) + raw = Command.vboxmanage("export", @original_name, "-o", filename, *options) true rescue Exceptions::CommandFailedException raise if raise_error false end @@ -312,11 +313,11 @@ # @param [Symbol] mode Described above. # @param [Boolean] raise_errors If true, {Exceptions::CommandFailedException} # will be raised if the command failed. # @return [Boolean] True if command was successful, false otherwise. def start(mode=:gui, raise_errors=false) - Command.vboxmanage("startvm #{Command.shell_escape(@original_name)} --type #{mode}") + Command.vboxmanage("startvm", @original_name, "--type", mode) true rescue Exceptions::CommandFailedException raise if raise_errors false end @@ -362,30 +363,44 @@ def resume(raise_errors=false) control(:resume, raise_errors) end # Saves the state of a VM and stops it. The VM can be resumed - # again by calling "start" again. + # again by calling "{#start}" again. # # @param [Boolean] raise_errors If true, {Exceptions::CommandFailedException} # will be raised if the command failed. # @return [Boolean] True if command was successful, false otherwise. def save_state(raise_errors=false) control(:savestate, raise_errors) end + # Discards any saved state on the current VM. The VM is not destroyed though + # and can still be started by calling {#start}. + # + # @param [Boolean] raise_errors If true, {Exceptions::CommandFailedException} + # will be raised if the command failed. + # @return [Boolean] True if command was successful, false otherwise. + def discard_state(raise_errors=false) + Command.vboxmanage("discardstate", @original_name) + true + rescue Exceptions::CommandFailedException + raise if raise_errors + false + end + # Controls the virtual machine. This method is used by {#stop}, # {#pause}, {#resume}, and {#save_state} to control the virtual machine. # Typically, you won't ever have to call this method and should # instead call those. # # @param [String] command The command to run on controlvm # @param [Boolean] raise_errors If true, {Exceptions::CommandFailedException} # will be raised if the command failed. # @return [Boolean] True if command was successful, false otherwise. def control(command, raise_errors=false) - Command.vboxmanage("controlvm #{Command.shell_escape(@original_name)} #{command}") + Command.vboxmanage("controlvm", @original_name, command) true rescue Exceptions::CommandFailedException raise if raise_errors false end @@ -403,10 +418,10 @@ def destroy(*args) # Call super first to destroy relationships, necessary before # unregistering a VM super - Command.vboxmanage("unregistervm #{Command.shell_escape(@original_name)} --delete") + Command.vboxmanage("unregistervm", @original_name, "--delete") end # Returns true if the virtual machine state is running # # @return [Boolean] True if virtual machine state is running \ No newline at end of file