From 682ca408d1fada3cb54523a259fed9451cc46098 Mon Sep 17 00:00:00 2001 From: Xicheng Chang Date: Wed, 31 Aug 2016 12:58:05 -0400 Subject: [PATCH] fix the bug caused by hostname. Change-Id: Id43088aa49ebe76107e8e9a62318b908ea3b384a --- compass/api/api.py | 10 +++++----- compass/db/api/host.py | 3 ++- .../installers/os_installers/cobbler/cobbler.py | 2 +- .../cobbler/CentOS-7-Minimal-1511-x86_64/system.tmpl | 3 ++- conf/templates/cobbler/CentOS-7.0-x86_64/system.tmpl | 3 ++- conf/templates/cobbler/Ubuntu-14.04-x86_64/system.tmpl | 3 ++- .../cobbler/ubuntu-14.04.3-server-x86_64/system.tmpl | 3 ++- misc/adapter_changes/preseed_post_anamon | 2 +- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/compass/api/api.py b/compass/api/api.py index fe169f3e..7af27217 100644 --- a/compass/api/api.py +++ b/compass/api/api.py @@ -3164,19 +3164,19 @@ def update_host_state(host_id): @util.deprecated -@app.route("/hosts//state_internal", methods=['PUT', 'POST']) -def update_host_state_internal(hostname): +@app.route("/hosts//state_internal", methods=['PUT', 'POST']) +def update_host_state_internal(host_id): """update host state. Supported fields: ['ready'] """ data = _get_request_data() - hosts = host_api.list_hosts(name=hostname) + host_id = int(host_id) + hosts = host_api.list_hosts(id=host_id) if not hosts: raise exception_handler.ItemNotFound( - 'no hosts found for hostname %s' % hostname + 'no hosts found for host_id %s' % host_id ) - host_id = hosts[0]['id'] return utils.make_json_response( 200, host_api.update_host_state_internal( diff --git a/compass/db/api/host.py b/compass/db/api/host.py index f485a245..15e0bb61 100644 --- a/compass/db/api/host.py +++ b/compass/db/api/host.py @@ -28,7 +28,7 @@ from compass.db import models from compass.utils import util -SUPPORTED_FIELDS = ['name', 'os_name', 'owner', 'mac'] +SUPPORTED_FIELDS = ['name', 'os_name', 'owner', 'mac', 'id'] SUPPORTED_MACHINE_HOST_FIELDS = [ 'mac', 'tag', 'location', 'os_name', 'os_id' ] @@ -884,6 +884,7 @@ def update_host_state_internal( """ # TODO(xicheng): should be merged into update_host_state host = _get_host(host_id, session=session) + logging.info("======host state: %s", host.state) if 'ready' in kwargs and kwargs['ready'] and not host.state.ready: ready_triggered = True else: diff --git a/compass/deployment/installers/os_installers/cobbler/cobbler.py b/compass/deployment/installers/os_installers/cobbler/cobbler.py index 302c9be2..9c2a9359 100644 --- a/compass/deployment/installers/os_installers/cobbler/cobbler.py +++ b/compass/deployment/installers/os_installers/cobbler/cobbler.py @@ -232,7 +232,7 @@ class CobblerInstaller(OSInstaller): err_msg = "Template '%s' does not exists!" % tmpl_path logging.error(err_msg) raise Exception(err_msg) - + host_vars_dict[const.BASEINFO]['host_id'] = host_id system_config = self.get_config_from_template(tmpl_path, host_vars_dict) diff --git a/conf/templates/cobbler/CentOS-7-Minimal-1511-x86_64/system.tmpl b/conf/templates/cobbler/CentOS-7-Minimal-1511-x86_64/system.tmpl index 8e4cbbbe..e2032988 100644 --- a/conf/templates/cobbler/CentOS-7-Minimal-1511-x86_64/system.tmpl +++ b/conf/templates/cobbler/CentOS-7-Minimal-1511-x86_64/system.tmpl @@ -71,6 +71,7 @@ "timezone": "$timezone", "ignore_proxy": "$no_proxy", "local_repo": "$getVar('local_repo', '')", - "disk_num": "1" + "disk_num": "1", + "host_id": "$getVar('host_id', int())" } } diff --git a/conf/templates/cobbler/CentOS-7.0-x86_64/system.tmpl b/conf/templates/cobbler/CentOS-7.0-x86_64/system.tmpl index 8e4cbbbe..e2032988 100644 --- a/conf/templates/cobbler/CentOS-7.0-x86_64/system.tmpl +++ b/conf/templates/cobbler/CentOS-7.0-x86_64/system.tmpl @@ -71,6 +71,7 @@ "timezone": "$timezone", "ignore_proxy": "$no_proxy", "local_repo": "$getVar('local_repo', '')", - "disk_num": "1" + "disk_num": "1", + "host_id": "$getVar('host_id', int())" } } diff --git a/conf/templates/cobbler/Ubuntu-14.04-x86_64/system.tmpl b/conf/templates/cobbler/Ubuntu-14.04-x86_64/system.tmpl index cfcc883e..3e46a110 100644 --- a/conf/templates/cobbler/Ubuntu-14.04-x86_64/system.tmpl +++ b/conf/templates/cobbler/Ubuntu-14.04-x86_64/system.tmpl @@ -70,6 +70,7 @@ "timezone": "$timezone", "ignore_proxy": "$no_proxy", "local_repo": "$getVar('local_repo', '')", - "disk_num": "1" + "disk_num": "1", + "host_id": "$getVar('host_id', int())" } } diff --git a/conf/templates/cobbler/ubuntu-14.04.3-server-x86_64/system.tmpl b/conf/templates/cobbler/ubuntu-14.04.3-server-x86_64/system.tmpl index cfcc883e..3e46a110 100644 --- a/conf/templates/cobbler/ubuntu-14.04.3-server-x86_64/system.tmpl +++ b/conf/templates/cobbler/ubuntu-14.04.3-server-x86_64/system.tmpl @@ -70,6 +70,7 @@ "timezone": "$timezone", "ignore_proxy": "$no_proxy", "local_repo": "$getVar('local_repo', '')", - "disk_num": "1" + "disk_num": "1", + "host_id": "$getVar('host_id', int())" } } diff --git a/misc/adapter_changes/preseed_post_anamon b/misc/adapter_changes/preseed_post_anamon index 216e70dc..aae183a9 100644 --- a/misc/adapter_changes/preseed_post_anamon +++ b/misc/adapter_changes/preseed_post_anamon @@ -66,7 +66,7 @@ cat << EOF > /etc/init.d/set_state # Description: set_state runs the first time a machine is booted after # installation. #end raw -wget -O /tmp/os_state --post-data='{"ready": true}' --header=Content-Type:application/json "http://c.stack360.io/api/hosts/${hostname}/state_internal" +wget -O /tmp/os_state --post-data='{"ready": true}' --header=Content-Type:application/json "http://c.stack360.io/api/hosts/${host_id}/state_internal" update-rc.d -f set_state remove mv /etc/init.d/set_state /tmp/set_state EOF