From 8b51c7dcaaf03f0b2b287420dad5c61e05cf31b6 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 9 Aug 2012 11:24:54 -0700 Subject: Key availability_zone in create server off of ext. Implements part of blueprint disable-server-extensions Adds a new extension descriptor for availability_zone and makes sure that availability_zone is only accepted in the create server request if the extension is enabled. Change-Id: I326b26c4741ffa6a8b594be26d0cd22d032a6162 --- .../openstack/compute/contrib/availability_zone.py | 27 ++++++++++++++++++++++ nova/api/openstack/compute/servers.py | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 nova/api/openstack/compute/contrib/availability_zone.py (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/availability_zone.py b/nova/api/openstack/compute/contrib/availability_zone.py new file mode 100644 index 000000000..524f454ea --- /dev/null +++ b/nova/api/openstack/compute/contrib/availability_zone.py @@ -0,0 +1,27 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 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 + +from nova.api.openstack import extensions + + +class Availability_zone(extensions.ExtensionDescriptor): + """Add availability_zone to the Create Server v1.1 API""" + + name = "AvailabilityZone" + alias = "os-availability-zone" + namespace = ("http://docs.openstack.org/compute/ext/" + "availabilityzone/api/v1.1") + updated = "2012-08-09T00:00:00+00:00" diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index b378d4139..de8f32d53 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -647,7 +647,9 @@ class Controller(wsgi.Controller): user_data = server_dict.get('user_data') self._validate_user_data(user_data) - availability_zone = server_dict.get('availability_zone') + availability_zone = None + if self.ext_mgr.is_loaded('os-availability-zone'): + availability_zone = server_dict.get('availability_zone') block_device_mapping = None if self.ext_mgr.is_loaded('os-volumes'): -- cgit From 38561c758dd0699fa31d17222bd06c06f4a28168 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 9 Aug 2012 11:51:05 -0700 Subject: Key min_count, max_count, ret_res_id off of ext. Implements part of blueprint disable-server-extensions Adds a new extension descriptor callsed os-multiple-create. Modifies the min_count, max_count, and return_reservation_id parameters to server create to only be allowed if the extension is enabled. Change-Id: Iaca009588d6c824e0852a060787d2a4cb9614278 --- .../openstack/compute/contrib/multiple_create.py | 27 ++++++++++++++++++++++ nova/api/openstack/compute/servers.py | 11 +++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 nova/api/openstack/compute/contrib/multiple_create.py (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/multiple_create.py b/nova/api/openstack/compute/contrib/multiple_create.py new file mode 100644 index 000000000..9b3ca8a57 --- /dev/null +++ b/nova/api/openstack/compute/contrib/multiple_create.py @@ -0,0 +1,27 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 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 + +from nova.api.openstack import extensions + + +class Multiple_create(extensions.ExtensionDescriptor): + """Allow multiple create in the Create Server v1.1 API""" + + name = "MultipleCreate" + alias = "os-multiple-create" + namespace = ("http://docs.openstack.org/compute/ext/" + "multiplecreate/api/v1.1") + updated = "2012-08-07T00:00:00+00:00" diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index de8f32d53..25a7e55e8 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -655,10 +655,13 @@ class Controller(wsgi.Controller): if self.ext_mgr.is_loaded('os-volumes'): block_device_mapping = server_dict.get('block_device_mapping') - ret_resv_id = server_dict.get('return_reservation_id', False) - - min_count = server_dict.get('min_count') - max_count = server_dict.get('max_count') + ret_resv_id = False + min_count = None + max_count = None + if self.ext_mgr.is_loaded('os-multiple-create'): + ret_resv_id = server_dict.get('return_reservation_id', False) + min_count = server_dict.get('min_count') + max_count = server_dict.get('max_count') # min_count and max_count are optional. If they exist, they come # in as strings. We want to default 'min_count' to 1, and default # 'max_count' to be 'min_count'. -- cgit From 13d25ed7dc0005f89a0522eff3bf5e5cda30fb07 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 10 Aug 2012 15:39:55 -0400 Subject: Don't accept key_name if not enabled partially implements blueprint disable-server-extensions moves filling out key_name variable behind conditional only used when os-keypairs is enabled. Adds unit tests to ensure this behaves as expected (Remove debugging that was left in) Change-Id: I87ce041c2093c93a1a2456ef51357593e9de0681 --- nova/api/openstack/compute/servers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 25a7e55e8..8f3e47eb8 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -641,7 +641,10 @@ class Controller(wsgi.Controller): raise exc.HTTPBadRequest(explanation=msg) # optional openstack extensions: - key_name = server_dict.get('key_name') + key_name = None + if self.ext_mgr.is_loaded('os-keypairs'): + key_name = server_dict.get('key_name') + user_data = None if self.ext_mgr.is_loaded('os-user-data'): user_data = server_dict.get('user_data') -- cgit