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.



85
86
87
88
89
# File 'lib/disk_reporter/disk_handler.rb', line 85

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

Instance Attribute Details

#diskObject

Returns the value of attribute disk.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def disk
  @disk
end

#fsObject

Returns the value of attribute fs.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def fs
  @fs
end

#mountedObject

Returns the value of attribute mounted.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def mounted
  @mounted
end

#nameObject

Returns the value of attribute name.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def name
  @name
end

#typeObject

Returns the value of attribute type.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def uuid
  @uuid
end

#uuid_subObject

Returns the value of attribute uuid_sub.



83
84
85
# File 'lib/disk_reporter/disk_handler.rb', line 83

def uuid_sub
  @uuid_sub
end

Instance Method Details

#blkidObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/disk_reporter/disk_handler.rb', line 107

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)


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

def fs?
  !!fs
end

#is_ceph?Boolean

Returns:

  • (Boolean)


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

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

#mounted?Boolean

Returns:

  • (Boolean)


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

def mounted?
  !!mounted
end

#should_have_ceph?Boolean

Returns:

  • (Boolean)


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

def should_have_ceph?
  true
end