Add a xapi-to-sql command#7
Open
edwintorok wants to merge 1 commit intomseri:masterfrom
Open
Conversation
This introduces a dependency on sqlite-utils. When no output file is specified then the SQL is dumped to stdout. For now nested maps are kept as JSON. sqlite-utils could flatten, but it requires all the flattened elements to have the same keys, which is not true for other-config and sm-config, etc. Here is an example query: ``` SELECT VM.name_label, host.name_label, VM.domid from VM INNER JOIN VM_guest_metrics ON guest_metrics=VM_guest_metrics.ref INNER JOIN host ON resident_on=host.ref WHERE power_state='Running' AND PV_drivers_detected == "true" AND json_extract(PV_drivers_version, '$.micro')=='-1'; ``` A similar query could be achieved with `jq` on the output of `xapi-to-json`, but it is cumbersome: ``` jq 'JOIN(INDEX(.host[]; .ref); JOIN(INDEX(.VM_guest_metrics[]; .ref); .VM[]; .guest_metrics; .); .[0].resident_on; .) | select(.[0][1].PV_drivers_detected == "true") | select(.[0][1].PV_drivers_version.micro? == "-1" // false) | select(.[0][0].power_state == "Running") | "\(.[0][0].name_label); \(.[1].name_label); \(.[0][0].domid)"' ``` Signed-off-by: Edwin Török <edwin.torok@citrix.com>
Author
|
If the added dependency is a concern it might be possible to figure out a way to make it optional, probably needs some fiddling with the python project file. Although keeping it as is would be simpler. |
MarkSymsCtx
approved these changes
Nov 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces a dependency on sqlite-utils.
When no output file is specified then the SQL is dumped to stdout.
For now nested maps are kept as JSON.
sqlite-utils could flatten,
but it requires all the flattened elements to have the same keys, which is not true for other-config and sm-config, etc.
Here is an example query:
A similar query could be achieved with
jqon the output ofxapi-to-json, but it is cumbersome: