PartedL - command parted -l
¶
This module provides processing for the parted
command. The output is parsed
by the PartedL
class. Attributes are provided for each field for the disk,
and a list of Partition
class objects, one for each partition in the output.
Typical content of the parted -l
command 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
The columns 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.parted
Examples
>>> parted_data = '''
... 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
... '''.strip()
>>> from insights.tests import context_wrap
>>> shared = {PartedL: PartedL(context_wrap(parted_data))}
>>> parted_info = shared[PartedL]
>>> parted_info.data
{'partition_table': 'gpt', 'sector_size': '512B/512B', 'disk_flags': 'pmbr_boot', 'partitions': [{'end': '2097kB', 'name': 'bios_grub', 'number': '1', 'start': '1049kB', 'flags': 'bios_grub', 'file_system': 'bios_grub', 'size': '1049kB'}, {'start': '2097kB', 'size': '524MB', 'end': '526MB', 'number': '2', 'file_system': 'xfs'}, {'end': '4001GB', 'name': 'lvm', 'number': '3', 'start': '526MB', 'flags': 'lvm', 'file_system': 'lvm', 'size': '4000GB'}], 'model': 'ATA TOSHIBA MG04ACA4 (scsi)', 'disk': '/dev/sda', 'size': '4001GB'}
>>> parted_info.data['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.data['disk_flags']
'pmbr_boot'
>>> len(parted_info.partitions)
3
>>> parted_info.partitions[0].data
{'end': '2097kB', 'name': 'bios_grub', 'number': '1', 'start': '1049kB', 'flags': 'bios_grub', 'file_system': 'bios_grub', 'size': '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
'bios_grub'
>>> parted_info.partitions[0].type
>>> parted_info.partitions[0].flags
'bios_grub'
-
class
insights.parsers.parted.
PartedL
(context, extra_bad_lines=[])[source]¶ Bases:
insights.core.CommandParser
Class to represent attributes of the
parted
command output.The columns may vary depending upon the type of device.
-
data
¶ Dictionary of information returned by
parted
command.- Type
dict
-
partitions
¶ The partitions found in the output, as Partition objects.
- Type
list
-
boot_partition
¶ the first partition marked as bootable, or
None
if one was not found.- Type
- Raises
ParseException -- Raised if
parted
output indicates “error” or “warning” in first line, or if “disk” field is not present, or if there is an error parsing the data.ValueError -- Raised if there is an error parsing the partition table.
-
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.
Partition
(data)[source]¶ Bases:
object
Class to contain information for one partition.
Represents the values from one row of the partition information from the
parted
command. Column names have been converted to lowercase and are provided as attributes. Column names may vary so theget
method 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
-