Class: Quickmox::Guest
- Inherits:
-
Object
- Object
- Quickmox::Guest
- Defined in:
- lib/quickmox/guest.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#id ⇒ Object
Returns the value of attribute id.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(id, host) ⇒ Guest
constructor
A new instance of Guest.
- #name ⇒ Object
- #rescan ⇒ Object
- #scan ⇒ Object
- #set_param(param, value) ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(id, host) ⇒ Guest
Returns a new instance of Guest.
7 8 9 10 11 |
# File 'lib/quickmox/guest.rb', line 7 def initialize(id, host) @host = host @id = id @params = Hash.new end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/quickmox/guest.rb', line 5 def host @host end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/quickmox/guest.rb', line 5 def id @id end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/quickmox/guest.rb', line 5 def params @params end |
Instance Method Details
#name ⇒ Object
34 35 36 |
# File 'lib/quickmox/guest.rb', line 34 def name params[:name] end |
#rescan ⇒ Object
30 31 32 |
# File 'lib/quickmox/guest.rb', line 30 def rescan scan end |
#scan ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/quickmox/guest.rb', line 38 def scan config_lines.each do |line| case line when /net0:.*=([0-9A-Fa-f:]{17}),/ params[:mac] = $1 params[:mac] = params[:mac].gsub(':', '').downcase when /cores: ([0-9]{1,3})/ params[:cores] = $1 when /(description|name|bootdisk): (.*)/ params[$1.to_sym] = $2 when /memory: ([0-9]{1,6})/ params[:memory] = $1 when /onboot: ([0-9])/ params[:onboot] = $1 when /(scsi|virtio|ide)[0-9]{1,3}: .*size=([0-9]{1,3}[MGTK])/ params[:disk] = $2 end end self end |
#set_param(param, value) ⇒ Object
26 27 28 |
# File 'lib/quickmox/guest.rb', line 26 def set_param(param, value) host.exec "qm set #{id} -#{param} #{value}" end |
#start ⇒ Object
18 19 20 |
# File 'lib/quickmox/guest.rb', line 18 def start host.exec "qm start #{id}" end |
#status ⇒ Object
13 14 15 16 |
# File 'lib/quickmox/guest.rb', line 13 def status line = host.exec "qm status #{id}" (line =~ /status: (.*)/) ? $1.chomp : 'unknown' end |
#stop ⇒ Object
22 23 24 |
# File 'lib/quickmox/guest.rb', line 22 def stop host.exec "qm stop #{id}" end |