From 2b090511832f1898f7d15cc33a6b9b20a8d88e07 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Wed, 15 Nov 2017 17:46:44 +0800 Subject: bugfix: hosts info is wrongly processed changes: 1. add usage example in hosts.yaml.sample 2. fix /etc/hosts from wrong format {'hostname': 'ip'} to the right 'ip hostnames' 3. fix --add-hosts from wrong usage --add-host {'hostname': 'ip'} to the right --add-host='hostnames':ip 4. support per ip mapping mutiple hostnames, which is also in line with /etc/hosts schema JIRA: DOVETAIL-556 Change-Id: I92e8cb0fd3476b61f5c73a69e34c4a66aef51d6e Signed-off-by: SerenaFeng --- dovetail/utils/dovetail_utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'dovetail/utils') diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 99d44484..87efa507 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -19,6 +19,7 @@ import urllib2 from datetime import datetime from distutils.version import LooseVersion import yaml +import python_hosts from dovetail_config import DovetailConfig as dt_cfg @@ -214,10 +215,13 @@ def check_docker_version(logger=None): "Docker client should be updated to at least 1.12.3.") -def add_hosts_info(hosts_info): - hosts_file = '/etc/hosts' - with open(hosts_file, 'a') as f: - f.write("{}\n".format(hosts_info)) +def add_hosts_info(ip, hostnames): + hosts = python_hosts.Hosts(path='/etc/hosts') + new_entry = python_hosts.HostsEntry(entry_type='ipv4', + address=ip, + names=hostnames) + hosts.add([new_entry]) + hosts.write() def get_hardware_info(logger=None): -- cgit 1.2.3-korg