fix the bug caused by hostname.

Change-Id: Id43088aa49ebe76107e8e9a62318b908ea3b384a
This commit is contained in:
Xicheng Chang 2016-08-31 12:58:05 -04:00
parent 71a193dd5b
commit 682ca408d1
8 changed files with 17 additions and 12 deletions

View File

@ -3164,19 +3164,19 @@ def update_host_state(host_id):
@util.deprecated
@app.route("/hosts/<hostname>/state_internal", methods=['PUT', 'POST'])
def update_host_state_internal(hostname):
@app.route("/hosts/<host_id>/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(

View File

@ -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:

View File

@ -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)

View File

@ -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())"
}
}

View File

@ -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())"
}
}

View File

@ -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())"
}
}

View File

@ -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())"
}
}

View File

@ -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