Hostname¶
- class rmote.tools.hostname.Hostname[source]¶
Bases:
ToolManage system hostname and
/etc/hostsentries. Requires root for mutating operations.Change the hostname in a disposable container with its own UTS namespace:
>>> from rmote.tools import FileSystem >>> remote = getfixture("debian_tool") >>> remote(Hostname.set, "rmote-example") True >>> remote(Hostname.set, "rmote-example") False >>> remote(Hostname.get) 'rmote-example' >>> remote(FileSystem.read_str, "/etc/hostname").strip() 'rmote-example' >>> remote(Hostname.hosts_entry, "192.0.2.1", "web") True >>> remote(Hostname.hosts_entry, "192.0.2.1", "web") False
- static get()[source]¶
Return the current running hostname.
Reads from
/proc/sys/kernel/hostnamewhich always reflects the live kernel value regardless of what/etc/hostnamecontains.- Return type:
- Returns:
The hostname string.
- static hosts_entry(ip, *names)[source]¶
Ensure
/etc/hostshas an entry mapping ip to names.If a line for ip already exists with exactly the same hostnames (in the same order), this is a no-op. If it exists with different hostnames, the line is replaced in-place. If no line exists for ip, one is appended.
Comment lines and blank lines are left untouched.
- Parameters:
- Return type:
- Returns:
Trueif/etc/hostswas modified.- Raises:
ValueError – If no names are provided.