Class: VagrantPlugins::ProviderVeertu::Driver::Base
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderVeertu::Driver::Base
- Includes:
- Vagrant::Util::Retryable
- Defined in:
- lib/vagrant-veertu/driver/base.rb
Overview
Base class for all VeertuManage drivers.
This class provides useful tools for things such as executing VeertuManage and handling SIGINTs and so on.
Direct Known Subclasses
Instance Method Summary collapse
-
#clear_forwarded_ports ⇒ Object
Clears the forwarded ports that have been set on the virtual machine.
-
#delete ⇒ Object
Deletes the virtual machine references by this driver.
-
#execute(*command, &block) ⇒ Object
Execute the given subcommand for VeertuManage and return the output.
-
#execute_command(command) ⇒ Object
Execute a raw command straight through to VeertuManage.
-
#export(path) {|progress| ... } ⇒ Object
Exports the virtual machine to the given path.
-
#forward_ports(ports) ⇒ Object
Forwards a set of ports for a VM.
-
#halt ⇒ Object
Halts the virtual machine (pulls the plug).
-
#import(box) ⇒ String
Imports the VM from an box file.
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #max_network_adapters ⇒ Object
-
#raw(*command, &block) ⇒ Object
Executes a command and returns the raw result object.
-
#read_forwarded_ports(uuid = nil, active_only = false) ⇒ Array<Array>
Returns a list of forwarded ports for a VM.
-
#read_state ⇒ Symbol
Returns the current state of this VM.
-
#read_used_ports ⇒ Array
Returns a list of all forwarded ports in use by active virtual machines.
-
#read_vms ⇒ Array<String>
Returns a list of all UUIDs of virtual machines currently known by Veertu.
-
#share_folders(folders) ⇒ Object
Share a set of folders on this VM.
-
#ssh_port(expected) ⇒ Object
Reads the SSH port of this VM.
-
#start(mode) ⇒ Object
Starts the virtual machine.
-
#suspend ⇒ Object
Suspend the virtual machine.
-
#verify! ⇒ Object
Verifies that the driver is ready to accept work.
-
#vm_exists?(uuid) ⇒ Boolean
Checks if a VM with the given UUID exists.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
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 |
# File 'lib/vagrant-veertu/driver/base.rb', line 21 def initialize @logger = Log4r::Logger.new("vagrant::provider::veertu::base") # This flag is used to keep track of interrupted state (SIGINT) @interrupted = false default_paths = ["/Applications/Veertu.app/Contents/SharedSupport/VeertuManage", "/Applications/Veertu Desktop.app/Contents/SharedSupport/VeertuManage"] ini_file = File.("~/.veertu_config") if File.exist?(ini_file) then file = IniFile.load(ini_file) @veertumanage_path = file['VAGRANT']['manage_path'] else default_paths.each do |veertu_path| if File.exist?(veertu_path) @veertumanage_path = veertu_path break end end end @logger.info("VeertuManage path: #{@veertumanage_path}") if !@veertumanage_path raise Errors::VeertuManageNotFoundError end end |
Instance Method Details
#clear_forwarded_ports ⇒ Object
Clears the forwarded ports that have been set on the virtual machine.
49 50 |
# File 'lib/vagrant-veertu/driver/base.rb', line 49 def clear_forwarded_ports end |
#delete ⇒ Object
Deletes the virtual machine references by this driver.
57 58 |
# File 'lib/vagrant-veertu/driver/base.rb', line 57 def delete end |
#execute(*command, &block) ⇒ Object
Execute the given subcommand for VeertuManage and return the output.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/vagrant-veertu/driver/base.rb', line 182 def execute(*command, &block) # Get the options hash if it exists opts = {} opts = command.pop if command.last.is_a?(Hash) tries = 0 tries = 3 if opts[:retryable] # Variable to store our execution result r = nil retryable(on: VagrantPlugins::ProviderVeertu::Errors::VeertuManageError, tries: tries, sleep: 1) do # If there is an error with VeertuManage, this gets set to true errored = false # Execute the command r = raw(*command, &block) # If the command was a failure, then raise an exception that is # nicely handled by Vagrant. if r.exit_code != 0 if @interrupted @logger.info("Exit code != 0, but interrupted. Ignoring.") elsif r.exit_code == 126 # This exit code happens if VeertuManage is on the PATH, # but another executable it tries to execute is missing. raise Errors::VeertuManageNotFoundError else errored = true end end # If there was an error running VeertuManage, show the error and the # output. if errored raise VagrantPlugins::ProviderVeertu::Errors::VeertuManageError, command: command.inspect, stderr: r.stderr, stdout: r.stdout end end r.stdout.gsub("\r\n", "\n") end |
#execute_command(command) ⇒ Object
Execute a raw command straight through to VeertuManage.
Accepts a retryable: true option if the command should be retried upon failure.
Raises a VeertuManage error if it fails.
68 69 |
# File 'lib/vagrant-veertu/driver/base.rb', line 68 def execute_command(command) end |
#export(path) {|progress| ... } ⇒ Object
Exports the virtual machine to the given path.
75 76 77 |
# File 'lib/vagrant-veertu/driver/base.rb', line 75 def export(path) raise NotImplementedError("please export manually") end |
#forward_ports(ports) ⇒ Object
Forwards a set of ports for a VM.
This will not affect any previously set forwarded ports, so be sure to delete those if you need to.
The format of each port hash should be the following:
{
name: "foo",
hostport: 8500,
guestport: 80,
adapter: 1,
protocol: "tcp"
}
Note that “adapter” and “protocol” are optional and will default to 1 and “tcp” respectively.
99 100 |
# File 'lib/vagrant-veertu/driver/base.rb', line 99 def forward_ports(ports) end |
#halt ⇒ Object
Halts the virtual machine (pulls the plug).
103 104 |
# File 'lib/vagrant-veertu/driver/base.rb', line 103 def halt end |
#import(box) ⇒ String
Imports the VM from an box file.
110 111 |
# File 'lib/vagrant-veertu/driver/base.rb', line 110 def import(box) end |
#max_network_adapters ⇒ Object
52 53 54 |
# File 'lib/vagrant-veertu/driver/base.rb', line 52 def max_network_adapters 36 end |
#raw(*command, &block) ⇒ Object
Executes a command and returns the raw result object.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/vagrant-veertu/driver/base.rb', line 228 def raw(*command, &block) int_callback = lambda do @interrupted = true # We have to execute this in a thread due to trap contexts # and locks. Thread.new { @logger.info("Interrupted.") }.join end # Append in the options for subprocess command << { notify: [:stdout, :stderr] } Vagrant::Util::Busy.busy(int_callback) do @logger.debug(YAML::dump(command)) Vagrant::Util::Subprocess.execute(@veertumanage_path, *command, &block) end rescue Vagrant::Util::Subprocess::LaunchError => e raise Vagrant::Errors::VeertuManageLaunchError, message: e.to_s end |
#read_forwarded_ports(uuid = nil, active_only = false) ⇒ Array<Array>
Returns a list of forwarded ports for a VM.
121 122 |
# File 'lib/vagrant-veertu/driver/base.rb', line 121 def read_forwarded_ports(uuid=nil, active_only=false) end |
#read_state ⇒ Symbol
Returns the current state of this VM.
127 128 |
# File 'lib/vagrant-veertu/driver/base.rb', line 127 def read_state end |
#read_used_ports ⇒ Array
Returns a list of all forwarded ports in use by active virtual machines.
134 135 |
# File 'lib/vagrant-veertu/driver/base.rb', line 134 def read_used_ports end |
#read_vms ⇒ Array<String>
Returns a list of all UUIDs of virtual machines currently known by Veertu.
141 142 |
# File 'lib/vagrant-veertu/driver/base.rb', line 141 def read_vms end |
#share_folders(folders) ⇒ Object
Share a set of folders on this VM.
147 148 |
# File 'lib/vagrant-veertu/driver/base.rb', line 147 def share_folders(folders) end |
#ssh_port(expected) ⇒ Object
Reads the SSH port of this VM.
153 154 |
# File 'lib/vagrant-veertu/driver/base.rb', line 153 def ssh_port(expected) end |
#start(mode) ⇒ Object
Starts the virtual machine.
160 161 |
# File 'lib/vagrant-veertu/driver/base.rb', line 160 def start(mode) end |
#suspend ⇒ Object
Suspend the virtual machine.
164 165 |
# File 'lib/vagrant-veertu/driver/base.rb', line 164 def suspend end |
#verify! ⇒ Object
Verifies that the driver is ready to accept work.
This should raise a VagrantError if things are not ready.
171 172 |
# File 'lib/vagrant-veertu/driver/base.rb', line 171 def verify! end |
#vm_exists?(uuid) ⇒ Boolean
Checks if a VM with the given UUID exists.
178 179 |
# File 'lib/vagrant-veertu/driver/base.rb', line 178 def vm_exists?(uuid) end |