Class: Quickmox::Host
- Inherits:
-
Object
- Object
- Quickmox::Host
- Defined in:
- lib/quickmox/host.rb
Overview
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.
Defined Under Namespace
Classes: HostError
Instance Attribute Summary collapse
-
#guests ⇒ Object
Returns the value of attribute guests.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#password ⇒ Object
Returns the value of attribute password.
-
#session ⇒ Object
Returns the value of attribute session.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #disconnect ⇒ Object
- #exec(cmd) ⇒ Object
- #guestlist ⇒ Object
-
#initialize(transport) ⇒ Host
constructor
A new instance of Host.
- #is_proxmox? ⇒ Boolean
- #localname ⇒ Object
- #rescan ⇒ Object
- #scan ⇒ Object
- #uptime ⇒ Object
Constructor Details
#initialize(transport) ⇒ Host
Returns a new instance of Host.
22 23 24 25 26 27 28 29 30 31 |
# 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 |
Instance Attribute Details
#guests ⇒ Object
Returns the value of attribute guests.
15 16 17 |
# File 'lib/quickmox/host.rb', line 15 def guests @guests end |
#hostname ⇒ Object
Returns the value of attribute hostname.
15 16 17 |
# File 'lib/quickmox/host.rb', line 15 def hostname @hostname end |
#ip ⇒ Object
Returns the value of attribute ip.
15 16 17 |
# File 'lib/quickmox/host.rb', line 15 def ip @ip end |
#password ⇒ Object
Returns the value of attribute password.
15 16 17 |
# File 'lib/quickmox/host.rb', line 15 def password @password end |
#session ⇒ Object
Returns the value of attribute session.
15 16 17 |
# File 'lib/quickmox/host.rb', line 15 def session @session end |
#username ⇒ Object
Returns the value of attribute username.
15 16 17 |
# File 'lib/quickmox/host.rb', line 15 def username @username end |
Instance Method Details
#close ⇒ Object
75 76 77 |
# File 'lib/quickmox/host.rb', line 75 def close handle_exceptions { disconnect } end |
#connect ⇒ Object
33 34 35 36 |
# File 'lib/quickmox/host.rb', line 33 def connect handle_exceptions { @session.connect } self end |
#disconnect ⇒ Object
79 80 81 |
# File 'lib/quickmox/host.rb', line 79 def disconnect handle_exceptions { session.close } end |
#exec(cmd) ⇒ Object
89 90 91 |
# File 'lib/quickmox/host.rb', line 89 def exec(cmd) handle_exceptions {session.exec!(cmd).chomp} end |
#guestlist ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/quickmox/host.rb', line 52 def guestlist list = String.new handle_exceptions do list = Array.new table = session.exec!('qm list') lines = table.split("\n") lines.each do |line| if line =~ /^ *([0-9]{1,4}) */ list << $1 end end end list end |
#is_proxmox? ⇒ Boolean
83 84 85 86 87 |
# File 'lib/quickmox/host.rb', line 83 def is_proxmox? output = String.new handle_exceptions { output = session.exec!('qm list') } (output =~ /VMID NAME/) ? true : false end |
#localname ⇒ Object
67 68 69 |
# File 'lib/quickmox/host.rb', line 67 def localname handle_exceptions { session.exec!('hostname').chomp } end |
#rescan ⇒ Object
38 39 40 |
# File 'lib/quickmox/host.rb', line 38 def rescan scan end |
#scan ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
71 72 73 |
# File 'lib/quickmox/host.rb', line 71 def uptime handle_exceptions { session.exec!('uptime').chomp } end |