Class: Mool::Disk
Instance Attribute Summary collapse
-
#block_free ⇒ Object
Returns the value of attribute block_free.
-
#block_used ⇒ Object
Returns the value of attribute block_used.
-
#devname ⇒ Object
Returns the value of attribute devname.
-
#devtype ⇒ Object
Returns the value of attribute devtype.
-
#file_system ⇒ Object
Returns the value of attribute file_system.
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#mount_point ⇒ Object
Returns the value of attribute mount_point.
-
#partitions ⇒ Object
Returns the value of attribute partitions.
-
#path ⇒ Object
Returns the value of attribute path.
-
#size ⇒ Object
Returns the value of attribute size.
-
#slaves ⇒ Object
Returns the value of attribute slaves.
-
#swap ⇒ Object
Returns the value of attribute swap.
-
#total_block ⇒ Object
Returns the value of attribute total_block.
-
#unity ⇒ Object
Returns the value of attribute unity.
Class Method Summary collapse
Instance Method Summary collapse
- #capacity ⇒ Object
- #dev ⇒ Object
- #free_percent ⇒ Object
-
#initialize(dev_name) ⇒ Disk
constructor
A new instance of Disk.
- #is_disk? ⇒ Boolean
- #is_partition? ⇒ Boolean
- #logical_name ⇒ Object
- #mounting_point ⇒ Object
- #read_uevent ⇒ Object
- #to_b ⇒ Object
- #to_gb ⇒ Object
- #to_kb ⇒ Object
- #to_mb ⇒ Object
- #used_percent ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(dev_name) ⇒ Disk
Returns a new instance of Disk.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mool/disk.rb', line 19 def initialize(dev_name) @path = nil Mool::Command.dev_block_command.each do |entry| logical_name = Mool::Command.logical_name_command(entry) next unless Mool::Command.dev_name_command(entry).include?(dev_name) || Mool::Command.uevent_command(entry).include?(dev_name) || (logical_name.present? && logical_name.include?(dev_name)) @path = entry break end raise "Does't exist #{dev_name}!" if @path.nil? read_uevent logical_name swap capacity @unity = Mool::BYTES mounting_point file_system end |
Instance Attribute Details
#block_free ⇒ Object
Returns the value of attribute block_free.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def block_free @block_free end |
#block_used ⇒ Object
Returns the value of attribute block_used.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def block_used @block_used end |
#devname ⇒ Object
Returns the value of attribute devname.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def devname @devname end |
#devtype ⇒ Object
Returns the value of attribute devtype.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def devtype @devtype end |
#file_system ⇒ Object
Returns the value of attribute file_system.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def file_system @file_system end |
#major ⇒ Object
Returns the value of attribute major.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def minor @minor end |
#mount_point ⇒ Object
Returns the value of attribute mount_point.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def mount_point @mount_point end |
#partitions ⇒ Object
Returns the value of attribute partitions.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def partitions @partitions end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def path @path end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def size @size end |
#slaves ⇒ Object
Returns the value of attribute slaves.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def slaves @slaves end |
#swap ⇒ Object
Returns the value of attribute swap.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def swap @swap end |
#total_block ⇒ Object
Returns the value of attribute total_block.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def total_block @total_block end |
#unity ⇒ Object
Returns the value of attribute unity.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def unity @unity end |
Class Method Details
.all ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/mool/disk.rb', line 166 def self.all disks = [] Mool::Command.dev_block_command.each do |entry| real_path = Mool::Command.real_path_block_command(entry) next unless !real_path.include?('virtual') && !real_path.include?('/sr') && !Mool::Command.real_path_command_exist?(real_path) && Mool::Command.slaves_command(real_path).empty? disks << Mool::Disk.new(entry.split('/').last) end disks.each { |disk| disk.partitions.each { |part| part.partitions && part.slaves }} disks.each { |disk| disk.slaves.each { |part| part.partitions && part.slaves }} disks end |
.all_usable ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/mool/disk.rb', line 189 def self.all_usable result = Mool::Disk.all result.each do |disk| result += (disk.partitions + disk.slaves + (disk.partitions + disk.slaves).collect { |p| p.partitions + p.slaves }.flatten) end result.reject(&:blank?).select { |d| (d.partitions + d.slaves).blank? } end |
Instance Method Details
#capacity ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/mool/disk.rb', line 91 def capacity return if defined?(@total_block) && defined?(@block_used) && defined?(@block_free) result = Mool::Command.df_command.scan( /(#{@logical_name}|#{@devname})\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/ ).flatten @total_block = Mool::Command.capacity_partition_command(@path).chomp.to_f * Mool::BLOCK_SIZE @block_used = result[2].to_f * Mool::BLOCK_SIZE @block_free = @total_block - @block_used end |
#dev ⇒ Object
75 76 77 |
# File 'lib/mool/disk.rb', line 75 def dev @major + @minor end |
#free_percent ⇒ Object
130 131 132 |
# File 'lib/mool/disk.rb', line 130 def free_percent @block_free / @total_block end |
#is_disk? ⇒ Boolean
79 80 81 |
# File 'lib/mool/disk.rb', line 79 def is_disk? @devtype == 'disk' end |
#is_partition? ⇒ Boolean
83 84 85 |
# File 'lib/mool/disk.rb', line 83 def is_partition? @devtype == 'partition' end |
#logical_name ⇒ Object
57 58 59 60 |
# File 'lib/mool/disk.rb', line 57 def logical_name lname = Mool::Command.logical_name_command(@path) @logical_name = lname.present? ? lname : @devname end |
#mounting_point ⇒ Object
41 42 43 44 45 46 |
# File 'lib/mool/disk.rb', line 41 def mounting_point Mool::Command.mount_command.include?(@logical_name) && @mount_point ||= Mool::Command.mount_command.scan( /#{@logical_name} (\S+)/ ).flatten.first end |
#read_uevent ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mool/disk.rb', line 62 def read_uevent @major, @minor, @devname, @devtype = Mool::Command.uevent_command(@path).split("\n").map do |result| result.split('=').last end # Mool::Command.uevent_command(@path).scan( # /.*=(\d+)\n.*=(\d+)\n.*=(\S+)\n.*=(\w+)\n/ # ).flatten end |
#to_b ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/mool/disk.rb', line 134 def to_b Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::BYTES) end |
#to_gb ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/mool/disk.rb', line 158 def to_gb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::GBYTES) end |
#to_kb ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/mool/disk.rb', line 142 def to_kb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::KBYTES) end |
#to_mb ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/mool/disk.rb', line 150 def to_mb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::MBYTES) end |
#used_percent ⇒ Object
126 127 128 |
# File 'lib/mool/disk.rb', line 126 def used_percent @block_used / @total_block end |