Bug 1334659
| Summary: | Make it possible to report output from lvm2 reporting commands in JSON format | ||
|---|---|---|---|
| Product: | [Community] LVM and device-mapper | Reporter: | Peter Rajnoha <prajnoha> |
| Component: | lvm2 | Assignee: | Peter Rajnoha <prajnoha> |
| lvm2 sub component: | Displaying and Reporting | QA Contact: | cluster-qe <cluster-qe> |
| Status: | CLOSED UPSTREAM | Docs Contact: | |
| Severity: | low | ||
| Priority: | medium | CC: | agk, heinzm, jbrassow, msnitzer, prajnoha, zkabelac |
| Version: | unspecified | Flags: | prajnoha:
lvm-technical-solution+
rule-engine: lvm-test-coverage? |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2017-08-24 08:39:42 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | 1334655 | ||
| Bug Blocks: | 1334682, 1346079 | ||
|
Description
Peter Rajnoha
2016-05-10 09:12:31 UTC
Specifics for JSON format and libdevmapper's report group API:
struct dm_report_group *dm_report_group_create(dm_report_group_type_t type, void *data)
--> "type" is DM_REPORT_GROUP_JSON, "data" is not used
int dm_report_group_push(struct dm_report_group *group, struct dm_report *report, void *data)
--> "data" is a name of the array under which the report is done in JSON format (each report is an array of rows for JSON format). If "report" is NULL, it's just a named wrapping array for the reports that follow. If "report" is NULL and "data" is NULL at the same time, it's unnamed wrapping object in JSON.
int dm_report_group_pop(struct dm_report_group *group)
--> Adds closing brackets (to end object) or square brackets (to end array), based on what the appropriate "push" operation was
int dm_report_group_destroy(struct dm_report_group *group)
--> Adds closing brackets for the whole JSON output.
Example:
# lvs
LV VG Attr LSize
root fedora -wi-ao---- 19.00g
swap fedora -wi-ao---- 500.00m
lvol0 vg -wi-a----- 4.00m
# lvs --reportformat json
{
"report": [
{
"lv": [
{"lv_name":"root", "vg_name":"fedora", "lv_attr":"-wi-ao----", "lv_size":"19.00g"},
{"lv_name":"swap", "vg_name":"fedora", "lv_attr":"-wi-ao----", "lv_size":"500.00m"},
{"lv_name":"lvol0", "vg_name":"vg", "lv_attr":"-wi-a-----", "lv_size":"4.00m"}
]
}
]
}
It's possible to switch report output from all lvm2 reporting command into JSON format since lvm2 version 2.02.158.
There's global report/output_format lvm.conf setting as well as --reportformat command line options (which takes precedence over report/output_format lvm.conf setting) to set the output format.
See also man 7 lvmreport for more information.
Example:
[0] rhel7-a/~ # lvmconfig --type diff
report {
compact_output=1
}
[0] rhel7-a/~ # lvs
LV VG Attr LSize
root rhel -wi-ao---- 9.02g
swap rhel -wi-ao---- 500.00m
[0] rhel7-a/~ # vim /etc/lvm/lvm.conf
[0] rhel7-a/~ # lvmconfig --type diff
report {
output_format="json"
compact_output=1
}
[0] rhel7-a/~ # lvs
{
"report": [
{
"lv": [
{"lv_name":"root", "vg_name":"rhel", "lv_attr":"-wi-ao----", "lv_size":"9.02g"},
{"lv_name":"swap", "vg_name":"rhel", "lv_attr":"-wi-ao----", "lv_size":"500.00m"}
]
}
]
}
[0] rhel7-a/~ # lvs --reportformat basic
LV VG Attr LSize
root rhel -wi-ao---- 9.02g
swap rhel -wi-ao---- 500.00m
[0] rhel7-a/~ # lvs --reportformat json
{
"report": [
{
"lv": [
{"lv_name":"root", "vg_name":"rhel", "lv_attr":"-wi-ao----", "lv_size":"9.02g"},
{"lv_name":"swap", "vg_name":"rhel", "lv_attr":"-wi-ao----", "lv_size":"500.00m"}
]
}
]
}
|