1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/sfdisk.md

234 lines
5.8 KiB
Markdown
Raw Normal View History

2021-06-30 12:38:36 -07:00
[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.sfdisk"></a>
2021-06-30 12:38:36 -07:00
# jc.parsers.sfdisk
2022-01-25 17:07:47 -08:00
2021-06-30 12:38:36 -07:00
jc - JSON CLI output utility `sfdisk` command output parser
Supports the following `sfdisk` options:
- `-l`
2021-08-30 21:53:40 -07:00
- `-F`
- `-d` (deprecated - only for older versions of util-linux)
- `-uM` (deprecated - only for older versions of util-linux)
- `-uC` (deprecated - only for older versions of util-linux)
- `-uS` (deprecated - only for older versions of util-linux)
- `-uB` (deprecated - only for older versions of util-linux)
2021-06-30 12:38:36 -07:00
Usage (cli):
2022-01-25 18:03:34 -08:00
# sfdisk -l | jc --sfdisk
2021-06-30 12:38:36 -07:00
2022-01-25 18:03:34 -08:00
or
2021-06-30 12:38:36 -07:00
2022-01-25 18:03:34 -08:00
# jc sfdisk -l
2021-06-30 12:38:36 -07:00
Usage (module):
2022-01-25 18:03:34 -08:00
import jc
result = jc.parse('sfdisk', sfdisk_command_output)
2022-01-18 15:38:03 -08:00
2022-01-25 18:03:34 -08:00
or
2022-01-18 15:38:03 -08:00
2022-01-25 18:03:34 -08:00
import jc.parsers.sfdisk
result = jc.parsers.sfdisk.parse(sfdisk_command_output)
2021-06-30 12:38:36 -07:00
Schema:
2022-01-25 18:03:34 -08:00
[
{
"disk": string,
"disk_size": string,
"free_disk_size": string,
"bytes": integer,
"free_bytes": integer,
"sectors": integer,
"free_sectors": integer,
"cylinders": integer,
"heads": integer,
"sectors_per_track": integer,
"units": string,
"logical_sector_size": integer,
"physical_sector_size": integer,
"min_io_size": integer,
"optimal_io_size": integer,
"disk_label_type": string,
"disk_identifier": string,
"disk_model": string,
"partitions": [
{
"device": string,
"boot": boolean,
"start": integer,
"end": integer,
"size": string, # [0]
"cyls": integer,
"mib": integer,
"blocks": integer,
"sectors": integer,
"id": string,
"system": string,
"type": string
}
]
}
]
[0] will be integer when using deprecated -d sfdisk option
Examples:
# sfdisk -l | jc --sfdisk -p
[
{
"disk": "/dev/sda",
"cylinders": 2610,
"heads": 255,
"sectors_per_track": 63,
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, ...",
"partitions": [
{
"device": "/dev/sda1",
"boot": true,
"start": 0,
"end": 130,
"cyls": 131,
"blocks": 1048576,
"id": "83",
"system": "Linux"
},
{
"device": "/dev/sda2",
"boot": false,
"start": 130,
"end": 2610,
"cyls": 2481,
"blocks": 19921920,
"id": "8e",
"system": "Linux LVM"
},
{
"device": "/dev/sda3",
"boot": false,
"start": 0,
"end": null,
"cyls": 0,
"blocks": 0,
"id": "0",
"system": "Empty"
},
{
"device": "/dev/sda4",
"boot": false,
"start": 0,
"end": null,
"cyls": 0,
"blocks": 0,
"id": "0",
"system": "Empty"
}
]
},
{
"disk": "/dev/mapper/centos-root",
"cylinders": 2218,
"heads": 255,
"sectors_per_track": 63
},
{
"disk": "/dev/mapper/centos-swap",
"cylinders": 261,
"heads": 255,
"sectors_per_track": 63
}
]
# sfdisk -l | jc --sfdisk -p -r
[
{
"disk": "/dev/sda",
"cylinders": "2610",
"heads": "255",
"sectors_per_track": "63",
"units": "cylinders of 8225280 bytes, blocks of 1024 bytes, co...",
"partitions": [
{
"device": "/dev/sda1",
"boot": "*",
"start": "0+",
"end": "130-",
"cyls": "131-",
"blocks": "1048576",
"id": "83",
"system": "Linux"
},
{
"device": "/dev/sda2",
"boot": null,
"start": "130+",
"end": "2610-",
"cyls": "2481-",
"blocks": "19921920",
"id": "8e",
"system": "Linux LVM"
},
{
"device": "/dev/sda3",
"boot": null,
"start": "0",
"end": "-",
"cyls": "0",
"blocks": "0",
"id": "0",
"system": "Empty"
},
{
"device": "/dev/sda4",
"boot": null,
"start": "0",
"end": "-",
"cyls": "0",
"blocks": "0",
"id": "0",
"system": "Empty"
}
]
},
{
"disk": "/dev/mapper/centos-root",
"cylinders": "2218",
"heads": "255",
"sectors_per_track": "63"
},
{
"disk": "/dev/mapper/centos-swap",
"cylinders": "261",
"heads": "255",
"sectors_per_track": "63"
}
]
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.sfdisk.parse"></a>
2022-01-25 19:18:54 -08:00
### parse
2022-01-25 17:07:47 -08:00
2021-06-30 12:38:36 -07:00
```python
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False)
2021-06-30 12:38:36 -07:00
```
Main text parsing function
2022-01-25 18:03:34 -08:00
Parameters:
2021-06-30 12:38:36 -07:00
2022-01-25 18:03:34 -08:00
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
2021-06-30 12:38:36 -07:00
2022-01-25 18:03:34 -08:00
Returns:
2021-06-30 12:38:36 -07:00
2022-01-25 18:03:34 -08:00
List of Dictionaries. Raw or processed structured data.
2021-06-30 12:38:36 -07:00
2022-01-25 19:18:54 -08:00
### Parser Information
2021-06-30 12:38:36 -07:00
Compatibility: linux
2021-12-01 16:12:51 -08:00
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)