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.
-
#logical_name ⇒ Object
Returns the value of attribute logical_name.
-
#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
- .all ⇒ Object
- .find_especific_devname(obj, key) ⇒ Object
- .find_partitions(disk, all_partitions) ⇒ Object
- .find_slaves(path, all_partitions) ⇒ Object
- .proc_partitions_hash(especific_devname = nil) ⇒ Object
- .swap ⇒ Object
Instance Method Summary collapse
- #capacity ⇒ Object
- #dev ⇒ Object
- #disk? ⇒ Boolean
- #free_percent ⇒ Object
-
#initialize(devname, path = nil) ⇒ Disk
constructor
A new instance of Disk.
- #mounting_point ⇒ Object
- #partition? ⇒ Boolean
- #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(devname, path = nil) ⇒ Disk
Returns a new instance of Disk.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mool/disk.rb', line 24 def initialize(devname, path = nil) @unity = Mool::BYTES @devname = devname @path = if path.nil? Mool::Disk.proc_partitions_hash(@devname)[:path] else path end raise "Does't exist #{devname} on #{@path}" if @path.nil? || @devname.nil? lname = Mool::Command.logical_name(@path) @logical_name = lname.blank? ? @devname : lname read_uevent capacity 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 |
#logical_name ⇒ Object
Returns the value of attribute logical_name.
3 4 5 |
# File 'lib/mool/disk.rb', line 3 def logical_name @logical_name 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
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/mool/disk.rb', line 238 def self.all disks = [] proc_partitions_hash.each do |disk_name, disk_opts| all_partitions = [] disk = Mool::Disk.new(disk_name, disk_opts[:path]) disk_opts[:partitions].map do |partition_name, partition_opts| partition = Mool::Disk.new( partition_name, partition_opts[:path] ) all_partitions << partition partition.slaves = partition_opts[:slaves].map do |slave_name, slave_opts| Mool::Disk.new( slave_name, slave_opts[:path] ) end end disk.partitions = all_partitions disk.slaves = disk_opts[:slaves].map do |slave_name, slave_opts| Mool::Disk.new( slave_name, slave_opts[:path] ) end disks << disk end 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 |
.find_especific_devname(obj, key) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/mool/disk.rb', line 204 def self.find_especific_devname(obj, key) if obj.respond_to?(:key?) && obj.key?(key) obj[key] elsif obj.respond_to?(:each) r = nil obj.find { |*a| r = find_especific_devname(a.last, key) } r end end |
.find_partitions(disk, all_partitions) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/mool/disk.rb', line 184 def self.find_partitions(disk, all_partitions) parts = Mool::Command.partitions(disk) result = {} parts.each do |part| all_partitions.each do |partition| devname = partition[3] next unless part.include?(devname) all_partitions.delete(partition) result[devname] = { path: part, slaves: find_slaves(part, all_partitions) } end end result end |
.find_slaves(path, all_partitions) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/mool/disk.rb', line 167 def self.find_slaves(path, all_partitions) slaves = Mool::Command.holders(path) result = {} slaves.each do |slave| all_partitions.each do |partition| devname = partition[3] next unless slave.include?(devname) all_partitions.delete(partition) result[devname] = { path: path + "/holders/#{slave}" } end end result end |
.proc_partitions_hash(especific_devname = nil) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/mool/disk.rb', line 214 def self.proc_partitions_hash(especific_devname = nil) all_partitions = Mool::Command.all_partitions.scan(/(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/) hash_disks = {} all_partitions.each do |partition| if partition[3].include?('ram') || partition[3].include?('sr') all_partitions.delete(partition) next end devname = partition[3] path = "/sys/block/#{devname}" next unless Mool::Command.root_block_device?(devname) all_partitions.delete(partition) hash_disks[devname] = { path: path, partitions: find_partitions(devname, all_partitions), slaves: find_slaves(path, all_partitions) } end return hash_disks if especific_devname.nil? find_especific_devname(hash_disks, especific_devname) end |
Instance Method Details
#capacity ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mool/disk.rb', line 84 def capacity return if defined?(@total_block) && defined?(@block_used) && defined?(@block_free) result = Mool::Command.df.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
68 69 70 |
# File 'lib/mool/disk.rb', line 68 def dev @major + @minor end |
#disk? ⇒ Boolean
72 73 74 |
# File 'lib/mool/disk.rb', line 72 def disk? @devtype == 'disk' end |
#free_percent ⇒ Object
126 127 128 |
# File 'lib/mool/disk.rb', line 126 def free_percent @block_free / @total_block end |
#mounting_point ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mool/disk.rb', line 41 def mounting_point @mount_point = nil Mool::Command.mount.include?(@devname) && @mount_point ||= Mool::Command.mount.scan( /#{@devname} (\S+)/ ).flatten.first end |
#partition? ⇒ Boolean
76 77 78 |
# File 'lib/mool/disk.rb', line 76 def partition? @devtype == 'partition' end |
#read_uevent ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/mool/disk.rb', line 58 def read_uevent @major, @minor, @devname, @devtype = Mool::Command.uevent(@path).split("\n").map do |result| result.split('=').last end end |
#to_b ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/mool/disk.rb', line 130 def to_b Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::BYTES) end |
#to_gb ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/mool/disk.rb', line 154 def to_gb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::GBYTES) end |
#to_kb ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/mool/disk.rb', line 138 def to_kb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::KBYTES) end |
#to_mb ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/mool/disk.rb', line 146 def to_mb Mool.parse_to(self, ['@total_block', '@block_used', '@block_free'], Mool::MBYTES) end |
#used_percent ⇒ Object
122 123 124 |
# File 'lib/mool/disk.rb', line 122 def used_percent @block_used / @total_block end |