Class: Derelict::VirtualMachine
- Inherits:
-
Object
- Object
- Derelict::VirtualMachine
- Extended by:
- Memoist
- Includes:
- Utils::Logger
- Defined in:
- lib/derelict/virtual_machine.rb,
lib/derelict/virtual_machine/invalid.rb,
lib/derelict/virtual_machine/not_found.rb
Overview
A Vagrant virtual machine in a particular Derelict connection
Defined Under Namespace
Constant Summary collapse
- COMMANDS =
[ :up, :halt, :destroy, :reload, :suspend, :resume, ]
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#description ⇒ Object
Provides a description of this Connection.
-
#exists? ⇒ Boolean
Determines whether this Vagrant virtual machine exists.
-
#initialize(connection, name) ⇒ VirtualMachine
constructor
Initializes a new VirtualMachine for a connection and name.
-
#running? ⇒ Boolean
Determines whether this virtual machine is currently running.
-
#state ⇒ Object
Gets the current state of this Vagrant virtual machine.
-
#status ⇒ Object
Retrieves the (parsed) status from the connection.
-
#validate! ⇒ Object
Validates the data used for this connection.
Methods included from Utils::Logger
Constructor Details
#initialize(connection, name) ⇒ VirtualMachine
Initializes a new VirtualMachine for a connection and name
* connection: The +Derelict::Connection+ to use to manipulate
the VirtualMachine instance
* name: The name of the virtual machine, used when
communicating with the connection)
31 32 33 34 35 |
# File 'lib/derelict/virtual_machine.rb', line 31 def initialize(connection, name) @connection = connection @name = name logger.debug "Successfully initialized #{description}" end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
22 23 24 |
# File 'lib/derelict/virtual_machine.rb', line 22 def connection @connection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/derelict/virtual_machine.rb', line 23 def name @name end |
Instance Method Details
#description ⇒ Object
Provides a description of this Connection
Mainly used for log messages.
124 125 126 |
# File 'lib/derelict/virtual_machine.rb', line 124 def description "Derelict::VirtualMachine '#{name}' from #{connection.description}" end |
#exists? ⇒ Boolean
Determines whether this Vagrant virtual machine exists
Returns true
if the connection reports a virtual machine with the requested name, otherwise returns false
.
55 56 57 |
# File 'lib/derelict/virtual_machine.rb', line 55 def exists? status.exists? name end |
#running? ⇒ Boolean
Determines whether this virtual machine is currently running
69 70 71 |
# File 'lib/derelict/virtual_machine.rb', line 69 def running? (state == :running) end |
#state ⇒ Object
Gets the current state of this Vagrant virtual machine
The state is returned as a symbol, e.g. :running.
63 64 65 |
# File 'lib/derelict/virtual_machine.rb', line 63 def state status.state name end |
#status ⇒ Object
Retrieves the (parsed) status from the connection
114 115 116 117 118 |
# File 'lib/derelict/virtual_machine.rb', line 114 def status logger.info "Retrieving Vagrant status for #{description}" output = connection.execute!(:status).stdout Derelict::Parser::Status.new(output) end |
#validate! ⇒ Object
Validates the data used for this connection
Raises exceptions on failure:
* +Derelict::VirtualMachine::NotFound+ if the connection
doesn't know about a virtual machine with the requested
name
44 45 46 47 48 49 |
# File 'lib/derelict/virtual_machine.rb', line 44 def validate! logger.debug "Starting validation for #{description}" raise NotFound.new name, connection unless exists? logger.info "Successfully validated #{description}" self end |