class Quickmox::Guest

Attributes

host[RW]
id[RW]
params[RW]

Public Class Methods

new(id, host) click to toggle source
# File lib/quickmox/guest.rb, line 7
def initialize(id, host)
  @host = host
  @id = id
  @params = Hash.new
end

Public Instance Methods

name() click to toggle source
# File lib/quickmox/guest.rb, line 34
def name
  params[:name]
end
rescan() click to toggle source
# File lib/quickmox/guest.rb, line 30
def rescan
  scan
end
scan() click to toggle source
# 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) click to toggle source
# File lib/quickmox/guest.rb, line 26
def set_param(param, value)
  host.exec "qm set #{id} -#{param} #{value}"
end
start() click to toggle source
# File lib/quickmox/guest.rb, line 18
def start
  host.exec "qm start #{id}"
end
status() click to toggle source
# File lib/quickmox/guest.rb, line 13
def status
  line = host.exec "qm status #{id}"
  (line =~ /status: (.*)/) ? $1.chomp : 'unknown'
end
stop() click to toggle source
# File lib/quickmox/guest.rb, line 22
def stop
  host.exec "qm stop #{id}"
end

Private Instance Methods

config_lines() click to toggle source
# File lib/quickmox/guest.rb, line 61
def config_lines
  host.exec("qm config #{id}").split("\n")
end