summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2011-06-22 13:31:28 -0500
committerRick Harris <rconradharris@gmail.com>2011-06-22 13:31:28 -0500
commit75a87df739effe840e6cb39c976002e99b49c796 (patch)
treebaaea8f74c7744f45093da09463a95eb59cd50c8
parent7cb4d3150bf0883944624d46bc458cfd25fa1c9a (diff)
downloadnova-75a87df739effe840e6cb39c976002e99b49c796.tar.gz
nova-75a87df739effe840e6cb39c976002e99b49c796.tar.xz
nova-75a87df739effe840e6cb39c976002e99b49c796.zip
Round 1 of backup with rotation.
-rw-r--r--nova/compute/api.py32
-rw-r--r--nova/compute/manager.py20
2 files changed, 48 insertions, 4 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index a7ea88d51..365aa1c5d 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -701,18 +701,46 @@ class API(base.Base):
raise exception.Error(_("Unable to find host for Instance %s")
% instance_id)
+ def backup(self, context, instance_id, backup_type, rotation):
+ """Backup the given instance
+
+ instance_id - int - id representing the instance
+ backup_type - str - whether it's 'daily' or 'weekly'
+ rotation - int - number of backups to keep around
+ """
+ name = backup_type # daily backups are called 'daily'
+ recv_meta = self._snapshot(context, instance_id, name, backup_type,
+ rotation=rotation)
+ return recv_meta
+
def snapshot(self, context, instance_id, name):
"""Snapshot the given instance.
:returns: A dict containing image metadata
"""
- properties = {'instance_id': str(instance_id),
+ return self._snapshot(context, instance_id, name, 'snapshot')
+
+ def _snapshot(self, context, instance_id, name, image_type, rotation=None):
+ """Snapshot an instance on this host.
+
+ :param context: security context
+ :param instance_id: nova.db.sqlalchemy.models.Instance.Id
+ :param name: string for name of the snapshot
+ :param image_type: snapshot | daily | weekly
+ :param rotation: int representing how many backups to keep around;
+ None if rotation shouldn't be used (as in the case of snapshots)
+ """
+ instance = db.api.instance_get(context, instance_id)
+ properties = {'instance_uuid': instance['uuid'],
'user_id': str(context.user_id),
'image_state': 'creating'}
+ if image_type != 'snapshot':
+ properties['backup_type'] = image_type
sent_meta = {'name': name, 'is_public': False,
'status': 'creating', 'properties': properties}
recv_meta = self.image_service.create(context, sent_meta)
- params = {'image_id': recv_meta['id']}
+ params = {'image_id': recv_meta['id'], 'image_type': image_type,
+ 'rotation': rotation}
self._cast_compute_message('snapshot_instance', context, instance_id,
params=params)
return recv_meta
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 4e006e677..bc6981c58 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -473,8 +473,17 @@ class ComputeManager(manager.SchedulerDependentManager):
self._update_state(context, instance_id)
@exception.wrap_exception
- def snapshot_instance(self, context, instance_id, image_id):
- """Snapshot an instance on this host."""
+ def snapshot_instance(self, context, instance_id, image_id,
+ image_type='snapshot', rotation=None):
+ """Snapshot an instance on this host.
+
+ :param context: security context
+ :param instance_id: nova.db.sqlalchemy.models.Instance.Id
+ :param image_id: glance.db.sqlalchemy.models.Image.Id
+ :param image_type: snapshot | daily | weekly
+ :param rotation: int representing how many backups to keep around;
+ None if rotation shouldn't be used (as in the case of snapshots)
+ """
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
@@ -493,6 +502,13 @@ class ComputeManager(manager.SchedulerDependentManager):
'expected: %(running)s)') % locals())
self.driver.snapshot(instance_ref, image_id)
+ if rotation:
+ self.rotate_backups(context, instance_id, image_type, rotation)
+
+ def rotate_backups(self, context, instance_id, image_type, rotation):
+ """
+ """
+ pass
@exception.wrap_exception
@checks_instance_lock