Class: Quickmox::Guest

Inherits:
Object
  • Object
show all
Defined in:
lib/quickmox/guest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/quickmox/guest.rb', line 5

def host
  @host
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/quickmox/guest.rb', line 5

def id
  @id
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/quickmox/guest.rb', line 5

def params
  @params
end

Instance Method Details

#nameObject



34
35
36
# File 'lib/quickmox/guest.rb', line 34

def name
  params[:name]
end

#rescanObject



30
31
32
# File 'lib/quickmox/guest.rb', line 30

def rescan
  scan
end

#scanObject



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

#startObject



18
19
20
# File 'lib/quickmox/guest.rb', line 18

def start
  host.exec "qm start #{id}"
end

#statusObject



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

#stopObject



22
23
24
# File 'lib/quickmox/guest.rb', line 22

def stop
  host.exec "qm stop #{id}"
end