Delete datastore

Admin user can delete datastore if there are no instances or backups
associated.

Change-Id: If15b79661859d5c40f4d9e5fe65e478954b6ddd4
This commit is contained in:
Lingxian Kong 2020-01-11 22:27:42 +13:00
parent a5f6c9b82c
commit 4551a6cd7c
5 changed files with 64 additions and 13 deletions

View File

@ -28,8 +28,6 @@ Response Example
:language: javascript :language: javascript
Show datastore details Show datastore details
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
@ -50,3 +48,19 @@ Response Example
.. literalinclude:: samples/datastore-show-response.json .. literalinclude:: samples/datastore-show-response.json
:language: javascript :language: javascript
Delete datastore
~~~~~~~~~~~~~~~~
.. rest_method:: DELETE /v1.0/{project_id}/datastores/{datastore}
Delete a datastore.
Request
-------
.. rest_parameters:: parameters.yaml
- project_id: project_id
- datastore: data_store

View File

@ -0,0 +1,4 @@
---
features:
- Admin user can delete datastore if there are no instances or backups
associated.

View File

@ -66,6 +66,12 @@ class NotFound(TroveError):
message = _("Resource %(uuid)s cannot be found.") message = _("Resource %(uuid)s cannot be found.")
class BadRequest(TroveError):
message = _("The server could not comply with the request since it is "
"either malformed or otherwise incorrect.")
class CapabilityNotFound(NotFound): class CapabilityNotFound(NotFound):
message = _("Capability '%(capability)s' cannot be found.") message = _("Capability '%(capability)s' cannot be found.")
@ -172,6 +178,16 @@ class DatastoreVersionInactive(TroveError):
message = _("Datastore version '%(version)s' is not active.") message = _("Datastore version '%(version)s' is not active.")
class DatastoreVersionAlreadyExists(BadRequest):
message = _("A datastore version with the name '%(name)s' already exists.")
class DatastoreVersionsExist(BadRequest):
message = _("Datastore versions exist for datastore %(datastore)s.")
class DatastoreDefaultDatastoreNotFound(TroveError): class DatastoreDefaultDatastoreNotFound(TroveError):
message = _("Please specify datastore. Default datastore " message = _("Please specify datastore. Default datastore "
@ -240,12 +256,6 @@ class GuestTimeout(TroveError):
message = _("Timeout trying to connect to the Guest Agent.") message = _("Timeout trying to connect to the Guest Agent.")
class BadRequest(TroveError):
message = _("The server could not comply with the request since it is "
"either malformed or otherwise incorrect.")
class MissingKey(BadRequest): class MissingKey(BadRequest):
message = _("Required element/key - %(key)s was not specified.") message = _("Required element/key - %(key)s was not specified.")
@ -661,11 +671,6 @@ class ImageNotFound(NotFound):
message = _("Image %(uuid)s cannot be found.") message = _("Image %(uuid)s cannot be found.")
class DatastoreVersionAlreadyExists(BadRequest):
message = _("A datastore version with the name '%(name)s' already exists.")
class LogAccessForbidden(Forbidden): class LogAccessForbidden(Forbidden):
message = _("You must be admin to %(action)s log '%(log)s'.") message = _("You must be admin to %(action)s log '%(log)s'.")

View File

@ -37,6 +37,16 @@ rules = [
'method': 'GET' 'method': 'GET'
} }
]), ]),
policy.DocumentedRuleDefault(
name='datastore:delete',
check_str='rule:admin',
description='Delete a datastore.',
operations=[
{
'path': PATH_DATASTORE,
'method': 'DELETE'
}
]),
policy.DocumentedRuleDefault( policy.DocumentedRuleDefault(
name='datastore:version_show', name='datastore:version_show',
check_str='', check_str='',

View File

@ -15,13 +15,17 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from oslo_log import log as logging
from trove.common import exception
from trove.common import policy from trove.common import policy
from trove.common import wsgi from trove.common import wsgi
from trove.datastore import models, views from trove.datastore import models, views
from trove.flavor import views as flavor_views from trove.flavor import views as flavor_views
from trove.volume_type import views as volume_type_view from trove.volume_type import views as volume_type_view
LOG = logging.getLogger(__name__)
class DatastoreController(wsgi.Controller): class DatastoreController(wsgi.Controller):
@ -105,3 +109,17 @@ class DatastoreController(wsgi.Controller):
context, datastore, version_id)) context, datastore, version_id))
return wsgi.Result(volume_type_view.VolumeTypesView( return wsgi.Result(volume_type_view.VolumeTypesView(
volume_types, req).data(), 200) volume_types, req).data(), 200)
def delete(self, req, tenant_id, id):
"""Remove an existing datastore."""
self.authorize_request(req, 'delete')
ds_versions = models.DatastoreVersions.load(id, only_active=False)
if len(ds_versions.db_info.all()) > 0:
raise exception.DatastoreVersionsExist(datastore=id)
LOG.info("Deleting datastore %s", id)
datastore = models.Datastore.load(id)
datastore.delete()
return wsgi.Result(None, 202)