From 5025f3e7af62f2e24bbb395f354f9421fc362b29 Mon Sep 17 00:00:00 2001 From: Marco Capetta Date: Thu, 4 Sep 2025 11:01:48 +0200 Subject: [PATCH] MT#63514 Add sites support to get_all_ips_for_host script Change-Id: I30cd9f99e1a63f5725aaecf2c084aac175f13543 (cherry picked from commit 04e6f0e56770e7e7d1dbf616be5de7da78a2643c) (cherry picked from commit 7979e69315f9a239978f2fa95db87c547aa22099) --- lib/get_all_ips_for_host | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/get_all_ips_for_host b/lib/get_all_ips_for_host index 7b59281b..5a1d4479 100644 --- a/lib/get_all_ips_for_host +++ b/lib/get_all_ips_for_host @@ -3,13 +3,18 @@ # Return an array of IPs for a given host. # +# @param argv.site The site to use, default value: current. # @param argv.host The host to get all IPs for. # @param argv.type The interface type or empty string for all types. # @param argv.status node status [ online, offline, inactive ] # default value: ['online', 'inactive'] # @return out The array of IPs. -IF !hosts.${argv.host}.defined; +IF !argv.site.length; + argv.site = 'current'; +END; + +IF !sites.${argv.site}.hosts.${argv.host}.defined; argv.host = 'self'; END; @@ -31,13 +36,13 @@ FOREACH val IN argv.status; END; out = []; -IF status.item(hosts.${argv.host}.status); - FOREACH iface IN hosts.${argv.host}.interfaces; - NEXT UNLESS hosts.${argv.host}.exists(iface); - NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size(); - NEXT UNLESS hosts.${argv.host}.$iface.ip; +IF status.item(sites.${argv.site}.hosts.${argv.host}.status); + FOREACH iface IN sites.${argv.site}.hosts.${argv.host}.interfaces; + NEXT UNLESS sites.${argv.site}.hosts.${argv.host}.exists(iface); + NEXT UNLESS sites.${argv.site}.hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size(); + NEXT UNLESS sites.${argv.site}.hosts.${argv.host}.$iface.ip; - out.push(hosts.${argv.host}.$iface.ip); + out.push(sites.${argv.site}.hosts.${argv.host}.$iface.ip); END; END; out = out.sort;