class ManageIQ::ApplianceConsole::LogicalVolumeManagement

Attributes

disk[RW]

Required instantiation parameters

filesystem_type[RW]

Derived or optionally provided instantiation parameters

logical_volume[R]

Logical Disk creation objects

logical_volume_path[RW]

Derived or optionally provided instantiation parameters

mount_point[RW]

Required instantiation parameters

name[RW]

Required instantiation parameters

partition[R]

Logical Disk creation objects

physical_volume[R]

Logical Disk creation objects

volume_group[R]

Logical Disk creation objects

volume_group_name[RW]

Derived or optionally provided instantiation parameters

Public Class Methods

new(options = {}) click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 18
def initialize(options = {})
  # Required instantiation parameters
  self.disk        = options[:disk]        || raise(ArgumentError, "disk object required")
  self.mount_point = options[:mount_point] || raise(ArgumentError, "mount point required")
  self.name        = options[:name]        || raise(ArgumentError, "unique name required")

  # Derived or optionally provided instantiation parameters
  self.volume_group_name   ||= "vg_#{name}"
  self.filesystem_type     ||= "xfs"
  self.logical_volume_path ||= "/dev/#{volume_group_name}/lv_#{name}"
end

Public Instance Methods

setup() click to toggle source

Helper method

# File lib/manageiq/appliance_console/logical_volume_management.rb, line 31
def setup
  create_partition_to_fill_disk
  create_physical_volume
  create_volume_group
  create_logical_volume_to_fill_volume_group
  format_logical_volume
  update_fstab
  lazy_unmount_mount_point
  mount_disk
end

Private Instance Methods

create_logical_volume_to_fill_volume_group() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 65
def create_logical_volume_to_fill_volume_group
  @logical_volume = LinuxAdmin::LogicalVolume.create(logical_volume_path, volume_group, 100)
end
create_partition_to_fill_disk() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 44
def create_partition_to_fill_disk
  # Check if you need to create a GPT part table or a MSDOS one in base of
  # max size of partition table
  max_msdos_ptable_size = 2.terabyte
  self.disk = LinuxAdmin::Disk.local.find { |d| d.path == disk.path }

  partition_type = disk.size >= max_msdos_ptable_size ? 'gpt' : 'msdos'
  disk.create_partition_table(partition_type)

  AwesomeSpawn.run!("parted -s #{disk.path} mkpart primary 0% 100%")
  @partition = disk.partitions.first
end
create_physical_volume() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 57
def create_physical_volume
  @physical_volume = LinuxAdmin::PhysicalVolume.create(partition)
end
create_volume_group() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 61
def create_volume_group
  @volume_group = LinuxAdmin::VolumeGroup.create(volume_group_name, physical_volume)
end
format_logical_volume() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 69
def format_logical_volume
  AwesomeSpawn.run!("mkfs.#{filesystem_type} #{logical_volume.path}")
end
lazy_unmount_mount_point() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 73
def lazy_unmount_mount_point
  AwesomeSpawn.run!("umount", :params => ["-l", mount_point.to_s]) if File.file?("/proc/mounts") && File.read("/proc/mounts").include?(" #{mount_point} ")
end
mount_disk() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 77
def mount_disk
  if mount_point.symlink?
    FileUtils.rm_rf(mount_point)
    FileUtils.mkdir_p(mount_point)
  end
  AwesomeSpawn.run!("mount", :params => ["-a"])
end
update_fstab() click to toggle source
# File lib/manageiq/appliance_console/logical_volume_management.rb, line 85
def update_fstab
  fstab = LinuxAdmin::FSTab.instance
  entry = fstab.entries.find { |e| e.mount_point == mount_point.to_s } || LinuxAdmin::FSTabEntry.new
  fstab.entries.delete(entry)

  entry.device        = logical_volume_path
  entry.mount_point   = mount_point
  entry.fs_type       = filesystem_type
  entry.mount_options = "rw,noatime"
  entry.dumpable      = 0
  entry.fsck_order    = 0

  fstab.entries << entry
  fstab.write!
end