Sha256: 30668a8a605f56f0f2ccfb5b5300bea8f4c3aa1e798b4065acbc42d0b5026484

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

# LinuxAdmin Partition Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

require 'fileutils'

class LinuxAdmin
  class Partition < LinuxAdmin
    attr_accessor :id
    attr_accessor :partition_type
    attr_accessor :fs_type
    attr_accessor :start_sector
    attr_accessor :end_sector
    attr_accessor :size
    attr_accessor :disk
    attr_accessor :mount_point

    def initialize(args={})
      @id      = args[:id]
      @size    = args[:size]
      @disk    = args[:disk]
      @fs_type = args[:fs_type]
      @start_sector   = args[:start_sector]
      @end_sector     = args[:end_sector]
      @partition_type = args[:partition_type]
    end

    def path
      "#{disk.path}#{id}"
    end

    def format_to(filesystem)
      run!(cmd(:mke2fs),
          :params => { '-t' => filesystem, nil => self.path})
      @fs_type = filesystem
    end

    def mount(mount_point=nil)
      @mount_point = mount_point
      @mount_point  =
        "/mnt/#{disk.path.split(File::SEPARATOR).last}#{id}" if mount_point.nil?
      FileUtils.mkdir(@mount_point) unless File.directory?(@mount_point)

      run!(cmd(:mount),
          :params => { nil => [self.path, @mount_point] })
    end

    def umount
      run!(cmd(:umount),
          :params => { nil => [@mount_point] })
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
linux_admin-0.5.4 lib/linux_admin/partition.rb
linux_admin-0.5.3 lib/linux_admin/partition.rb
linux_admin-0.5.2 lib/linux_admin/partition.rb
linux_admin-0.5.1 lib/linux_admin/partition.rb
linux_admin-0.5.0 lib/linux_admin/partition.rb
linux_admin-0.4.1 lib/linux_admin/partition.rb
linux_admin-0.4.0 lib/linux_admin/partition.rb
linux_admin-0.3.0 lib/linux_admin/partition.rb
linux_admin-0.2.3 lib/linux_admin/partition.rb
linux_admin-0.2.2 lib/linux_admin/partition.rb
linux_admin-0.2.1 lib/linux_admin/partition.rb
linux_admin-0.2.0 lib/linux_admin/partition.rb