def delete(self, request, database_name, format=None): env = get_url_env(request) data = request.DATA LOG.debug("Request DATA {}".format(data)) response = check_database_status(database_name, env) if type(response) != Database: return response database = response unit_network = check_acl_service_and_get_unit_network( database, data, ignore_ip_error=True) if type(unit_network) == Response: return unit_network transaction.set_autocommit(False) try: db_bind = DatabaseBind.objects.get(database=database, bind_address=unit_network) database_bind = DatabaseBind.objects.select_for_update().filter( id=db_bind.id)[0] if database_bind.bind_status == CREATING: raise Exception("Bind for {} has not yet been created!".format( unit_network)) if database_bind.bind_status != DESTROYING: if database_bind.binds_requested > 0: database_bind.binds_requested -= 1 if database_bind.binds_requested == 0: database_bind.bind_status = DESTROYING database_bind.save() except (IndexError, ObjectDoesNotExist) as e: database_bind = None msg = "DatabaseBind does not exist: {}" LOG.info(msg.format(e)) except IpNaoExisteError as e: msg = "IpNaoExisteError: {}" LOG.info(msg.format(e)) except Exception as e: msg = "Bind for {} has not yet been created!".format(unit_network) return log_and_response( msg=msg, e=e, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR) finally: LOG.debug("Finishing transaction!") transaction.commit() transaction.set_autocommit(True) if database_bind and database_bind.binds_requested == 0: unbind_address_on_database.delay(database_bind=database_bind, user=request.user) return Response(status.HTTP_204_NO_CONTENT)
def delete(self, request, database_name, format=None): env = get_url_env(request) data = request.DATA LOG.debug("Request DATA {}".format(data)) response = check_database_status(database_name, env) if type(response) != Database: return response database = response unit_network = get_network_from_ip(data.get('unit-host'), database.environment) transaction.set_autocommit(False) try: db_bind = DatabaseBind.objects.get(database=database, bind_address=unit_network) database_bind = DatabaseBind.objects.select_for_update().filter( id=db_bind.id)[0] if database_bind.bind_status != DESTROYING: if database_bind.binds_requested > 0: database_bind.binds_requested -= 1 if database_bind.binds_requested == 0: database_bind.status = DESTROYING database_bind.save() except (IndexError, ObjectDoesNotExist) as e: msg = "DatabaseBind does not exist" return log_and_response( msg=msg, e=e, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR) finally: LOG.debug("Finishing transaction!") transaction.commit() transaction.set_autocommit(True) if database_bind.binds_requested == 0: unbind_address_on_database.delay(database_bind=database_bind, user=request.user) return Response(status.HTTP_204_NO_CONTENT)
def delete(self, request, database_name, format=None): env = get_url_env(request) data = request.DATA LOG.debug("Request DATA {}".format(data)) response = check_database_status(database_name, env) if type(response) != Database: return response database = response unit_network = get_network_from_ip( data.get('unit-host'), database.environment ) transaction.set_autocommit(False) try: db_bind = DatabaseBind.objects.get(database=database, bind_address=unit_network) database_bind = DatabaseBind.objects.select_for_update().filter( id=db_bind.id)[0] if database_bind.bind_status != DESTROYING: if database_bind.binds_requested > 0: database_bind.binds_requested -= 1 if database_bind.binds_requested == 0: database_bind.status = DESTROYING database_bind.save() except (IndexError, ObjectDoesNotExist) as e: msg = "DatabaseBind does not exist" return log_and_response( msg=msg, e=e, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR) finally: LOG.debug("Finishing transaction!") transaction.commit() transaction.set_autocommit(True) if database_bind.binds_requested == 0: unbind_address_on_database.delay(database_bind=database_bind, user=request.user) return Response(status.HTTP_204_NO_CONTENT)
database_bind.status = DESTROYING database_bind.save() except (IndexError, ObjectDoesNotExist), e: msg = "DatabaseBind does not exist" return log_and_response( msg=msg, e=e, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR) finally: LOG.debug("Finishing transaction!") transaction.commit() transaction.set_autocommit(True) if database_bind.binds_requested == 0: unbind_address_on_database.delay(database_bind=database_bind, user=request.user) return Response(status.HTTP_204_NO_CONTENT) class ServiceAdd(APIView): renderer_classes = (JSONRenderer, JSONPRenderer) model = Database def post(self, request, format=None): data = request.DATA name = data['name'] user = data['user'] team = data['team'] env = get_url_env(request)
if database_bind.binds_requested == 0: database_bind.status = DESTROYING database_bind.save() except (IndexError, ObjectDoesNotExist), e: msg = "DatabaseBind does not exist" return log_and_response(msg=msg, e=e, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR) finally: LOG.debug("Finishing transaction!") transaction.commit() transaction.set_autocommit(True) if database_bind.binds_requested == 0: unbind_address_on_database.delay(database_bind=database_bind, user=request.user) return Response(status.HTTP_204_NO_CONTENT) class ServiceAdd(APIView): renderer_classes = (JSONRenderer, JSONPRenderer) model = Database def post(self, request, format=None): data = request.DATA name = data['name'] user = data['user'] team = data['team'] env = get_url_env(request)