Comment 1 for bug 1025737

Revision history for this message
jiang, yunhong (yunhong-jiang) wrote :

As the extension code will be executed before servers.py, I didn't think out a good method to distinguish whether the "scheduler_hints" in request body is set by the schedule hints extensions or by user directly.

I considered that it's possible that the schedule hints extension set the req's environment, like followed draft show. With this changes, even user set the "scheduler_hints" in the server dictionary, it will not be utilized. The servers.py always get scheduler hints from the wsgi environment.

However, I'm not quite sure if this is the right and clean solution, because I'm not sure if the wsgi environment fits for this purpose. Although my quick test showed it works.

Brian, how do you think of this? If it's acceptable, I will do more testing on it.

Thanks
--jyh

diff --git a/nova/api/openstack/compute/contrib/scheduler_hints.py b/nova/api/op
index 86b7564..d97d0bd 100644
--- a/nova/api/openstack/compute/contrib/scheduler_hints.py
+++ b/nova/api/openstack/compute/contrib/scheduler_hints.py
@@ -46,7 +46,7 @@ class SchedulerHintsController(wsgi.Controller):
     @wsgi.extends
     def create(self, req, body):
         hints = self._extract_scheduler_hints(body)
- body['server']['scheduler_hints'] = hints
+ req.environ['nova.scheduler_hints'] = hints
         yield

diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/
index 0b37b5c..42a5036 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -678,7 +678,7 @@ class Controller(wsgi.Controller):
             min_count = max_count

         auto_disk_config = server_dict.get('auto_disk_config')
- scheduler_hints = server_dict.get('scheduler_hints', {})
+ scheduler_hints = req.environ['nova.scheduler_hints']

         try:
             _get_inst_type = instance_types.get_instance_type_by_flavor_id
~