summaryrefslogtreecommitdiff
path: root/automated
diff options
context:
space:
mode:
authorAnders Roxell <anders.roxell@linaro.org>2016-10-01 17:26:54 +0200
committerMilosz Wasilewski <milosz.wasilewski@linaro.org>2016-10-27 11:25:24 +0000
commit8c4bfe3eb387760bd59e876440d3273f20d67470 (patch)
treec22cb6d9f73892b28f51540c2bd6f0be9d87a017 /automated
parentc2e2f698aa666e3ead64aecfa4d12d965798a6f3 (diff)
automated/utils: add vland helper functions.
get_vland_interface and get_vland_mac Change-Id: I32e84c985ca4e59eb695bcc8312da9d6de1643a4 Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Diffstat (limited to 'automated')
-rwxr-xr-xautomated/utils/vland/get_vland_interface.sh56
-rwxr-xr-xautomated/utils/vland/get_vland_mac.sh11
2 files changed, 67 insertions, 0 deletions
diff --git a/automated/utils/vland/get_vland_interface.sh b/automated/utils/vland/get_vland_interface.sh
new file mode 100755
index 0000000..fcca95a
--- /dev/null
+++ b/automated/utils/vland/get_vland_interface.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+set -e
+
+get_vland_entry() {
+ lava-vland-names | grep "^${1}" | cut -d , -f 2
+}
+
+get_vland_sys_path() {
+ vland_entries=$(get_vland_entry "${1}")
+ if [ -z "${vland_entries}" ]; then
+ echo "No valid vland name given" >&2
+ echo "Alternatives are:" >&2
+ get_vland_names >&2
+ exit 1
+ fi
+ lava-vland-self | grep -F "${vland_entries}" | cut -d , -f 3-
+}
+
+get_vland_interface() {
+ sys_path=$(get_vland_sys_path "${1}")
+ find "${sys_path}" -maxdepth 1 -mindepth 1 -type d | sed -e 's|.*/||g'
+}
+
+get_vland_names() {
+ lava-vland-names | cut -d , -f 1 | grep -v "^$"
+}
+
+##
+# Main entry point
+
+vland_name=${1}
+
+if [ -z "$(which lava-vland-names 2>/dev/null)" ]; then
+ echo "Not in LAVA"
+ exit 1
+fi
+
+if [ -n "${vland_name}" ]; then
+ ret=$(get_vland_interface "${vland_name}")
+ if [ -n "${ret}" ]; then
+ echo "${ret}"
+ exit 0
+ fi
+ echo "No such vland: $vland_name" >&2
+ exit 1
+fi
+
+if [ "$(get_vland_names|wc -l)" -ne 1 ]; then
+ echo "More then one vland name available" >&2
+ echo "Alternatives are:" >&2
+ get_vland_names >&2
+ exit 1
+else
+ get_vland_interface "$(get_vland_names)"
+fi
diff --git a/automated/utils/vland/get_vland_mac.sh b/automated/utils/vland/get_vland_mac.sh
new file mode 100755
index 0000000..cb96939
--- /dev/null
+++ b/automated/utils/vland/get_vland_mac.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+set -e
+
+vland_name="${1}"
+
+iface=$("$(readlink -f "$(dirname "$0")")"/get_vland_interface.sh "${vland_name}")
+if [ -z "${iface}" ]; then
+ exit 1
+fi
+cat /sys/class/net/"${iface}"/address