diff options
author | Steve Leon <steve.leon@hp.com> | 2014-04-21 22:07:20 -0700 |
---|---|---|
committer | Steve Leon <kokhang@gmail.com> | 2014-06-12 16:24:17 -0700 |
commit | 1543db553e0ad992bca156e9da91c8d86beadc94 (patch) | |
tree | d7cdf002cdb052417acd8f847eda6c9105729317 /trove/backup | |
parent | 064622e005f934145b609f77f2f81cc59b031785 (diff) | |
download | trove-1543db553e0ad992bca156e9da91c8d86beadc94.tar.gz |
Add datastore version to backups
This fix adds datastore information to the backup APIs.
These API includes backup list, backup list by instance and
backup show.
Also this fix enhances backup-list to optionally receive a
datastore to filter the backups by.
The integration tests will fail until the update for the client
gets merged: https://review.openstack.org/#/c/90462/
Change-Id: Icfec975b92cd9523e639ad6a2d6787ee4d4cb39d
Implements: blueprint backup-metadata
Diffstat (limited to 'trove/backup')
-rw-r--r-- | trove/backup/models.py | 34 | ||||
-rw-r--r-- | trove/backup/service.py | 3 | ||||
-rw-r--r-- | trove/backup/views.py | 32 |
3 files changed, 52 insertions, 17 deletions
diff --git a/trove/backup/models.py b/trove/backup/models.py index 92720d55..bbb5bba9 100644 --- a/trove/backup/models.py +++ b/trove/backup/models.py @@ -20,6 +20,7 @@ from swiftclient.client import ClientException from trove.common import cfg from trove.common import exception from trove.db.models import DatabaseModelBase +from trove.datastore import models as datastore_models from trove.openstack.common import log as logging from trove.taskmanager import api from trove.common.remote import create_swift_client @@ -78,6 +79,8 @@ class Backup(object): instance_model, 'backup_create') cls.verify_swift_auth_token(context) + ds = instance_model.datastore + ds_version = instance_model.datastore_version parent = None if parent_id: # Look up the parent info or fail early if not found or if @@ -94,6 +97,7 @@ class Backup(object): state=BackupState.NEW, instance_id=instance_id, parent_id=parent_id, + datastore_version_id=ds_version.id, deleted=False) except exception.InvalidModelError as ex: LOG.exception("Unable to create Backup record:") @@ -106,6 +110,8 @@ class Backup(object): 'backup_type': db_info.backup_type, 'checksum': db_info.checksum, 'parent': parent, + 'datastore': ds.name, + 'datastore_version': ds_version.name, } api.API(context).create_backup(backup_info, instance_id) return db_info @@ -168,16 +174,23 @@ class Backup(object): return query.all(), marker @classmethod - def list(cls, context): + def list(cls, context, datastore=None): """ list all live Backups belong to given tenant :param cls: :param context: tenant_id included + :param datastore: datastore to filter by :return: """ query = DBBackup.query() - query = query.filter_by(tenant_id=context.tenant, - deleted=False) + filters = [DBBackup.tenant_id == context.tenant, + DBBackup.deleted == 0] + if datastore: + ds = datastore_models.Datastore.load(datastore) + filters.append(datastore_models.DBDatastoreVersion. + datastore_id == ds.id) + query = query.join(datastore_models.DBDatastoreVersion) + query = query.filter(*filters) return cls._paginate(context, query) @classmethod @@ -250,7 +263,8 @@ class DBBackup(DatabaseModelBase): _data_fields = ['id', 'name', 'description', 'location', 'backup_type', 'size', 'tenant_id', 'state', 'instance_id', 'checksum', 'backup_timestamp', 'deleted', 'created', - 'updated', 'deleted_at', 'parent_id'] + 'updated', 'deleted_at', 'parent_id', + 'datastore_version_id'] preserve_on_delete = True @property @@ -271,6 +285,18 @@ class DBBackup(DatabaseModelBase): else: return None + @property + def datastore(self): + if self.datastore_version_id: + return datastore_models.Datastore.load( + self.datastore_version.datastore_id) + + @property + def datastore_version(self): + if self.datastore_version_id: + return datastore_models.DatastoreVersion.load_by_uuid( + self.datastore_version_id) + def check_swift_object_exist(self, context, verify_checksum=False): try: parts = self.location.split('/') diff --git a/trove/backup/service.py b/trove/backup/service.py index 6fb52f66..08baa389 100644 --- a/trove/backup/service.py +++ b/trove/backup/service.py @@ -37,8 +37,9 @@ class BackupController(wsgi.Controller): Return all backups information for a tenant ID. """ LOG.debug("Listing Backups for tenant '%s'" % tenant_id) + datastore = req.GET.get('datastore') context = req.environ[wsgi.CONTEXT_KEY] - backups, marker = Backup.list(context) + backups, marker = Backup.list(context, datastore) view = views.BackupViews(backups) paged = pagination.SimplePaginatedDataView(req.url, 'backups', view, marker) diff --git a/trove/backup/views.py b/trove/backup/views.py index f35322e7..9e1cfd2b 100644 --- a/trove/backup/views.py +++ b/trove/backup/views.py @@ -20,19 +20,27 @@ class BackupView(object): self.backup = backup def data(self): - return {"backup": { - "id": self.backup.id, - "name": self.backup.name, - "description": self.backup.description, - "locationRef": self.backup.location, - "instance_id": self.backup.instance_id, - "created": self.backup.created, - "updated": self.backup.updated, - "size": self.backup.size, - "status": self.backup.state, - "parent_id": self.backup.parent_id, - } + result = { + "backup": { + "id": self.backup.id, + "name": self.backup.name, + "description": self.backup.description, + "locationRef": self.backup.location, + "instance_id": self.backup.instance_id, + "created": self.backup.created, + "updated": self.backup.updated, + "size": self.backup.size, + "status": self.backup.state, + "parent_id": self.backup.parent_id, + } } + if self.backup.datastore_version_id: + result['backup']['datastore'] = { + "type": self.backup.datastore.name, + "version": self.backup.datastore_version.name, + "version_id": self.backup.datastore_version.id + } + return result class BackupViews(object): |