def database_delete_host(request, database_id, host_id): database = Database.objects.get(id=database_id) instance = database.infra.instances.get(hostname_id=host_id) can_delete = True if not instance.read_only: messages.add_message( request, messages.ERROR, 'Host is not read only, cannot be removed.' ) can_delete = False if database.is_being_used_elsewhere(): messages.add_message( request, messages.ERROR, 'Host cannot be deleted because database is in use by another task.' ) can_delete = False if can_delete: TaskRegister.database_remove_instance(database=database, instance=instance, user=request.user) return HttpResponseRedirect( reverse('admin:logical_database_hosts', kwargs={'id': database.id}) )
def database_delete_host(request, database_id, host_id): database = Database.objects.get(id=database_id) instance = database.infra.instances.get(hostname_id=host_id) can_delete = True if not instance.read_only: messages.add_message( request, messages.ERROR, 'Host is not read only, cannot be removed.' ) can_delete = False if database.is_being_used_elsewhere(): messages.add_message( request, messages.ERROR, 'Host cannot be deleted because database is in use by another task.' ) can_delete = False if can_delete: TaskRegister.database_remove_instance(database=database, instance=instance, user=request.user) return HttpResponseRedirect( reverse('admin:logical_database_hosts', kwargs={'id': database.id}) )
def execute(self): status, message = self.check_database_status() if not status: raise exceptions.DatabaseNotAvailable(message) if not self.instance.read_only: raise exceptions.HostIsNotReadOnly( "Host is not read only, cannot be removed.") self.task_params = dict(database=self.database, user=self.request.user, instance=self.instance) if self.retry: since_step = self.manager.current_step self.task_params['since_step'] = since_step self.task_params['step_manager'] = self.manager TaskRegister.database_remove_instance(**self.task_params)