def retrieve_backup_data(self, object_name, output_filepath=None): """ Argument: object_name: delete target object name """ if (client.is_container(self.token, self.storage_url, self.container_name, verify=self.verify) and client.is_object(self.token, self.storage_url, self.container_name, object_name, verify=self.verify)): rc, content = client.retrieve_object(self.token, self.storage_url, self.container_name, object_name, verify=self.verify) if not rc: raise RuntimeError('Failed to retrieve the object "%s"' % object_name) if output_filepath: fpath = os.path.abspath(output_filepath) dpath = os.path.dirname(fpath) if not os.path.isdir(dpath): raise IOError('No such directory "%s"' % dpath) else: dpath = os.path.abspath(os.curdir) fpath = os.path.join(dpath, object_name) with open(fpath, 'w') as f: f.write(content) else: raise RuntimeError('No such object "%s"' % object_name)
def delete_backup_data(self, object_name): """ Argument: object_name: delete target object name """ if (client.is_container(self.token, self.storage_url, self.container_name, verify=self.verify) and client.is_object(self.token, self.storage_url, self.container_name, object_name, verify=self.verify)): rc = client.delete_object(self.token, self.storage_url, self.container_name, object_name, veirfy=self.verify) if not rc == 204: raise RuntimeError('Failed to delete the object "%s"' % object_name) return True else: raise RuntimeError('No such object "%s"' % object_name)