def run(self, context): swift = self.get_object_client(context) swift_service = self.get_object_service(context) tmp_dir = tempfile.mkdtemp() tarball_name = '%s.tar.gz' % self.plan try: swiftutils.download_container(swift, self.plan, tmp_dir) swiftutils.create_and_upload_tarball( swift_service, tmp_dir, self.exports_container, tarball_name, delete_after=self.delete_after) except swiftexceptions.ClientException as err: msg = "Error attempting an operation on container: %s" % err return actions.Result(error=msg) except (OSError, IOError) as err: msg = "Error while writing file: %s" % err return actions.Result(error=msg) except processutils.ProcessExecutionError as err: msg = "Error while creating a tarball: %s" % err return actions.Result(error=msg) except Exception as err: msg = "Error exporting plan: %s" % err return actions.Result(error=msg) finally: shutil.rmtree(tmp_dir)
def run(self, context): swift = self.get_object_client(context) swift_service = self.get_object_service(context) tarball_name = 'temporary_dir-%s.tar.gz' \ % timeutils.timestamp() # regex from tempfile's _RandomNameSequence characters _regex = '^/tmp/file-mistral-action[A-Za-z0-9_]{6}$' if (not isinstance(self.path, six.string_types) or not re.match(_regex, self.path)): msg = "Path does not match %s" % _regex return actions.Result(error={"msg": msg}) try: headers, objects = swift.get_container(self.container) for o in objects: swift.delete_object(self.container, o['name']) swiftutils.create_and_upload_tarball( swift_service, self.path, self.container, tarball_name, delete_after=sys.maxsize) except swiftexceptions.ClientException as err: msg = "Error attempting an operation on container: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) except (OSError, IOError) as err: msg = "Error while writing file: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) except processutils.ProcessExecutionError as err: msg = "Error while creating a tarball: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) except Exception as err: msg = "Error exporting logs: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) msg = "Saved tarball of directory: %s in Swift container: %s" % ( self.path, self.container) return actions.Result(data={"msg": msg})
def run(self, context): swift = self.get_object_client(context) swift_service = self.get_object_service(context) tarball_name = 'temporary_dir-%s.tar.gz' \ % timeutils.timestamp() # regex from tempfile's _RandomNameSequence characters _regex = '^/tmp/file-mistral-action[A-Za-z0-9_]{6}$' if (not isinstance(self.path, six.string_types) or not re.match(_regex, self.path)): msg = "Path does not match %s" % _regex return actions.Result(error={"msg": msg}) try: headers, objects = swift.get_container(self.container) for o in objects: swift.delete_object(self.container, o['name']) swiftutils.create_and_upload_tarball(swift_service, self.path, self.container, tarball_name, delete_after=sys.maxsize) except swiftexceptions.ClientException as err: msg = "Error attempting an operation on container: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) except (OSError, IOError) as err: msg = "Error while writing file: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) except processutils.ProcessExecutionError as err: msg = "Error while creating a tarball: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) except Exception as err: msg = "Error exporting logs: %s" % err return actions.Result(error={"msg": six.text_type(msg)}) msg = "Saved tarball of directory: %s in Swift container: %s" % ( self.path, self.container) return actions.Result(data={"msg": msg})
def run(self, context): try: LOG.info('Uploading backup to swift') swift_service = self.get_object_service(context) # Create tarball without gzip and store it 24h swiftutils.create_and_upload_tarball( swift_service, self.backup_path, self.container, self.tarball_name, '-cf', self.expire) msg = 'Backup uploaded to undercloud-backups succesfully' return actions.Result(data={'msg': msg}) except Exception as msg: return actions.Result(error={'msg': six.text_type(msg)})