Class: Proxmox::Qemu
Instance Attribute Summary
Attributes inherited from Base
#sid
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Hosted
#===, #cnfset, #config, #current_status, #destroy, #migrate, #refresh!, #running?, #start, #stop, #stopped?, #wait
Methods inherited from Base
__new__, fetch, #method_missing, #refresh!, #respond_to?
#bench, #rest_del, #rest_get, #rest_post, #rest_put
Constructor Details
#initialize ⇒ Qemu
Returns a new instance of Qemu.
447
448
449
450
|
# File 'lib/pve/proxmox.rb', line 447
def initialize
rest_prefix
@sid = "qm:#{@vmid}"
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Proxmox::Base
Class Method Details
.all ⇒ Object
395
396
397
|
# File 'lib/pve/proxmox.rb', line 395
def all
Node.all.flat_map {|n| n.qemu }
end
|
.find(name_or_id = nil, name: nil, vmid: nil) ⇒ Object
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
# File 'lib/pve/proxmox.rb', line 414
def find name_or_id = nil, name: nil, vmid: nil
if (name and vmid) or (name and name_or_id) or (name_or_id and vmid)
raise Proxmox::NotFound, "name xor vmid needed to find CT, not both."
elsif name
find_by_name name
elsif vmid
find_by_vmid vmid.to_i
elsif name_or_id =~ /\D/
find_by_name name_or_id
elsif name_or_id.is_a?( Numeric) or name_or_id =~ /\d/
find_by_vmid name_or_id.to_i
else
raise Proxmox::NotFound, "name xor vmid needed to find CT."
end
end
|
.find!(name) ⇒ Object
438
439
440
|
# File 'lib/pve/proxmox.rb', line 438
def find! name
find( name) or raise( Proxmox::NotFound, "Virtual Machine not found: #{name}")
end
|
.find_by_name(name) ⇒ Object
407
408
409
410
411
412
|
# File 'lib/pve/proxmox.rb', line 407
def find_by_name name
all.each do |l|
return l if l.name == name
end
nil
end
|
.find_by_name!(name) ⇒ Object
434
435
436
|
# File 'lib/pve/proxmox.rb', line 434
def find_by_name! name
find_by_name( name) or raise( Proxmox::NotFound, "Virtual Machine not found: #{name}")
end
|
.find_by_vmid(vmid) ⇒ Object
399
400
401
402
403
404
405
|
# File 'lib/pve/proxmox.rb', line 399
def find_by_vmid vmid
vmid = vmid.to_s
all.each do |l|
return l if l.vmid == vmid
end
nil
end
|
.find_by_vmid!(name) ⇒ Object
430
431
432
|
# File 'lib/pve/proxmox.rb', line 430
def find_by_vmid! name
find_by_vmid( name) or raise( Proxmox::NotFound, "Virtual Machine not found: #{name}")
end
|
Instance Method Details
#exec(*args) ⇒ Object
456
457
458
|
# File 'lib/pve/proxmox.rb', line 456
def exec *args
node.exec 'qm', 'guest', 'exec', vmid, '--', *args
end
|
#ha ⇒ Object
452
453
454
|
# File 'lib/pve/proxmox.rb', line 452
def ha
HA.find self
end
|
#resize(disk, size) ⇒ Object
460
461
462
463
|
# File 'lib/pve/proxmox.rb', line 460
def resize disk, size
upid = rest_put "#{@rest_prefix}/resize", disk: disk, size: size
Task.send :__new__, node: @node, host: self, upid: upid
end
|
#rest_prefix ⇒ Object
443
444
445
|
# File 'lib/pve/proxmox.rb', line 443
def rest_prefix
@rest_prefix ||= "/nodes/%s/qemu/%d" % [@node.node, @vmid]
end
|