Class: PrlBackup::VirtualMachine

Inherits:
Object
  • Object
show all
Extended by:
Enumerable, PrlBackup
Includes:
PrlBackup
Defined in:
lib/prlbackup/virtual_machine.rb

Constant Summary

Constants included from PrlBackup

VERSION

Class Method Summary collapse

Instance Method Summary collapse

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

.allArray<VirtualMachine>

Return a list of all virtual machines.

Returns:



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

.eachObject

Iterate over all virtual machines.

Parameters:

  • (Block)


11
12
13
# File 'lib/prlbackup/virtual_machine.rb', line 11

def each
  all.each { |virtual_machine| yield(virtual_machine) }
end

.to_sObject



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

#cleanupObject

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

#configObject



33
34
35
# File 'lib/prlbackup/virtual_machine.rb', line 33

def config
  PrlBackup.config
end

#nameString

Return the virtual machine’s name.

Returns:

  • (String)


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

Note:

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_sObject

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

#uuidString

Return the virtual machine’s UUID.

Returns:

  • (String)


56
57
58
# File 'lib/prlbackup/virtual_machine.rb', line 56

def uuid
  info[/^ID:\s+(\{[a-f0-9-]+\})$/,1] if info
end