names: Use hostnamectl instead of socket API get the current hostname

- This would mean consistent interfacing with systemd instead of a split
approach.

Tests:

- Edit hostname page shows the current value of hostname correctly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-01-05 17:45:24 -08:00 committed by James Valleroy
parent 4176f53e05
commit d9f9168c76
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -242,7 +242,9 @@ def get_domain_name():
def get_hostname():
"""Return the hostname."""
return socket.gethostname()
process = subprocess.run(['hostnamectl', 'hostname', '--static'],
stdout=subprocess.PIPE, check=True)
return process.stdout.decode().strip()
def set_hostname(hostname):