From bc9bf92025c2dbe1742da1af39a9738ea7c9eb55 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 31 Oct 2016 15:56:27 +0100 Subject: [run-virt] Use xmlstarlet for xml operations --- .../vmchooser/run-virt-includes/get_xml_file_variables.inc | 4 +--- .../vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc | 9 +++++++++ remote/modules/run-virt/module.conf | 1 + remote/modules/run-virt/module.conf.ubuntu | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) (limited to 'remote') diff --git a/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc b/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc index d40d97bb..cf0d545b 100644 --- a/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc +++ b/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc @@ -8,9 +8,7 @@ declare -rg VMSTORE_PATH=/mnt/vmstore # Need some lean and mean xml parser some day in the far future get_xml () { - grep -Pio "<$1"'\s+param=[^"]*".*' "${xmlfile}" \ - | awk -F '"' '{ print $2 }' \ - | sed 's/&/+/g;s/"/"/g;s/<//g' + xmlextract "//settings/eintrag/${1}/@param" "${xmlfile}" } IMGUUID=$(get_xml "uuid") diff --git a/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc b/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc index 7519a48d..ca475da0 100644 --- a/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc +++ b/remote/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc @@ -96,3 +96,12 @@ notempty() { return 0 } +## +# Extract given xpath from given xml file +# e.g.: xmlextract '//node/nestednode/@attribute' "$file" +# @param +# @return Plain text, UTF-8 +xmlextract() { + xmlstarlet sel -T -E utf-8 -t -v "$1" "$2" +} + diff --git a/remote/modules/run-virt/module.conf b/remote/modules/run-virt/module.conf index 73155f89..cc1b34a6 100644 --- a/remote/modules/run-virt/module.conf +++ b/remote/modules/run-virt/module.conf @@ -3,5 +3,6 @@ REQUIRED_BINARIES=" mcopy pwdaemon slxfwtool + xmlstarlet " diff --git a/remote/modules/run-virt/module.conf.ubuntu b/remote/modules/run-virt/module.conf.ubuntu index b06efa7a..b6008fa0 100644 --- a/remote/modules/run-virt/module.conf.ubuntu +++ b/remote/modules/run-virt/module.conf.ubuntu @@ -1,9 +1,11 @@ REQUIRED_INSTALLED_PACKAGES=" usbutils mtools + xmlstarlet " REQUIRED_CONTENT_PACKAGES=" usbutils mtools + xmlstarlet " -- cgit v1.2.3-55-g7522