Convert unicode (but otherwise valid) hostname to ASCII. Pass hostname option to hostname-change as a string rather than a list.

This commit is contained in:
James Valleroy 2013-11-02 02:20:02 +00:00
parent b9b4e0a2ec
commit a5adb1c292

View File

@ -49,9 +49,13 @@ def get_hostname():
def set_hostname(hostname):
"Sets machine hostname to hostname"
# Hostname should be ASCII. If it's unicode but passed our valid_hostname check, convert to ASCII.
hostname = str(hostname)
cfg.log.info("Changing hostname to '%s'" % hostname)
try:
privilegedaction_run("hostname-change", [hostname])
privilegedaction_run("hostname-change", hostname)
# don't persist/cache change unless it was saved successfuly
sys_store = filedict_con(cfg.store_file, 'sys')
sys_store['hostname'] = hostname