Class: PrlBackup::VirtualMachine
- Inherits:
-
Object
- Object
- PrlBackup::VirtualMachine
- Extended by:
- Enumerable, PrlBackup
- Includes:
- PrlBackup
- Defined in:
- lib/prlbackup/virtual_machine.rb
Constant Summary
Constants included from PrlBackup
Class Method Summary collapse
-
.all ⇒ Array<VirtualMachine>
Return a list of all virtual machines.
-
.each ⇒ Object
Iterate over all virtual machines.
- .to_s ⇒ Object
Instance Method Summary collapse
-
#==(other_vm) ⇒ Object
Is equal if the virtual machines UUIDs are equal.
-
#cleanup ⇒ Object
Cleanup (delete) old backups.
- #config ⇒ Object
-
#initialize(name_or_uuid) ⇒ VirtualMachine
constructor
Initialize with a valid name or UUID from the virtual machine.
-
#name ⇒ String
Return the virtual machine’s name.
-
#safely_backup(full = false) ⇒ Object
Safely backup the virtual machine.
-
#to_s ⇒ Object
Return the virtual machine’s name.
-
#uuid ⇒ String
Return the virtual machine’s UUID.
Methods included from PrlBackup
conditionally_run, logger, run
Constructor Details
#initialize(name_or_uuid) ⇒ VirtualMachine
Initialize with a valid name or UUID from the virtual machine.
28 29 30 31 |
# File 'lib/prlbackup/virtual_machine.rb', line 28 def initialize(name_or_uuid) @name_or_uuid = name_or_uuid update_info end |
Class Method Details
.all ⇒ Array<VirtualMachine>
Return a list of all virtual machines.
17 18 19 20 |
# File 'lib/prlbackup/virtual_machine.rb', line 17 def all cmd = %w{prlctl list --all --output uuid} run(*cmd).split("\n").grep(/(\{[a-f0-9-]+\})/) { new($1) } end |
.each ⇒ Object
Iterate over all virtual machines.
11 12 13 |
# File 'lib/prlbackup/virtual_machine.rb', line 11 def each all.each { |virtual_machine| yield(virtual_machine) } end |
.to_s ⇒ Object
22 23 24 |
# File 'lib/prlbackup/virtual_machine.rb', line 22 def to_s 'VM' end |
Instance Method Details
#==(other_vm) ⇒ Object
Is equal if the virtual machines UUIDs are equal.
61 62 63 |
# File 'lib/prlbackup/virtual_machine.rb', line 61 def ==(other_vm) uuid == other_vm.uuid end |
#cleanup ⇒ Object
Cleanup (delete) old backups.
44 45 46 |
# File 'lib/prlbackup/virtual_machine.rb', line 44 def cleanup full_backups.shift.delete while full_backups.count > config[:keep_only] end |
#config ⇒ Object
33 34 35 |
# File 'lib/prlbackup/virtual_machine.rb', line 33 def config PrlBackup.config end |
#name ⇒ String
Return the virtual machine’s name.
50 51 52 |
# File 'lib/prlbackup/virtual_machine.rb', line 50 def name info[/^Name:\s+(.+)$/,1] if info end |
#safely_backup(full = false) ⇒ Object
A running virtual machine will be stopped during the backup!
Safely backup the virtual machine.
39 40 41 |
# File 'lib/prlbackup/virtual_machine.rb', line 39 def safely_backup(full=false) stopped? ? backup : (stop; backup; start) end |
#to_s ⇒ Object
Return the virtual machine’s name.
66 67 68 |
# File 'lib/prlbackup/virtual_machine.rb', line 66 def to_s "VM: %s" % (name || 'Unknown') end |
#uuid ⇒ String
Return the virtual machine’s UUID.
56 57 58 |
# File 'lib/prlbackup/virtual_machine.rb', line 56 def uuid info[/^ID:\s+(\{[a-f0-9-]+\})$/,1] if info end |