diff options
| author | Brian Waldon <bcwaldon@gmail.com> | 2012-01-20 15:12:01 -0800 |
|---|---|---|
| committer | Brian Waldon <bcwaldon@gmail.com> | 2012-01-20 19:47:46 -0800 |
| commit | c7646aa88d564694b99a569c3cdd2c7ffbbb745d (patch) | |
| tree | 2fab0252183edb69fd9e99afa79dce2f41a050d2 /nova/api | |
| parent | 16ea348a1623f055809d0d9b7fe9f046515b5dd1 (diff) | |
| download | nova-c7646aa88d564694b99a569c3cdd2c7ffbbb745d.tar.gz nova-c7646aa88d564694b99a569c3cdd2c7ffbbb745d.tar.xz nova-c7646aa88d564694b99a569c3cdd2c7ffbbb745d.zip | |
Add SchedulerHints compute extension
This allows arbitrary key/values to be passed in on a compute create
request or rebuild/resize action. That data will be made available to the
compute api as a filter_properties dictionary.
Change-Id: Ie2ec57dcbc0d1d178e06606cb41027f9e46719a2
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/scheduler_hints.py | 65 | ||||
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 4 |
2 files changed, 68 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/contrib/scheduler_hints.py b/nova/api/openstack/compute/contrib/scheduler_hints.py new file mode 100644 index 000000000..ef665da27 --- /dev/null +++ b/nova/api/openstack/compute/contrib/scheduler_hints.py @@ -0,0 +1,65 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License + +import webob.exc + +from nova.api.openstack import extensions +from nova.api.openstack import wsgi +import nova.log as logging + +LOG = logging.getLogger('nova.api.openstack.compute.contrib.scheduler_hints') + + +class SchedulerHintsController(wsgi.Controller): + + @staticmethod + def _extract_scheduler_hints(body): + hints = {} + + try: + hints.update(body['os:scheduler_hints']) + + # Ignore if data is not present + except KeyError: + pass + + # Fail if non-dict provided + except ValueError: + msg = _("Malformed scheduler_hints attribute") + raise webob.exc.HTTPBadRequest(reason=msg) + + return hints + + @wsgi.extends + def create(self, req, body): + hints = self._extract_scheduler_hints(body) + body['server']['scheduler_hints'] = hints + yield + + +class Scheduler_hints(extensions.ExtensionDescriptor): + """Pass arbitrary key/value pairs to the scheduler""" + + name = "SchedulerHints" + alias = "os-scheduler-hints" + namespace = "http://docs.openstack.org/compute/ext/" \ + "scheduler-hints/api/v2" + updated = "2011-07-19T00:00:00+00:00" + + def get_controller_extensions(self): + controller = SchedulerHintsController() + ext = extensions.ControllerExtension(self, 'servers', controller) + return [ext] diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 988b403b1..ee7038c6e 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -709,6 +709,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', {}) try: inst_type = \ @@ -735,7 +736,8 @@ class Controller(wsgi.Controller): availability_zone=availability_zone, config_drive=config_drive, block_device_mapping=block_device_mapping, - auto_disk_config=auto_disk_config) + auto_disk_config=auto_disk_config, + scheduler_hints=scheduler_hints) except exception.QuotaError as error: self._handle_quota_error(error) except exception.InstanceTypeMemoryTooSmall as error: |
