Sha256: b137862a2b89bfaad2a19f19926af97356db71a0e441f79eb73f691773468f8b

Contents?: true

Size: 1.14 KB

Versions: 12

Compression:

Stored size: 1.14 KB

Contents

# LinuxAdmin Mountable Disk Mixin
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

class LinuxAdmin
  module Mountable
    attr_accessor :fs_type
    attr_accessor :mount_point

    module ClassMethods
      def mount_point_exists?(mount_point)
        result = self.run!(cmd(:mount))
        result.output.split("\n").any? { |line| line.split[2] == mount_point }
      end

      def mount_point_available?(mount_point)
        !mount_point_exists?(mount_point)
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

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

    def mount(mount_point)
      FileUtils.mkdir(mount_point) unless File.directory?(mount_point)

      if self.class.mount_point_exists?(mount_point)
        raise ArgumentError, "disk already mounted at #{mount_point}"
      end

      run!(cmd(:mount), :params => { nil => [self.path, mount_point] })
      @mount_point = 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.9.4 lib/linux_admin/mountable.rb
linux_admin-0.9.3 lib/linux_admin/mountable.rb
linux_admin-0.9.2 lib/linux_admin/mountable.rb
linux_admin-0.9.1 lib/linux_admin/mountable.rb
linux_admin-0.9.0 lib/linux_admin/mountable.rb
linux_admin-0.8.1 lib/linux_admin/mountable.rb
linux_admin-0.8.0 lib/linux_admin/mountable.rb
linux_admin-0.7.0 lib/linux_admin/mountable.rb
linux_admin-0.6.0 lib/linux_admin/mountable.rb
linux_admin-0.5.7 lib/linux_admin/mountable.rb
linux_admin-0.5.6 lib/linux_admin/mountable.rb
linux_admin-0.5.5 lib/linux_admin/mountable.rb