From 8c4bfe3eb387760bd59e876440d3273f20d67470 Mon Sep 17 00:00:00 2001 From: Anders Roxell Date: Sat, 1 Oct 2016 17:26:54 +0200 Subject: automated/utils: add vland helper functions. get_vland_interface and get_vland_mac Change-Id: I32e84c985ca4e59eb695bcc8312da9d6de1643a4 Signed-off-by: Anders Roxell --- automated/utils/vland/get_vland_interface.sh | 56 ++++++++++++++++++++++++++++ automated/utils/vland/get_vland_mac.sh | 11 ++++++ 2 files changed, 67 insertions(+) create mode 100755 automated/utils/vland/get_vland_interface.sh create mode 100755 automated/utils/vland/get_vland_mac.sh (limited to 'automated') 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 -- cgit v1.2.3