Extract preserve ephemeral on rebuild from servers plugin

The preserve ephemeral on rebuild functionality was merged into the servers plugin
code. This should never have happened and the hook for handling extra parameters
for the rebuild api used instead (otherwise we end up with monster functions).

This patch splits the relevant bits out to their own plugin.

Partially implements bp v2-on-v3-api

Change-Id: I0f35f897b9470039d509a97e6513c6cc806169b4
This commit is contained in:
Chris Yeoh 2015-02-05 16:21:04 +10:30
parent 512b3c6486
commit 9631e4836a
17 changed files with 208 additions and 51 deletions

View File

@ -600,6 +600,14 @@
"namespace": "http://docs.openstack.org/compute/ext/fake_xml",
"updated": "2014-12-03T00:00:00Z"
},
{
"alias": "os-preserve-ephemeral-rebuild",
"description": "Allow preservation of the ephemeral partition on rebuild.",
"links": [],
"name": "PreserveEphemeralOnRebuild",
"namespace": "http://docs.openstack.org/compute/ext/fake_xml",
"updated": "2014-12-03T00:00:00Z"
},
{
"alias": "os-quota-class-sets",
"description": "Quota classes management support.",

View File

@ -0,0 +1,11 @@
{
"rebuild": {
"imageRef": "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
"name": "foobar",
"adminPass": "seekr3t",
"metadata": {
"meta_var": "meta_val"
},
"preserve_ephemeral": false
}
}

View File

@ -0,0 +1,10 @@
{
"server" : {
"name" : "new-server-test",
"imageRef" : "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "http://openstack.example.com/flavors/1",
"metadata" : {
"My Server Name" : "Apache1"
}
}
}

View File

@ -0,0 +1,16 @@
{
"server": {
"adminPass": "xZXF6h4KfadW",
"id": "638e486b-44b1-4eb4-aace-8c7cb738ef61",
"links": [
{
"href": "http://openstack.example.com/v3/servers/638e486b-44b1-4eb4-aace-8c7cb738ef61",
"rel": "self"
},
{
"href": "http://openstack.example.com/servers/638e486b-44b1-4eb4-aace-8c7cb738ef61",
"rel": "bookmark"
}
]
}
}

View File

@ -238,6 +238,7 @@
"compute_extension:v3:os-pci:detail": "rule:admin_api",
"compute_extension:v3:os-pci:show": "rule:admin_api",
"compute_extension:v3:os-personality:discoverable": "",
"compute_extension:v3:os-preserve-ephemeral-rebuild:discoverable": "",
"compute_extension:quotas:show": "",
"compute_extension:quotas:update": "rule:admin_api",
"compute_extension:quotas:delete": "rule:admin_api",

View File

@ -0,0 +1,44 @@
# Copyright 2015 IBM Corp.
#
# 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 oslo.utils import strutils
from nova.api.openstack.compute.schemas.v3 import preserve_ephemeral_rebuild
from nova.api.openstack import extensions
ALIAS = "os-preserve-ephemeral-rebuild"
class PreserveEphemeralRebuild(extensions.V3APIExtensionBase):
"""Allow preservation of the ephemeral partition on rebuild."""
name = "PreserveEphemeralOnRebuild"
alias = ALIAS
version = 1
def get_controller_extensions(self):
return []
def get_resources(self):
return []
def server_rebuild(self, rebuild_dict, rebuild_kwargs,
body_deprecated_param=None):
if 'preserve_ephemeral' in rebuild_dict:
rebuild_kwargs['preserve_ephemeral'] = strutils.bool_from_string(
rebuild_dict['preserve_ephemeral'], strict=True)
def get_server_rebuild_schema(self):
return preserve_ephemeral_rebuild.server_rebuild

View File

@ -917,10 +917,6 @@ class ServersController(wsgi.Controller):
rebuild_kwargs = {}
if 'preserve_ephemeral' in rebuild_dict:
rebuild_kwargs['preserve_ephemeral'] = strutils.bool_from_string(
rebuild_dict['preserve_ephemeral'], strict=True)
if list(self.rebuild_extension_manager):
self.rebuild_extension_manager.map(self._rebuild_extension_point,
rebuild_dict, rebuild_kwargs)

View File

@ -0,0 +1,21 @@
# Copyright 2015 IBM Corp.
#
# 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.validation import parameter_types
server_rebuild = {
'preserve_ephemeral': parameter_types.boolean,
}

View File

@ -600,6 +600,14 @@
"namespace": "http://docs.openstack.org/compute/ext/fake_xml",
"updated": "2014-12-03T00:00:00Z"
},
{
"alias": "os-preserve-ephemeral-rebuild",
"description": "Allow preservation of the ephemeral partition on rebuild.",
"links": [],
"name": "PreserveEphemeralOnRebuild",
"namespace": "http://docs.openstack.org/compute/ext/fake_xml",
"updated": "2014-12-03T00:00:00Z"
},
{
"alias": "os-quota-class-sets",
"description": "Quota classes management support.",

View File

@ -0,0 +1,11 @@
{
"rebuild": {
"imageRef": "%(glance_host)s/images/%(uuid)s",
"name": "%(name)s",
"adminPass": "%(pass)s",
"metadata": {
"meta_var": "meta_val"
},
"preserve_ephemeral": %(preserve_ephemeral)s
}
}

View File

@ -0,0 +1,10 @@
{
"server" : {
"name" : "new-server-test",
"imageRef" : "%(glance_host)s/images/%(image_id)s",
"flavorRef" : "%(host)s/flavors/1",
"metadata" : {
"My Server Name" : "Apache1"
}
}
}

View File

@ -0,0 +1,16 @@
{
"server": {
"adminPass": "%(password)s",
"id": "%(id)s",
"links": [
{
"href": "http://openstack.example.com/v3/servers/%(uuid)s",
"rel": "self"
},
{
"href": "http://openstack.example.com/servers/%(uuid)s",
"rel": "bookmark"
}
]
}
}

View File

@ -1,17 +0,0 @@
{
"rebuild" : {
"imageRef" : "%(glance_host)s/images/%(uuid)s",
"name" : "%(name)s",
"adminPass" : "%(pass)s",
"metadata" : {
"meta_var" : "meta_val"
},
"personality" : [
{
"path" : "/etc/banner.txt",
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
}
],
"preserve_ephemeral": %(preserve_ephemeral)s
}
}

View File

@ -0,0 +1,50 @@
# Copyright 2013 IBM Corp.
#
# 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.compute import api as compute_api
from nova.tests.functional.v3 import test_servers
from nova.tests.unit.image import fake
class PreserveEphemeralOnRebuildJsonTest(test_servers.ServersSampleBase):
extension_name = 'os-preserve-ephemeral-rebuild'
def _test_server_rebuild_preserve_ephemeral(self, value):
uuid = self._post_server()
image = fake.get_valid_image_id()
subs = {'host': self._get_host(),
'uuid': image,
'name': 'foobar',
'pass': 'seekr3t',
'hostid': '[a-f0-9]+',
'preserve_ephemeral': str(value).lower(),
'action': 'rebuild',
'glance_host': self._get_glance_host(),
}
def fake_rebuild(self_, context, instance, image_href, admin_password,
files_to_inject=None, **kwargs):
self.assertEqual(kwargs['preserve_ephemeral'], value)
self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild)
response = self._do_post('servers/%s/action' % uuid,
'server-action-rebuild-preserve-ephemeral',
subs)
self.assertEqual(response.status_code, 202)
def test_server_rebuild_preserve_ephemeral_true(self):
self._test_server_rebuild_preserve_ephemeral(True)
def test_server_rebuild_preserve_ephemeral_false(self):
self._test_server_rebuild_preserve_ephemeral(False)

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.compute import api as compute_api
from nova.tests.functional.v3 import api_sample_base
from nova.tests.unit.image import fake
@ -123,35 +122,6 @@ class ServersActionsJsonTest(ServersSampleBase):
subs,
'server-action-rebuild-resp')
def _test_server_rebuild_preserve_ephemeral(self, value):
uuid = self._post_server()
image = fake.get_valid_image_id()
subs = {'host': self._get_host(),
'uuid': image,
'name': 'foobar',
'pass': 'seekr3t',
'hostid': '[a-f0-9]+',
'preserve_ephemeral': str(value).lower(),
'action': 'rebuild',
'glance_host': self._get_glance_host(),
}
def fake_rebuild(self_, context, instance, image_href, admin_password,
files_to_inject=None, **kwargs):
self.assertEqual(kwargs['preserve_ephemeral'], value)
self.stubs.Set(compute_api.API, 'rebuild', fake_rebuild)
response = self._do_post('servers/%s/action' % uuid,
'server-action-rebuild-preserve-ephemeral',
subs)
self.assertEqual(response.status_code, 202)
def test_server_rebuild_preserve_ephemeral_true(self):
self._test_server_rebuild_preserve_ephemeral(True)
def test_server_rebuild_preserve_ephemeral_false(self):
self._test_server_rebuild_preserve_ephemeral(False)
def test_server_resize(self):
self.flags(allow_resize_to_same_host=True)
uuid = self._post_server()

