test/framework/runner/objects/run_host_info.py
croy 82d417b9e6 New StarlingX Automation Framework
Fresh start for the StarlingX automation framework.

Change-Id: Ie265e0791024f45f71faad6315c2b91b022934d1
2024-11-29 16:01:57 -05:00

36 lines
798 B
Python

import socket
class RunHostInfoClass:
"""
Singleton Class that keeps track of the information about the host currently running the tests.
"""
def __init__(self):
self._cached_host_ip = None
def _get_host_ip_from_system(self):
"""
Gets the host ip
Returns: the host ip
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
host_ip = s.getsockname()[0]
s.close()
return host_ip
def get_host_ip(self):
"""
Gets the host ip.
Returns: the host ip
"""
if self._cached_host_ip is None:
self._cached_host_ip = self._get_host_ip_from_system()
return self._cached_host_ip
RunHostInfo = RunHostInfoClass()