Class: DiskHandler::Partition

Inherits:
Object
  • Object
show all
Defined in:
lib/disk_reporter/disk_handler.rb

Constant Summary collapse

BLKID_REGEX =
%r[/dev/.*:\sUUID="(.{36})"\s(UUID_SUB="(.{36})"\s)*TYPE="(.*)"\s]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(disk, name) ⇒ Partition

Returns a new instance of Partition.



90
91
92
93
94
# File 'lib/disk_reporter/disk_handler.rb', line 90

def initialize(disk, name)
  self.disk = disk
  self.name = name.gsub("\n", "")
  blkid
end

Instance Attribute Details

#diskObject

Returns the value of attribute disk.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def disk
  @disk
end

#fsObject

Returns the value of attribute fs.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def fs
  @fs
end

#mountedObject

Returns the value of attribute mounted.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def mounted
  @mounted
end

#nameObject

Returns the value of attribute name.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def name
  @name
end

#typeObject

Returns the value of attribute type.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def uuid
  @uuid
end

#uuid_subObject

Returns the value of attribute uuid_sub.



88
89
90
# File 'lib/disk_reporter/disk_handler.rb', line 88

def uuid_sub
  @uuid_sub
end

Instance Method Details

#blkidObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/disk_reporter/disk_handler.rb', line 112

def blkid
  response = `#{BLKID} #{name}`
  self.fs = $?.exitstatus == 0
  # puts "FS: #{fs}"
  # puts response
  if fs?
    resp = response.scan(BLKID_REGEX)
    if resp && resp[0]
      self.uuid = resp[0][0]
      self.uuid_sub = resp[0][2]
      self.type = resp[0][3]
    end
    # puts 'check if mounted'
    # puts "grep #{name} /proc/mounts"
    mtab = `grep #{name} /proc/mounts`
    self.mounted = mtab.split(' ')[1] if $?
  end
end

#fs?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/disk_reporter/disk_handler.rb', line 108

def fs?
  !!fs
end

#is_ceph?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/disk_reporter/disk_handler.rb', line 96

def is_ceph?
  mounted? && mounted.match(%r{/var/lib/ceph/})
end

#mounted?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/disk_reporter/disk_handler.rb', line 104

def mounted?
  !!mounted
end

#should_have_ceph?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/disk_reporter/disk_handler.rb', line 100

def should_have_ceph?
  true
end