From 55399b2bcf8061570ccf4d625949a80ac2d30232 Mon Sep 17 00:00:00 2001 From: Erwan MAS Date: Tue, 28 Apr 2020 04:59:48 +0000 Subject: [PATCH] fix lshw json issue . instead of of filtering with lswh use a jq function to filter --- common/usr/bin/openstack-cluster-installer-agent | 2 +- .../share/openstack-cluster-installer-common/filterclass.jq | 1 + debian/openstack-cluster-installer-common.install | 1 + utils/usr/bin/oci-hdd-maint | 6 +++--- 4 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 common/usr/share/openstack-cluster-installer-common/filterclass.jq diff --git a/common/usr/bin/openstack-cluster-installer-agent b/common/usr/bin/openstack-cluster-installer-agent index b57c52c5..1acf1704 100755 --- a/common/usr/bin/openstack-cluster-installer-agent +++ b/common/usr/bin/openstack-cluster-installer-agent @@ -56,7 +56,7 @@ fi echo ' "interfaces": [' >>${TMPFILE2} for i in $(ip link show | grep -v '^ ' | grep -v 'lo:' | cut -d' ' -f2 | cut -d: -f1 | grep -v vlan | grep -v -E 'bond|qvb.*|qvo.*|vxlan.*|tap.*|qbr.*|qr.*|sg-.*|ha-.*|ovs.*|qg-.*|sg-.*|fg-.*|ovs-system|br-ex|br-int|br-tun|vlan.*') ; do MAC_ADDR=$(ip link show dev $i | grep 'link/ether' | awk '{print $2}') - ETH_SPEED=$(( $(lshw -class network -json 2>/dev/null | jq '.[] | select(.serial|test("'${MAC_ADDR}'")) | .capacity' | head -n 1) / 1000000)) + ETH_SPEED=$(( $(lshw -json 2>/dev/null | jq -f /usr/share/openstack-cluster-installer-common/filterclass.jq --arg F_ARG network | jq '.[] | select(.serial|test("'${MAC_ADDR}'")) | .capacity' | head -n 1) / 1000000)) # Find the neighbors using lldpcli if lldpcli -f json show neighbors | jq -r '.[]["interface"][] | keys[]' | grep -q $i ; then diff --git a/common/usr/share/openstack-cluster-installer-common/filterclass.jq b/common/usr/share/openstack-cluster-installer-common/filterclass.jq new file mode 100644 index 00000000..b8e86666 --- /dev/null +++ b/common/usr/share/openstack-cluster-installer-common/filterclass.jq @@ -0,0 +1 @@ +def filterclass(c): . as $in | if type == "object" then if has("class") and .class == c then [ $in ] else reduce keys[] as $key ( []; . + [$in[$key] | filterclass(c)] ) end elif type == "array" then map( filterclass(c) ) else empty end; filterclass($F_ARG) | flatten diff --git a/debian/openstack-cluster-installer-common.install b/debian/openstack-cluster-installer-common.install index ce9fd344..64372aa8 100644 --- a/debian/openstack-cluster-installer-common.install +++ b/debian/openstack-cluster-installer-common.install @@ -1 +1,2 @@ common/usr/bin/* /usr/bin +common/usr/share/openstack-cluster-installer-common/* /usr/share/openstack-cluster-installer-common/ diff --git a/utils/usr/bin/oci-hdd-maint b/utils/usr/bin/oci-hdd-maint index a3fa0bda..5d042e04 100755 --- a/utils/usr/bin/oci-hdd-maint +++ b/utils/usr/bin/oci-hdd-maint @@ -4,8 +4,8 @@ set -e #set -x show_disk_status () { - if [ ""$(lshw -class storage -json 2>/dev/null | jq -r '.[]["id"]' | head -n1) = "raid" ] ; then - HDRAID_PROD=$(lshw -class storage -json 2>/dev/null | jq -r '.[]["product"]') + if [ ""$(lshw -json 2>/dev/null | jq -f /usr/share/openstack-cluster-installer-common/filterclass.jq --arg F_ARG storage | jq -r '.[]["id"]' | head -n1) = "raid" ] ; then + HDRAID_PROD=$(lshw -json 2>/dev/null | jq -f /usr/share/openstack-cluster-installer-common/filterclass.jq --arg F_ARG storage | jq -r '.[]["product"]') # echo "Detected RAID card: ${HDRAID_PROD}" #number of physical disks @@ -70,7 +70,7 @@ else if [ -z "${2}" ] ; then usage fi - if [ ""$(lshw -class storage -json 2>/dev/null | jq -r '.[]["id"]' | head -n1) = "raid" ] ; then + if [ ""$(lshw -json 2>/dev/null | jq -f /usr/share/openstack-cluster-installer-common/filterclass.jq --arg F_ARG storage | jq -r '.[]["id"]' | head -n1) = "raid" ] ; then echo "Setting up RAID for device ${2}..." megacli -DiscardPreservedCache -Lall -a0 megacli -CfgLdAdd -r0[32:${2}] WB RA Direct -a0 -- GitLab