Class: VGH::System::LVM

Inherits:
Object
  • Object
show all
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

Instance Method Details

#dm_cmdString

Returns The dmsetup system command.

Returns:

  • (String)

    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

Returns:

  • (Boolean)


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
    message.warn "LVM Tools are not installed"
    return false
  end
end

#lvsString

Returns A list of logical volumes present.

Returns:

  • (String)

    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
    message.warn "Listing logical volume needs root privileges!"
  end
  return @lvs
end

#resumeObject

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
    message.info "Resuming Logical Volume '#{lv_name}'..."
    `#{dm_cmd} resume #{lv_name}`
  end
end

#suspendObject

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
    message.info "Suspending Logical Volume '#{lv_name}'..."
    `#{dm_cmd} suspend #{lv_name}`
  end
end