win_disk_facts: Adds Win32_DiskDrive object to facts (#51595)

* Adds win32_disk_drive object to win_disk_facts

* Names class parameter for Get-CimInstance as requested in the devdocs

* Maps whole class and adds docs

* Improve matching of disks when UniqueID is different format

* Improve logic for PNPDeviceID mapping

* Adds test for win32_disk_drive
This commit is contained in:
Wilmar den Ouden 2019-11-15 06:45:18 +01:00 committed by Jordan Borean
parent 762fcf78b9
commit 40071e5db3
4 changed files with 366 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- win_disk_facts - Adds Win32_DiskDrive class object as `win32_disk_drive` key to return of the module

View file

@ -109,6 +109,68 @@ foreach ($disk in $disks) {
}
}
}
$win32_disk_drive = Get-CimInstance -ClassName Win32_DiskDrive -ErrorAction SilentlyContinue | Where-Object {
if ($_.SerialNumber) {
$_.SerialNumber -eq $disk.SerialNumber
} elseif ($disk.UniqueIdFormat -eq 'Vendor Specific') {
$_.PNPDeviceID -eq $disk.UniqueId.split(':')[0]
}
}
if ($win32_disk_drive) {
$disk_info["win32_disk_drive"] += @{
availability=$win32_disk_drive.Availability
bytes_per_sector=$win32_disk_drive.BytesPerSector
capabilities=$win32_disk_drive.Capabilities
capability_descriptions=$win32_disk_drive.CapabilityDescriptions
caption=$win32_disk_drive.Caption
compression_method=$win32_disk_drive.CompressionMethod
config_manager_error_code=$win32_disk_drive.ConfigManagerErrorCode
config_manager_user_config=$win32_disk_drive.ConfigManagerUserConfig
creation_class_name=$win32_disk_drive.CreationClassName
default_block_size=$win32_disk_drive.DefaultBlockSize
description=$win32_disk_drive.Description
device_id=$win32_disk_drive.DeviceID
error_cleared=$win32_disk_drive.ErrorCleared
error_description=$win32_disk_drive.ErrorDescription
error_methodology=$win32_disk_drive.ErrorMethodology
firmware_revision=$win32_disk_drive.FirmwareRevision
index=$win32_disk_drive.Index
install_date=$win32_disk_drive.InstallDate
interface_type=$win32_disk_drive.InterfaceType
last_error_code=$win32_disk_drive.LastErrorCode
manufacturer=$win32_disk_drive.Manufacturer
max_block_size=$win32_disk_drive.MaxBlockSize
max_media_size=$win32_disk_drive.MaxMediaSize
media_loaded=$win32_disk_drive.MediaLoaded
media_type=$win32_disk_drive.MediaType
min_block_size=$win32_disk_drive.MinBlockSize
model=$win32_disk_drive.Model
name=$win32_disk_drive.Name
needs_cleaning=$win32_disk_drive.NeedsCleaning
number_of_media_supported=$win32_disk_drive.NumberOfMediaSupported
partitions=$win32_disk_drive.Partitions
pnp_device_id=$win32_disk_drive.PNPDeviceID
power_management_capabilities=$win32_disk_drive.PowerManagementCapabilities
power_management_supported=$win32_disk_drive.PowerManagementSupported
scsi_bus=$win32_disk_drive.SCSIBus
scsi_logical_unit=$win32_disk_drive.SCSILogicalUnit
scsi_port=$win32_disk_drive.SCSIPort
scsi_target_id=$win32_disk_drive.SCSITargetId
sectors_per_track=$win32_disk_drive.SectorsPerTrack
serial_number=$win32_disk_drive.SerialNumber
signature=$win32_disk_drive.Signature
size=$win32_disk_drive.Size
status=$win32_disk_drive.status
status_info=$win32_disk_drive.StatusInfo
system_creation_class_name=$win32_disk_drive.SystemCreationClassName
system_name=$win32_disk_drive.SystemName
total_cylinders=$win32_disk_drive.TotalCylinders
total_heads=$win32_disk_drive.TotalHeads
total_sectors=$win32_disk_drive.TotalSectors
total_tracks=$win32_disk_drive.TotalTracks
tracks_per_cylinder=$win32_disk_drive.TracksPerCylinder
}
}
$disk_info.number = $disk.Number
$disk_info.size = $disk.Size
$disk_info.bus_type = $disk.BusType

