Class: Inspec::Resources::WindowsFileSystemResource
- Inherits:
-
FsManagement
- Object
- FsManagement
- Inspec::Resources::WindowsFileSystemResource
- Defined in:
- lib/resources/filesystem.rb
Instance Attribute Summary
Attributes inherited from FsManagement
Instance Method Summary collapse
Methods inherited from FsManagement
Constructor Details
This class inherits a constructor from Inspec::Resources::FsManagement
Instance Method Details
#info(partition) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/resources/filesystem.rb', line 108 def info(partition) cmd = inspec.command <<-EOF.gsub(/^\s*/, '') $disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='#{partition}'" $disk.Size = $disk.Size / 1KB $disk.FreeSpace = $disk.FreeSpace / 1KB $disk | select -property DeviceID,Size,FileSystem,FreeSpace | ConvertTo-Json EOF raise Inspec::Exceptions::ResourceSkipped, "Unable to get available space for partition #{partition}" if cmd.stdout == '' || cmd.exit_status.to_i != 0 begin fs = JSON.parse(cmd.stdout) rescue JSON::ParserError => e raise Inspec::Exceptions::ResourceFailed, 'Failed to parse JSON from Powershell. ' \ "Error: #{e}" end { name: fs['DeviceID'], size_kb: fs['Size'].to_i, free_kb: fs['FreeSpace'].to_i, type: fs['FileSystem'], } end |