Class: Inspec::Resources::FileSystemResource

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/filesystem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(partition) ⇒ FileSystemResource

Returns a new instance of FileSystemResource.



13
14
15
# File 'lib/resources/filesystem.rb', line 13

def initialize(partition)
  @partition = partition
end

Instance Attribute Details

#partitionObject (readonly)

Returns the value of attribute partition.



11
12
13
# File 'lib/resources/filesystem.rb', line 11

def partition
  @partition
end

Instance Method Details

#sizeObject



17
18
19
20
21
22
23
24
25
# File 'lib/resources/filesystem.rb', line 17

def size
  @size ||= begin
    cmd = inspec.command("df #{partition} --output=size")
    raise Inspec::Exceptions::ResourceFailed, "Unable to get available space for partition #{partition}" if cmd.stdout.nil? || cmd.stdout.empty? || !cmd.exit_status.zero?

    value = cmd.stdout.gsub(/\dK-blocks[\r\n]/, '').strip
    value.to_i
  end
end

#to_sObject



27
28
29
# File 'lib/resources/filesystem.rb', line 27

def to_s
  "Filesystem #{partition}"
end