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)) host = export.host export_id = export.nfsaas_export_id clean_unused_data(export_id=export_id, export_path=export.nfsaas_path, host=instance.hostname, databaseinfra=databaseinfra) nfsaas_client = NfsaasProvider() nfsaas_client.revoke_access(environment=environment, host=host, export_id=export_id) nfsaas_client.drop_export(environment=environment, export_id=export_id) export.delete()
def do(self, workflow_dict): try: for host_and_export in workflow_dict['hosts_and_exports']: clean_unused_data( export_id=host_and_export['old_export_id'], export_path=host_and_export['old_export_path'], host=host_and_export['host'], databaseinfra=workflow_dict['databaseinfra']) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0021) workflow_dict['exceptions']['traceback'].append(traceback) return True
def do(self, workflow_dict): try: for host_and_export in workflow_dict["hosts_and_exports"]: clean_unused_data( export_id=host_and_export["old_export_id"], export_path=host_and_export["old_export_path"], host=host_and_export["host"], databaseinfra=workflow_dict["databaseinfra"], ) return True except Exception: traceback = full_stack() workflow_dict["exceptions"]["error_codes"].append(DBAAS_0021) workflow_dict["exceptions"]["traceback"].append(traceback) return True
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)) host = export.host export_id = export.nfsaas_export_id clean_unused_data(export_id=export_id, export_path=export.nfsaas_path, host=instance.hostname, databaseinfra=databaseinfra) nfsaas_client = NfsaasProvider() nfsaas_client.revoke_access(environment=environment, host=host, export_id=export_id) nfsaas_client.drop_export(environment=environment, export_id=export_id) export.delete()
def destroy_unused_export(export_id, export_path, host, databaseinfra): clean_unused_data(export_id, export_path, host, databaseinfra) provider = NfsaasProvider() provider.drop_export(environment=databaseinfra.environment, export_id=export_id)