Parted Parsers
Classes to parse parted command information.
Parsers provided by this module include:
PartedL - command parted -l -s
- class insights.parsers.parted.PartedDevice(content)[source]
Bases:
objectClass to contain information for one device of
partedcommand output.The columns of partation table may vary depending upon the type of device.
- device_info
Dictionary of information of this device.
- Type:
dict
- partitions
The partitions of this device, as Partition objects.
- Type:
list
- boot_partition
the first partition marked as bootable, or
Noneif one was not found.- Type:
- Raises:
ParseException -- Raised if command output of this device indicates “error” or “warning” in first line, or if “disk” field is not present, or if there is an error parsing the data.
- property data
Device information.
- Type:
dict
- property disk
Disk information.
- Type:
str
- property logical_sector_size
Logical part of sector size.
- Type:
str
- property physical_sector_size
Physical part of sector size.
- Type:
str
- class insights.parsers.parted.PartedL(context, extra_bad_lines=None)[source]
Bases:
CommandParserClass to represent attributes of the
parted -l -scommand output.- devices_info
The devices found in the output, as PartedDevice objects.
- Type:
list
Typical content of the
parted -l -scommand output looks like:Model: ATA TOSHIBA MG04ACA4 (scsi) Disk /dev/sda: 4001GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: pmbr_boot Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 526MB 524MB xfs 3 526MB 4001GB 4000GB lvm Model: IBM 2107900 (scsi) Disk /dev/sdb: 2147MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32.3kB 2580kB 2548kB primary
The columns of partation table may vary depending upon the type of device.
Note
The examples in this module may be executed with the following command:
python -m insights.parsers.partedExamples
>>> [device.disk for device in parted_l_results] ['/dev/sda', '/dev/sdb'] >>> parted_info = parted_l_results.get('/dev/sda') >>> sorted(parted_info.device_info.items()) [('disk', '/dev/sda'), ('disk_flags', 'pmbr_boot'), ('model', 'ATA TOSHIBA MG04ACA4 (scsi)'), ('partition_table', 'gpt'), ('sector_size', '512B/512B'), ('size', '4001GB')] >>> parted_info.device_info['model'] 'ATA TOSHIBA MG04ACA4 (scsi)' >>> parted_info.disk '/dev/sda' >>> parted_info.logical_sector_size '512B' >>> parted_info.physical_sector_size '512B' >>> parted_info.boot_partition >>> parted_info.device_info['disk_flags'] 'pmbr_boot' >>> len(parted_info.partitions) 3 >>> sorted(parted_info.partitions[0].data.items()) [('end', '2097kB'), ('file_system', ''), ('flags', 'bios_grub'), ('name', ''), ('number', '1'), ('size', '1049kB'), ('start', '1049kB')] >>> parted_info.partitions[0].number '1' >>> parted_info.partitions[0].start '1049kB' >>> parted_info.partitions[0].end '2097kB' >>> parted_info.partitions[0].size '1049kB' >>> parted_info.partitions[0].file_system '' >>> parted_info.partitions[0].type >>> parted_info.partitions[0].flags 'bios_grub'
- class insights.parsers.parted.Partition(data)[source]
Bases:
objectClass to contain information for one partition.
Represents the values from one row of the partition information from the
partedcommand. Column names have been converted to lowercase and are provided as attributes. Column names may vary so thegetmethod may be used to check for the presence of a column.- data
Dictionary of partition information keyed by column names in lowercase.
- Type:
dict
- property end
Ending location for the partition.
- Type:
str
- property file_system
File system type.
- Type:
str
- property flags
Partition flags.
- Type:
str
- property number
Partition number.
- Type:
str
- property size
Size of the partition.
- Type:
str
- property start
Starting location for the partition.
- Type:
str
- property type
File system type.
- Type:
str