def purge_unused_exports(task=None): from dbaas_nfsaas.models import HostAttr success = True for export in HostAttr.objects.filter(is_active=False): if export.snapshots(): continue if task: task.add_detail('Removing: {}'.format(export), level=2) environment = export.host.instances.first().databaseinfra.environment try: delete_export(environment, export.nfsaas_path_host) except Exception as e: success = False LOG.info('Error removing {} - {}'.format(export, e)) if task: task.add_detail('Error: {}'.format(e), level=4) else: if task: task.add_detail('Success', level=4) export.delete() return success
def purge_unused_exports(): from dbaas_nfsaas.models import HostAttr databaseinfras = DatabaseInfra.objects.filter( plan__provider=Plan.CLOUDSTACK).prefetch_related('instances') for databaseinfra in databaseinfras: instances = databaseinfra.get_driver().get_database_instances() environment = databaseinfra.environment for instance in instances: exports = HostAttr.objects.filter( host=instance.hostname, is_active=False ) for export in exports: snapshots = Snapshot.objects.filter( export_path=export.nfsaas_path, purge_at=None ) if snapshots: continue LOG.info( 'Export {} will be removed'.format(export.nfsaas_export_id) ) delete_export(environment, export.nfsaas_path_host) export.delete()
def undo(self, workflow_dict): LOG.info("Running undo...") try: databaseinfra = workflow_dict['databaseinfra'] for host_and_export in workflow_dict['hosts_and_exports']: disk = HostAttr.objects.get( nfsaas_path=host_and_export['new_export_path']) delete_export(environment=databaseinfra.environment, export_path=disk.nfsaas_path_host) disk.delete() return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0021) workflow_dict['exceptions']['traceback'].append(traceback) return False