class Quickmox::Host
This class represents a SSH server host. It may or may not be connected to a Proxmox server. If it's not, proxmox specific methods like guests(), guest_params() etc. will return empty data structures.
Attributes
guests[RW]
hostname[RW]
ip[RW]
password[RW]
session[RW]
username[RW]
Public Class Methods
new(transport)
click to toggle source
# File lib/quickmox/host.rb, line 22 def initialize(transport) @session = transport @guests = Guestlist.new begin @ip = Resolv.getaddress(@session.host) rescue => e @ip = String.new end end
Public Instance Methods
close()
click to toggle source
# File lib/quickmox/host.rb, line 75 def close handle_exceptions { disconnect } end
connect()
click to toggle source
# File lib/quickmox/host.rb, line 33 def connect handle_exceptions { @session.connect } self end
disconnect()
click to toggle source
# File lib/quickmox/host.rb, line 79 def disconnect handle_exceptions { session.close } end
exec(cmd)
click to toggle source
# File lib/quickmox/host.rb, line 89 def exec(cmd) handle_exceptions { session.exec!(cmd) } end
guestlist()
click to toggle source
# File lib/quickmox/host.rb, line 52 def guestlist list = String.new handle_exceptions do list = Array.new table = exec('qm list') lines = table.split("\n") lines.each do |line| if line =~ /^ *([0-9]{1,6}) */ list << $1 end end end list end
is_proxmox?()
click to toggle source
# File lib/quickmox/host.rb, line 83 def is_proxmox? output = String.new handle_exceptions { output = exec('qm list') } (output =~ /VMID NAME/) ? true : false end
localname()
click to toggle source
# File lib/quickmox/host.rb, line 67 def localname handle_exceptions { exec('hostname') } end
rescan()
click to toggle source
# File lib/quickmox/host.rb, line 38 def rescan scan end
scan()
click to toggle source
# File lib/quickmox/host.rb, line 42 def scan handle_exceptions do guestlist.each do |id| @guests << Guest.new(id, self) end @guests.scan end self end
uptime()
click to toggle source
# File lib/quickmox/host.rb, line 71 def uptime handle_exceptions { exec('uptime') } end
Private Instance Methods
handle_exceptions() { || ... }
click to toggle source
# File lib/quickmox/host.rb, line 95 def handle_exceptions begin yield rescue => e raise HostError, "Exception in Quickmox::Host while handling host #{@session.host}: #{e}" end end