View file

@ -588,4 +588,304 @@ ansible_facts:
returned: always
type: str
sample: "Vendor Specific"
win32_disk_drive:
description: Representation of the Win32_DiskDrive class.
returned: if existent
type: complex
contains:
availability:
description: Availability and status of the device.
returned: always
type: int
bytes_per_sector:
description: Number of bytes in each sector for the physical disk drive.
returned: always
type: int
sample: 512
capabilities:
description:
- Array of capabilities of the media access device.
- For example, the device may support random access (3), removable media (7), and automatic cleaning (9).
returned: always
type: list
sample:
- 3
- 4
capability_descriptions:
description:
- List of more detailed explanations for any of the access device features indicated in the Capabilities array.
- Note, each entry of this array is related to the entry in the Capabilities array that is located at the same index.
returned: always
type: list
sample:
- Random Access
- Supports Writing
caption:
description: Short description of the object.
returned: always
type: str
sample: VMware Virtual disk SCSI Disk Device
compression_method:
description: Algorithm or tool used by the device to support compression.
returned: always
type: str
sample: Compressed
config_manager_error_code:
description: Windows Configuration Manager error code.
returned: always
type: int
sample: 0
config_manager_user_config:
description: If True, the device is using a user-defined configuration.
returned: always
type: bool
sample: true
creation_class_name:
description:
- Name of the first concrete class to appear in the inheritance chain used in the creation of an instance.
- When used with the other key properties of the class, the property allows all instances of this class
- and its subclasses to be uniquely identified.
returned: always
type: str
sample: Win32_DiskDrive
default_block_size:
description: Default block size, in bytes, for this device.
returned: always
type: int
sample: 512
description:
description: Description of the object.
returned: always
type: str
sample: Disk drive
device_id:
description: Unique identifier of the disk drive with other devices on the system.
returned: always
type: str
sample: "\\\\.\\PHYSICALDRIVE0"
error_cleared:
description: If True, the error reported in LastErrorCode is now cleared.
returned: always
type: bool
sample: true
error_description:
description:
- More information about the error recorded in LastErrorCode,
- and information on any corrective actions that may be taken.
returned: always
type: str
error_methodology:
description: Type of error detection and correction supported by this device.
returned: always
type: str
firmware_revision:
description: Revision for the disk drive firmware that is assigned by the manufacturer.
returned: always
type: str
sample: 1.0
index:
description:
- Physical drive number of the given drive.
- This property is filled by the STORAGE_DEVICE_NUMBER structure returned from the IOCTL_STORAGE_GET_DEVICE_NUMBER control code
- A value of 0xffffffff indicates that the given drive does not map to a physical drive.
returned: always
type: int
sample: 0
install_date:
description: Date and time the object was installed. This property does not need a value to indicate that the object is installed.
returned: always
type: str
interface_type:
description: Interface type of physical disk drive.
returned: always
type: str
sample: SCSI
last_error_code:
description: Last error code reported by the logical device.
returned: always
type: int
manufacturer:
description: Name of the disk drive manufacturer.
returned: always
type: str
sample: Seagate
max_block_size:
description: Maximum block size, in bytes, for media accessed by this device.
returned: always
type: int
max_media_size:
description: Maximum media size, in kilobytes, of media supported by this device.
returned: always
type: int
media_loaded:
description:
- If True, the media for a disk drive is loaded, which means that the device has a readable file system and is accessible.
- For fixed disk drives, this property will always be TRUE.
returned: always
type: bool
sample: true
media_type:
description: Type of media used or accessed by this device.
returned: always
type: str
sample: Fixed hard disk media
min_block_size:
description: Minimum block size, in bytes, for media accessed by this device.
returned: always
type: int
model:
description: Manufacturer's model number of the disk drive.
returned: always
type: str
sample: ST32171W
name:
description: Label by which the object is known. When subclassed, the property can be overridden to be a key property.
returned: always
type: str
sample: \\\\.\\PHYSICALDRIVE0
needs_cleaning:
description:
- If True, the media access device needs cleaning.
- Whether manual or automatic cleaning is possible is indicated in the Capabilities property.
returned: always
type: bool
number_of_media_supported:
description:
- Maximum number of media which can be supported or inserted
- (when the media access device supports multiple individual media).
returned: always
type: int
partitions:
description: Number of partitions on this physical disk drive that are recognized by the operating system.
returned: always
type: int
sample: 3
pnp_device_id:
description: Windows Plug and Play device identifier of the logical device.
returned: always
type: str
sample: "SCSI\\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\\5&1982005&0&000000"
power_management_capabilities:
description: Array of the specific power-related capabilities of a logical device.
returned: always
type: list
power_management_supported:
description:
- If True, the device can be power-managed (can be put into suspend mode, and so on).
- The property does not indicate that power management features are currently enabled,
- only that the logical device is capable of power management.
returned: always
type: bool
scsi_bus:
description: SCSI bus number of the disk drive.
returned: always
type: int
sample: 0
scsi_logical_unit:
description: SCSI logical unit number (LUN) of the disk drive.
returned: always
type: int
sample: 0
scsi_port:
description: SCSI port number of the disk drive.
returned: always
type: int
sample: 0
scsi_target_id:
description: SCSI identifier number of the disk drive.
returned: always
type: int
sample: 0
sectors_per_track:
description: Number of sectors in each track for this physical disk drive.
returned: always
type: int
sample: 63
serial_number:
description: Number allocated by the manufacturer to identify the physical media.
returned: always
type: str
sample: 6000c298f34101b38cb2b2508926b9de
signature:
description: Disk identification. This property can be used to identify a shared resource.
returned: always
type: int
size:
description:
- Size of the disk drive. It is calculated by multiplying the total number of cylinders, tracks in each cylinder,
- sectors in each track, and bytes in each sector.
returned: always
type: int
sample: 53686402560
status:
description:
- Current status of the object. Various operational and nonoperational statuses can be defined.
- 'Operational statuses include: "OK", "Degraded", and "Pred Fail"'
- (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future).
- 'Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service".'
- '"Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work.'
- Not all such work is online, yet the managed element is neither "OK" nor in one of the other states.
returned: always
type: str
sample: OK
status_info:
description:
- State of the logical device. If this property does not apply to the logical device, the value 5 (Not Applicable) should be used.
returned: always
type: int
system_creation_class_name:
description: Value of the scoping computer's CreationClassName property.
returned: always
type: str
sample: Win32_ComputerSystem
system_name:
description: Name of the scoping system.
returned: always
type: str
sample: WILMAR-TEST-123
total_cylinders:
description:
- Total number of cylinders on the physical disk drive.
- 'Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.'
- The value may be inaccurate if the drive uses a translation scheme to support high-capacity disk sizes.
- Consult the manufacturer for accurate drive specifications.
returned: always
type: int
sample: 6527
total_heads:
description:
- Total number of heads on the disk drive.
- 'Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.'
- The value may be inaccurate if the drive uses a translation scheme to support high-capacity disk sizes.
- Consult the manufacturer for accurate drive specifications.
returned: always
type: int
sample: 255
total_sectors:
description:
- Total number of sectors on the physical disk drive.
- 'Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.'
- The value may be inaccurate if the drive uses a translation scheme to support high-capacity disk sizes.
- Consult the manufacturer for accurate drive specifications.
returned: always
type: int
sample: 104856255
total_tracks:
description:
- Total number of tracks on the physical disk drive.
- 'Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.'
- The value may be inaccurate if the drive uses a translation scheme to support high-capacity disk sizes.
- Consult the manufacturer for accurate drive specifications.
returned: always
type: int
sample: 1664385
tracks_per_cylinder:
description:
- Number of tracks in each cylinder on the physical disk drive.
- 'Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.'
- The value may be inaccurate if the drive uses a translation scheme to support high-capacity disk sizes.
- Consult the manufacturer for accurate drive specifications.
returned: always
type: int
sample: 255
'''

View file

@ -15,3 +15,4 @@
- disks_found.ansible_facts.ansible_disks[0].bootable is defined
- disks_found.ansible_facts.ansible_disks[0].physical_disk.size is defined
- disks_found.ansible_facts.ansible_disks[0].physical_disk.operational_status is defined
- disks_found.ansible_facts.ansible_disks[0].win32_disk_drive is defined