Class: Linecook::Commands::State

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

Overview

:startdoc::desc print a 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 VirtualBoxCommand

VirtualBoxCommand::HOST_REGEXP

Instance Method Summary collapse

Methods inherited from VirtualBoxCommand

#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 included from Linecook::CommandUtils

#sh, #sh!

Methods inherited from Linecook::Command

#call, help, #initialize, parse, signature

Constructor Details

This class inherits a constructor from Linecook::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