Modify a few bugs for supporting ftp/ftps

Change-Id: Ia0cd1a3561097f543cab932bf34cd8161754a0d4
This commit is contained in:
gengchc2 2018-12-04 18:13:37 -08:00
parent cac61b7132
commit d59b138182
3 changed files with 30 additions and 5 deletions

View File

@ -90,7 +90,6 @@ class NovaEngine(engine.BackupEngine):
with open(file.name) as f:
data = f.readline()
LOG.info("get_nova_tenant download {0}".format(data))
file.close()
return json.loads(data)
@ -208,7 +207,6 @@ class NovaEngine(engine.BackupEngine):
f.write(data)
LOG.info("backup_nova_tenant data={0}".format(data))
self.storage.put_file(file.name, backup_basepath)
file.close()
executor = futures.ThreadPoolExecutor(
max_workers=len(instance_ids))

View File

@ -19,6 +19,8 @@ Freezer restore modes related functions
import json
import os
import shutil
import tempfile
import time
from oslo_config import cfg
@ -62,7 +64,7 @@ class RestoreOs(object):
elif self.storage.type == "local":
path = "{0}/{1}".format(self.container, path)
backups = os.listdir(os.path.abspath(path))
elif self.storage.type in ["ssh", 'ftp', 'ftps']:
elif self.storage.type in ['ssh', 'ftp', 'ftps']:
path = "{0}/{1}".format(self.container, path)
backups = self.storage.listdir(path)
else:
@ -161,7 +163,7 @@ class RestoreOs(object):
disk_format="raw",
data=data)
return info, image
elif self.storage.type in ['ssh', 'ftp', 'ftps']:
elif self.storage.type == 'ssh':
image_file = "{0}/{1}/{2}/{3}".format(self.container, path,
backup, path)
metadata_file = "{0}/{1}/{2}/metadata".format(self.container,
@ -179,6 +181,32 @@ class RestoreOs(object):
disk_format="raw",
data=data)
return info, image
elif self.storage.type in ['ftp', 'ftps']:
image_file = "{0}/{1}/{2}/{3}".format(self.container, path,
backup, path)
metadata_file = "{0}/{1}/{2}/metadata".format(self.container,
path, backup)
try:
tmpdir = tempfile.mkdtemp()
except Exception:
LOG.error("Unable to create a tmp directory")
raise
try:
data_image = utils.path_join(tmpdir, "data_image")
LOG.info('create image restore ftp storage')
self.storage.get_file(image_file, data_image)
data_meta = utils.path_join(tmpdir, "data_meta")
self.storage.get_file(metadata_file, data_meta)
data = open(data_image, 'rb')
info = json.load(open(data_meta, 'r'))
image = self.client_manager.create_image(
name="restore_{}".format(path),
container_format="bare",
disk_format="raw",
data=data)
return info, image
finally:
shutil.rmtree(tmpdir)
else:
return {}

View File

@ -74,7 +74,6 @@ class BaseFtpStorage(fslike.FsLikeStorage):
def _create_tempdir(self):
try:
tmpdir = tempfile.mkdtemp()
LOG.info("****mkdir****")
except Exception:
LOG.error("Unable to create a tmp directory")
raise