Class: Inspec::Resources::FileSystemResource
- Inherits:
-
Object
- Object
- Inspec::Resources::FileSystemResource
- Defined in:
- lib/resources/filesystem.rb
Instance Attribute Summary collapse
-
#partition ⇒ Object
readonly
Returns the value of attribute partition.
Instance Method Summary collapse
- #free_kb ⇒ Object
- #info ⇒ Object
-
#initialize(partition) ⇒ FileSystemResource
constructor
A new instance of FileSystemResource.
- #name ⇒ Object
- #percent_free ⇒ Object
- #size ⇒ Object
- #size_kb ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(partition) ⇒ FileSystemResource
Returns a new instance of FileSystemResource.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/resources/filesystem.rb', line 23 def initialize(partition) @partition = partition @cache = nil # select file system manager @fsman = nil os = inspec.os if os.linux? @fsman = LinuxFileSystemResource.new(inspec) elsif os.windows? @fsman = WindowsFileSystemResource.new(inspec) else raise Inspec::Exceptions::ResourceSkipped, 'The `filesystem` resource is not supported on your OS yet.' end end |
Instance Attribute Details
#partition ⇒ Object (readonly)
Returns the value of attribute partition.
21 22 23 |
# File 'lib/resources/filesystem.rb', line 21 def partition @partition end |
Instance Method Details
#free_kb ⇒ Object
66 67 68 69 |
# File 'lib/resources/filesystem.rb', line 66 def free_kb info = @fsman.info(@partition) info[:free_kb] end |
#info ⇒ Object
39 40 41 42 43 |
# File 'lib/resources/filesystem.rb', line 39 def info return @cache if !@cache.nil? return {} if @fsman.nil? @cache = @fsman.info(@partition) end |
#name ⇒ Object
80 81 82 83 |
# File 'lib/resources/filesystem.rb', line 80 def name info = @fsman.info(@partition) info[:name] end |
#percent_free ⇒ Object
71 72 73 |
# File 'lib/resources/filesystem.rb', line 71 def percent_free 100 * free_kb / size_kb end |
#size ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/resources/filesystem.rb', line 54 def size Inspec.deprecate(:filesystem_property_size, 'The `size` property did not reliably use the correct units. Please use `size_kb` instead.') if inspec.os.windows? # On windows, we had a bug prior to #3767 in which the # 'size' value was be scaled to GB in powershell. # We now collect it in KB. (size_kb / (1024 * 1024)).to_i else size_kb end end |
#size_kb ⇒ Object
49 50 51 52 |
# File 'lib/resources/filesystem.rb', line 49 def size_kb info = @fsman.info(@partition) info[:size_kb] end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/resources/filesystem.rb', line 45 def to_s "FileSystem #{@partition}" end |
#type ⇒ Object
75 76 77 78 |
# File 'lib/resources/filesystem.rb', line 75 def type info = @fsman.info(@partition) info[:type] end |