Update 'admin action' of nova based backups
There are two issues in current 'admin action' of nova based backups. 1. When remove old nova backups with command 'freezer-agent --action admin --mode nova --engine nova --nova-inst-id xxxx --no-incremental true --remove-older-than x" will fail cause the incorrect swift path. 2. Can not do 'admin action' of nova tenant. This patch contains two changes. 1. Fix remove old nova backups error. 2. Add option to do 'admin action' of nova tenant. Change-Id: I60b3445905fab65725882fba9b0ca6b1e2abc408 Closes-Bug: #1684526
This commit is contained in:
parent
4c83a3f7c3
commit
76cca40b29
|
@ -52,9 +52,8 @@ class NovaEngine(engine.BackupEngine):
|
|||
except EOFError:
|
||||
pass
|
||||
|
||||
def restore_nova_tenant(self, project_id, hostname_backup_name,
|
||||
overwrite, recent_to_date):
|
||||
# Load info about tenant instances in swift
|
||||
def get_nova_tenant(self, project_id):
|
||||
# Load info about tenant instances
|
||||
if self.storage._type == 'swift':
|
||||
swift_connection = self.client.create_swift()
|
||||
headers, data = swift_connection.get_object(
|
||||
|
@ -66,7 +65,12 @@ class NovaEngine(engine.BackupEngine):
|
|||
with self.storage.open(backup_basepath, 'rb') as backup_file:
|
||||
data = backup_file.readline()
|
||||
|
||||
instance_ids = json.loads(data)
|
||||
return json.loads(data)
|
||||
|
||||
def restore_nova_tenant(self, project_id, hostname_backup_name,
|
||||
overwrite, recent_to_date):
|
||||
|
||||
instance_ids = self.get_nova_tenant(project_id)
|
||||
for instance_id in instance_ids:
|
||||
LOG.info("Restore nova instance ID: {0} from container {1}".
|
||||
format(instance_id, self.storage.storage_path))
|
||||
|
|
|
@ -418,9 +418,28 @@ class AdminJob(Job):
|
|||
datetime.timedelta(days=self.conf.remove_older_than)
|
||||
timestamp = int(time.mktime(timestamp.timetuple()))
|
||||
|
||||
self.storage.remove_older_than(self.engine,
|
||||
timestamp,
|
||||
self.conf.hostname_backup_name)
|
||||
hostname_backup_name_set = set()
|
||||
|
||||
if self.conf.backup_media == 'nova':
|
||||
if self.conf.project_id:
|
||||
instance_ids = self.engine.get_nova_tenant(
|
||||
self.conf.project_id)
|
||||
for instance_id in instance_ids:
|
||||
hostname_backup_name = os.path.join(
|
||||
self.conf.hostname_backup_name, instance_id)
|
||||
hostname_backup_name_set.add(hostname_backup_name)
|
||||
else:
|
||||
hostname_backup_name = os.path.join(
|
||||
self.conf.hostname_backup_name,
|
||||
self.conf.nova_inst_id)
|
||||
hostname_backup_name_set.add(hostname_backup_name)
|
||||
else:
|
||||
hostname_backup_name_set.add(self.conf.hostname_backup_name)
|
||||
|
||||
for backup_name in hostname_backup_name_set:
|
||||
self.storage.remove_older_than(self.engine,
|
||||
timestamp,
|
||||
backup_name)
|
||||
return {}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class SwiftStorage(physical.PhysicalStorage):
|
|||
_type = 'swift'
|
||||
|
||||
def rmtree(self, path):
|
||||
split = path.rsplit('/', 1)
|
||||
split = path.split('/', 1)
|
||||
for file in self.swift().get_container(split[0],
|
||||
prefix=split[1])[1]:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue