def Parse(self, query, result, knowledge_base): """Parse the wmi packages output.""" _ = query, knowledge_base result = result.ToDict() winvolume = rdf_client.WindowsVolume( drive_letter=result.get("DeviceID"), drive_type=result.get("DriveType")) try: size = int(result.get("Size")) except (ValueError, TypeError): size = None try: free_space = int(result.get("FreeSpace")) except (ValueError, TypeError): free_space = None # Since we don't get the sector sizes from WMI, we just set them at 1 byte volume = rdf_client.Volume( windowsvolume=winvolume, name=result.get("VolumeName"), file_system_type=result.get("FileSystem"), serial_number=result.get("VolumeSerialNumber"), sectors_per_allocation_unit=1, bytes_per_sector=1, total_allocation_units=size, actual_available_allocation_units=free_space) yield volume
class WindowsVolumeClientMock(ActionMock): """A mock of client filesystem volumes.""" windows_d = rdf_client.WindowsVolume(drive_letter="D:") windows_c = rdf_client.WindowsVolume(drive_letter="C:") path_results = [ rdf_client.Volume( windowsvolume=windows_d, bytes_per_sector=4096, sectors_per_allocation_unit=1, actual_available_allocation_units=50, total_allocation_units=100), rdf_client.Volume( windowsvolume=windows_c, bytes_per_sector=4096, sectors_per_allocation_unit=1, actual_available_allocation_units=10, total_allocation_units=100)] def WmiQuery(self, query): if query.query == u"SELECT * FROM Win32_LogicalDisk": return client_fixture.WMI_SAMPLE else: return None