Class: Derelict::Parser::Status

Inherits:
Derelict::Parser show all
Extended by:
Memoist
Defined in:
lib/derelict/parser/status.rb,
lib/derelict/parser/status/invalid_format.rb

Overview

Parses the output of “vagrant status”

Defined Under Namespace

Classes: InvalidFormat

Constant Summary collapse

PARSE_LIST_FROM_OUTPUT =

Regexp to extract the VM list from the “vagrant status” output

/\n\n((?:.*\n)+)\n/
PARSE_STATE_FROM_LIST_ITEM =

Regexp to extract the state from a line in the VM list

%r[
^(.*?) # VM name starts at the start of the line,
\s{2,} # to the first instance of 2 or more spaces.
(.*?)  # VM state starts after the whitespace,
\s+\(  # continuing until whitespace and open bracket.
  (.*) # The provider name starts after the bracket,
\)$    # and ends at a closing bracket at line end.
]x

Instance Attribute Summary

Attributes inherited from Derelict::Parser

#output

Instance Method Summary collapse

Methods inherited from Derelict::Parser

#initialize

Methods included from Utils::Logger

#logger

Constructor Details

This class inherits a constructor from Derelict::Parser

Instance Method Details

#descriptionObject

Provides a description of this Parser

Mainly used for log messages.



52
53
54
# File 'lib/derelict/parser/status.rb', line 52

def description
  "Derelict::Parser::Status instance"
end

#exists?(vm_name) ⇒ Boolean

Determines if a particular virtual machine exists in the output

* vm_name: The name of the virtual machine to look for

Returns:

  • (Boolean)


32
33
34
# File 'lib/derelict/parser/status.rb', line 32

def exists?(vm_name)
  vm_names.include? vm_name.to_sym
end

#state(vm_name) ⇒ Object

Determines the state of a particular virtual machine

The state is returned as a symbol, e.g. :running.

* vm_name: The name of the virtual machine to retrieve state


41
42
43
44
45
46
47
# File 'lib/derelict/parser/status.rb', line 41

def state(vm_name)
  unless states.include? vm_name.to_sym
    raise Derelict::VirtualMachine::NotFound.new vm_name
  end

  states[vm_name.to_sym]
end

#vm_namesObject

Retrieves the names of all virtual machines in the output

The names are returned as a Set of symbols.



25
26
27
# File 'lib/derelict/parser/status.rb', line 25

def vm_names
  Set[*states.keys]
end