Class: Linecook::Commands::State

Inherits:
VboxCommand show all
Defined in:
lib/linecook/commands/state.rb

Overview

:startdoc::desc print the vm state

Prints the state of one or more VirtualBox virtual machines. By default all virtual machines configured in config/ssh will print their state.

Constant Summary

Constants inherited from VboxCommand

VboxCommand::HOST_REGEXP

Constants inherited from Command

Command::REGISTRY

Instance Attribute Summary

Attributes inherited from Command

#quiet

Instance Method Summary collapse

Methods inherited from VboxCommand

#discardstate, #each_host, #each_vm_name, #host_list, #host_map, #load_hosts, #resolve_vm_names, #restore, #running?, #share, #ssh, #ssh!, #ssh_config_file=, #start, #start_ssh_socket, #stop

Methods inherited from Command

#call, inherited, #initialize, #log, registry, #sh, #sh!

Constructor Details

This class inherits a constructor from Linecook::Commands::Command

Instance Method Details

#process(*hosts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/linecook/commands/state.rb', line 18

def process(*hosts)
  vm_names = resolve_vm_names(hosts)
  if hosts
    each_host(vm_names) do |host|
      puts "#{host}: #{state(host_map[host] || host)}"
    end
  else
    each_vm_name(vm_names) do |vm_name|
      puts "#{vm_name}: #{state(vm_name)}"
    end
  end
end

#state(vm_name) ⇒ Object



14
15
16
# File 'lib/linecook/commands/state.rb', line 14

def state(vm_name)
  `VBoxManage showvminfo #{vm_name}` =~ /^State:\s+(.*)$/ ? $1 : 'unknown'
end