Skip to content

Commit

Permalink
Prepare testbed_network_devices.fact for managerless (#1754)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Sep 15, 2023
1 parent 7662ef7 commit dad3684
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions environments/custom/files/testbed_network_devices.fact
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import netifaces
import subprocess

NETWORKS = {
"external": "192.168.96",
Expand Down Expand Up @@ -39,4 +40,19 @@ for interface in netifaces.interfaces():
# NOTE: vxlan is always used as provider network.
result["provider"] = "vxlan0"


# If result is empty, we are probably on the managerless deployment path
# and use the IP address of the 1st interface accordingly.
if "management" not in result:
r = subprocess.check_output(
"hostname --all-ip-addresses | awk '{print $1}'", shell=True
)
firstip_address = r.decode().strip()

r = subprocess.check_output(
"ip -br -4 a sh | grep %s | awk '{print $1}'" % firstip_address, shell=True
)
first_network_interface = r.decode().strip()
result["management"] = first_network_interface

print(json.dumps(result))

0 comments on commit dad3684

Please sign in to comment.