This commit is contained in:
@@ -7,7 +7,6 @@ import xml.etree.ElementTree as ET
|
|||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def configure_logging():
|
def configure_logging():
|
||||||
current_file = Path(__file__).resolve()
|
current_file = Path(__file__).resolve()
|
||||||
sdsat_root = current_file.parent.parent
|
sdsat_root = current_file.parent.parent
|
||||||
@@ -28,12 +27,10 @@ def configure_logging():
|
|||||||
root.handlers.clear()
|
root.handlers.clear()
|
||||||
root.addHandler(handler)
|
root.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
def generate_random_string(length: int) -> str:
|
def generate_random_string(length: int) -> str:
|
||||||
letters = string.ascii_lowercase
|
letters = string.ascii_lowercase
|
||||||
return "".join(random.choice(letters) for _ in range(length))
|
return "".join(random.choice(letters) for _ in range(length))
|
||||||
|
|
||||||
|
|
||||||
def update_config_hostname(config_path: str, new_hostname: str) -> tuple[str | None, bool]:
|
def update_config_hostname(config_path: str, new_hostname: str) -> tuple[str | None, bool]:
|
||||||
"""
|
"""
|
||||||
Met à jour <hostname> dans le XML.
|
Met à jour <hostname> dans le XML.
|
||||||
@@ -55,12 +52,10 @@ def update_config_hostname(config_path: str, new_hostname: str) -> tuple[str | N
|
|||||||
|
|
||||||
return old_hostname, changed
|
return old_hostname, changed
|
||||||
|
|
||||||
|
|
||||||
def apply_hostname(new_hostname: str) -> int:
|
def apply_hostname(new_hostname: str) -> int:
|
||||||
# Retourne le code retour de la commande
|
# Retourne le code retour de la commande
|
||||||
return os.system(f"sudo hostname {new_hostname}")
|
return os.system(f"sudo hostname {new_hostname}")
|
||||||
|
|
||||||
|
|
||||||
def main(
|
def main(
|
||||||
expected_hostname: str = "sd-satxx.dtx.io",
|
expected_hostname: str = "sd-satxx.dtx.io",
|
||||||
config_path: str = "/conf/config.xml",
|
config_path: str = "/conf/config.xml",
|
||||||
@@ -86,6 +81,5 @@ def main(
|
|||||||
rc = apply_hostname(new_hostname)
|
rc = apply_hostname(new_hostname)
|
||||||
logging.info(f"Hostname change completed successfully (rc={rc})")
|
logging.info(f"Hostname change completed successfully (rc={rc})")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user