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.
-
#free_size ⇒ Object
Returns the value of attribute free_size.
-
#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.
-
#percentage_used ⇒ Object
Returns the value of attribute percentage_used.
-
#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.
-
#total_size ⇒ Object
Returns the value of attribute total_size.
-
#unity ⇒ Object
Returns the value of attribute unity.
-
#used_size ⇒ Object
Returns the value of attribute used_size.
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mool/disk.rb', line 23 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 |
#free_size ⇒ Object
Returns the value of attribute free_size.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def free_size @free_size 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 |
#percentage_used ⇒ Object
Returns the value of attribute percentage_used.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def percentage_used @percentage_used 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 |
#total_size ⇒ Object
Returns the value of attribute total_size.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def total_size @total_size end |
#unity ⇒ Object
Returns the value of attribute unity.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def unity @unity end |
#used_size ⇒ Object
Returns the value of attribute used_size.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def used_size @used_size end |
Class Method Details
.all ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/mool/disk.rb', line 176 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.each do |disk| disk.partitions.each do |partition| partition.slaves.each do |slave| partition.total_size += slave.total_size partition.used_size += slave.used_size partition.free_size += slave.free_size partition.block_free += slave.block_free partition.block_used += slave.block_used partition.total_block += slave.total_block end disk.total_size += partition.total_size disk.used_size += partition.used_size disk.free_size += partition.free_size disk.block_free += partition.block_free disk.block_used += partition.block_used disk.total_block += partition.total_block end end disks end |
.all_usable ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/mool/disk.rb', line 219 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 |
.swap ⇒ Object
214 215 216 217 |
# File 'lib/mool/disk.rb', line 214 def self.swap result = Mool::Command.swap_command.scan(%r{/.*\n\/dev\/(\S+)/}).flatten.first Mool::Disk.new(result) unless result.nil? end |
Instance Method Details
#capacity ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mool/disk.rb', line 96 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 @total_block = result[1].to_f @total_size = result[1].to_f * Mool::BLOCK_SIZE @block_used = result[2].to_f @block_free = result[3].to_f @used_size = result[2].to_f * Mool::BLOCK_SIZE @free_size = result[3].to_f * Mool::BLOCK_SIZE return if result.empty? @percentage_used = result[4].delete('%') end |
#dev ⇒ Object
80 81 82 |
# File 'lib/mool/disk.rb', line 80 def dev @major + @minor end |
#free_percent ⇒ Object
140 141 142 |
# File 'lib/mool/disk.rb', line 140 def free_percent @block_free / @total_block end |
#is_disk? ⇒ Boolean
84 85 86 |
# File 'lib/mool/disk.rb', line 84 def is_disk? @devtype == 'disk' end |
#is_partition? ⇒ Boolean
88 89 90 |
# File 'lib/mool/disk.rb', line 88 def is_partition? @devtype == 'partition' end |
#logical_name ⇒ Object
62 63 64 65 |
# File 'lib/mool/disk.rb', line 62 def logical_name lname = Mool::Command.logical_name_command(@path) @logical_name = lname.present? ? lname : @devname end |
#mounting_point ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/mool/disk.rb', line 45 def mounting_point @mount_point = nil Mool::Command.mount_command.include?(@logical_name) && @mount_point ||= Mool::Command.mount_command.scan( /#{@logical_name} (\S+)/ ).flatten.first end |
#read_uevent ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mool/disk.rb', line 67 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
144 145 146 147 148 149 150 |
# File 'lib/mool/disk.rb', line 144 def to_b Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::BYTES) end |
#to_gb ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/mool/disk.rb', line 168 def to_gb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::GBYTES) end |
#to_kb ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/mool/disk.rb', line 152 def to_kb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::KBYTES) end |
#to_mb ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/mool/disk.rb', line 160 def to_mb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::MBYTES) end |
#used_percent ⇒ Object
136 137 138 |
# File 'lib/mool/disk.rb', line 136 def used_percent @block_used / @total_block end |