Class: Proxmox::Qemu

Inherits:
Hosted show all
Defined in:
lib/pve/proxmox.rb

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?

Methods included from RestConnection

#bench, #rest_del, #rest_get, #rest_post, #rest_put

Constructor Details

#initializeQemu

Returns a new instance of Qemu.



451
452
453
454
# File 'lib/pve/proxmox.rb', line 451

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

.allObject



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



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/pve/proxmox.rb', line 418

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



442
443
444
# File 'lib/pve/proxmox.rb', line 442

def find! name
  find( name) or raise( Proxmox::NotFound, "Virtual Machine not found: #{name}")
end

.find_by_name(name) ⇒ Object



409
410
411
412
413
414
415
416
# File 'lib/pve/proxmox.rb', line 409

def find_by_name name
  Node.all.each do |n|
    n.qemu.each do |l|
      return l  if l.name == name
    end
  end
  nil
end

.find_by_name!(name) ⇒ Object



438
439
440
# File 'lib/pve/proxmox.rb', line 438

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
406
407
# File 'lib/pve/proxmox.rb', line 399

def find_by_vmid vmid
  vmid = vmid.to_s
  Node.all.each do |n|
    n.qemu.each do |l|
      return l  if l.vmid == vmid
    end
  end
  nil
end

.find_by_vmid!(name) ⇒ Object



434
435
436
# File 'lib/pve/proxmox.rb', line 434

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



460
461
462
# File 'lib/pve/proxmox.rb', line 460

def exec *args
  node.exec 'qm', 'guest', 'exec', vmid, '--', *args
end

#haObject



456
457
458
# File 'lib/pve/proxmox.rb', line 456

def ha
  HA.find self
end

#resize(disk, size) ⇒ Object



464
465
466
467
# File 'lib/pve/proxmox.rb', line 464

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_prefixObject



447
448
449
# File 'lib/pve/proxmox.rb', line 447

def rest_prefix
  @rest_prefix ||= "/nodes/%s/qemu/%d" % [@node.node, @vmid]
end