I wanted to parse geom <xxx> list/status output as JSON in a Python script I'm working on and got somewhat disappointed when I found that there was no --libxo support for geom status and list sub commands. So I thought I could add it. I haven't really written anything in C for nearly 8 years so I'm somewhat rusty and it's my first time adding libxo support to something, so please do tell me how to improve this code if you have suggestions.
Some example outputs:
gpart status --libxo json,pretty
{
"__version": "1",
"status": [
{
"name": "ada0p1",
"status": " OK",
"components": [
{
}
],
"name": "ada0p2",
"status": " OK",
"components": [
{
}
],
"name": "ada0p3",
"status": " OK",
"components": [
{
}
],
"name": "ada0p4",
"status": " OK",
"components": [
{
}
],
"name": "ada0p5",
"status": " OK",
"components": [
{
}
],
"name": "ada0p6",
"status": " OK",
"components": [
{
}
],
"name": "ada0p7",
"status": " OK",
"components": [
{
}
]
}
]
}geom multipath list --libxo json,pretty
{
"__version": "1",
"Geoms": [
{
"Name": "test",
"Type": "MANUAL",
"Mode": "Active/Active",
"UUID": "(null)",
"State": "OPTIMAL",
"Providers": [
{
"Name": "multipath/test",
"Mediasize": 1073741824,
"Sectorsize": 512,
"State": "OPTIMAL"
}
],
"Consumers": [
{
"Name": "zvol/zroot/test1",
"Mediasize": 1073741824,
"Sectorsize": 512,
"Stripesize": 8192,
"Stripesize": 0,
"Mode": "r1w1e1",
"State": "ACTIVE"
},
{
"Name": "zvol/zroot/test2",
"Mediasize": 1073741824,
"Sectorsize": 512,
"Stripesize": 8192,
"Stripesize": 0,
"Mode": "r1w1e1",
"State": "ACTIVE"
}
]
}
]
}