Class: VGH::System::LVM
- Inherits:
-
Object
- Object
- VGH::System::LVM
- Defined in:
- lib/vgh/system/lvm.rb
Overview
This class is able to suspend or resume logical volumes. The lvm2
package needs to be installed for this to work.
Suspending a volume becomes useful if you want for example a consistent EC2 snapshot of it. Any I/O that has already been mapped by the device but has not yet completed will be flushed. Any further I/O to that device will be postponed for as long as the device is suspended.
Usage:
lvm = System::LVM.new
lvm.suspend
# run the code that takes the snapshot
lvm.resume
Instance Method Summary collapse
-
#dm_cmd ⇒ String
The dmsetup system command.
-
#installed? ⇒ Boolean
Warn message if LVM tools are not installed.
-
#lvs ⇒ String
A list of logical volumes present.
-
#resume ⇒ Object
The actual resume action.
-
#suspend ⇒ Object
The actual suspend action.
Instance Method Details
#dm_cmd ⇒ String
Returns The dmsetup system command.
23 24 25 |
# File 'lib/vgh/system/lvm.rb', line 23 def dm_cmd @dmcmd ||= '/sbin/dmsetup' end |
#installed? ⇒ Boolean
Warn message if LVM tools are not installed
28 29 30 31 32 33 34 35 |
# File 'lib/vgh/system/lvm.rb', line 28 def installed? if File.exists?(dm_cmd) return true else .warn "LVM Tools are not installed" return false end end |
#lvs ⇒ String
Returns A list of logical volumes present.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vgh/system/lvm.rb', line 38 def lvs @lvs = [] if ( installed? and System.is_root? ) lv_list = `#{dm_cmd} ls | /bin/grep -E -v 'swap|root'` @lvs.push(lv_list.split[0]) unless lv_list == "No devices found\n" else .warn "Listing logical volume needs root privileges!" end return @lvs end |
#resume ⇒ Object
The actual resume action
58 59 60 61 62 63 |
# File 'lib/vgh/system/lvm.rb', line 58 def resume for lv_name in lvs .info "Resuming Logical Volume '#{lv_name}'..." `#{dm_cmd} resume #{lv_name}` end end |
#suspend ⇒ Object
The actual suspend action
50 51 52 53 54 55 |
# File 'lib/vgh/system/lvm.rb', line 50 def suspend for lv_name in lvs .info "Suspending Logical Volume '#{lv_name}'..." `#{dm_cmd} suspend #{lv_name}` end end |