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
This commit is contained in:
parent
8b51c7dcaa
commit
38561c758d
|
@ -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"
|
|
@ -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'.
|
||||
|
|
|
@ -176,6 +176,7 @@ class ExtensionControllerTest(ExtensionTestCase):
|
|||
"Hosts",
|
||||
"Keypairs",
|
||||
"Multinic",
|
||||
"MultipleCreate",
|
||||
"Networks",
|
||||
"QuotaClasses",
|
||||
"Quotas",
|
||||
|
|
|
@ -1623,6 +1623,7 @@ class ServersControllerCreateTest(test.TestCase):
|
|||
"""Test creating multiple instances but not asking for
|
||||
reservation_id
|
||||
"""
|
||||
self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
|
||||
image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
|
||||
flavor_ref = 'http://localhost/123/flavors/3'
|
||||
body = {
|
||||
|
@ -1650,6 +1651,7 @@ class ServersControllerCreateTest(test.TestCase):
|
|||
"""Test creating multiple instances but not asking for
|
||||
reservation_id
|
||||
"""
|
||||
self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
|
||||
self.flags(enable_instance_password=False)
|
||||
image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
|
||||
flavor_ref = 'http://localhost/123/flavors/3'
|
||||
|
@ -1678,6 +1680,7 @@ class ServersControllerCreateTest(test.TestCase):
|
|||
"""Test creating multiple instances with asking for
|
||||
reservation_id
|
||||
"""
|
||||
self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
|
||||
image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
|
||||
flavor_ref = 'http://localhost/123/flavors/3'
|
||||
body = {
|
||||
|
@ -1862,6 +1865,42 @@ class ServersControllerCreateTest(test.TestCase):
|
|||
self.stubs.Set(nova.compute.api.API, 'create', create)
|
||||
self._test_create_extra(params)
|
||||
|
||||
def test_create_instance_with_multiple_create_enabled(self):
|
||||
self.ext_mgr.extensions = {'os-multiple-create': 'fake'}
|
||||
min_count = 2
|
||||
max_count = 3
|
||||
params = {
|
||||
'min_count': min_count,
|
||||
'max_count': max_count,
|
||||
}
|
||||
old_create = nova.compute.api.API.create
|
||||
|
||||
def create(*args, **kwargs):
|
||||
self.assertEqual(kwargs['min_count'], 2)
|
||||
self.assertEqual(kwargs['max_count'], 3)
|
||||
return old_create(*args, **kwargs)
|
||||
|
||||
self.stubs.Set(nova.compute.api.API, 'create', create)
|
||||
self._test_create_extra(params)
|
||||
|
||||
def test_create_instance_with_multiple_create_disabled(self):
|
||||
ret_res_id = True
|
||||
min_count = 2
|
||||
max_count = 3
|
||||
params = {
|
||||
'min_count': min_count,
|
||||
'max_count': max_count,
|
||||
}
|
||||
old_create = nova.compute.api.API.create
|
||||
|
||||
def create(*args, **kwargs):
|
||||
self.assertEqual(kwargs['min_count'], 1)
|
||||
self.assertEqual(kwargs['max_count'], 1)
|
||||
return old_create(*args, **kwargs)
|
||||
|
||||
self.stubs.Set(nova.compute.api.API, 'create', create)
|
||||
self._test_create_extra(params)
|
||||
|
||||
def test_create_instance_with_access_ip(self):
|
||||
# proper local hrefs must start with 'http://localhost/v2/'
|
||||
image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
|
||||
|
|
Loading…
Reference in New Issue