View File

@ -113,6 +113,7 @@ nova.api.v3.extensions =
pause_server = nova.api.openstack.compute.plugins.v3.pause_server:PauseServer
pci = nova.api.openstack.compute.plugins.v3.pci:Pci
personality = nova.api.openstack.compute.plugins.v3.personality:Personality
preserve_ephemeral_rebuild = nova.api.openstack.compute.plugins.v3.preserve_ephemeral_rebuild:PreserveEphemeralRebuild
quota_classes = nova.api.openstack.compute.plugins.v3.quota_classes:QuotaClasses
quota_sets = nova.api.openstack.compute.plugins.v3.quota_sets:QuotaSets
remote_consoles = nova.api.openstack.compute.plugins.v3.remote_consoles:RemoteConsoles
@ -156,6 +157,7 @@ nova.api.v3.extensions.server.rebuild =
access_ips = nova.api.openstack.compute.plugins.v3.access_ips:AccessIPs
disk_config = nova.api.openstack.compute.plugins.v3.disk_config:DiskConfig
personality = nova.api.openstack.compute.plugins.v3.personality:Personality
preserve_ephemeral_rebuild = nova.api.openstack.compute.plugins.v3.preserve_ephemeral_rebuild:PreserveEphemeralRebuild
nova.api.v3.extensions.server.update =
access_ips = nova.api.openstack.compute.plugins.v3.access_ips:AccessIPs