Commit 98de5c9a authored by alexAubin's avatar alexAubin
Browse files

Merge remote-tracking branch 'origin/enh-ip-allocation-logging' into arn-tmp

parents 56606564 1f01953a
......@@ -371,6 +371,7 @@ MEMBERSHIP_FEE_REMINDER_DATES = [
- `HANDLE_BALANCE`: Allows to handle money balances for members (False default)
- `INVOICES_INCLUDE_CONFIG_COMMENTS`: Add comment related to a subscription configuration when generating invoices
- `MEMBER_CAN_EDIT_VPN_CONF`: Allow members to edit some part of their vpn configuration
- `IP_ALLOCATION_MESSAGE`: Template string that will be used to log IP allocation in the corresponding coin.subnets logging system
- `DEBUG` : Enable debug for development **do not use in production** : display
stracktraces and enable [django-debug-toolbar](https://django-debug-toolbar.readthedocs.io).
- `SITE_TITLE`: the base of site title (displayed in browser window/tab title)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
from django.db import models
from polymorphic import PolymorphicModel
from coin.offers.models import OfferSubscription
from django.db.models.signals import post_save, post_delete
from django.core.exceptions import ObjectDoesNotExist
from django.dispatch import receiver
from django.conf import settings
from coin.resources.models import IPSubnet
......@@ -94,8 +97,19 @@ def offer_subscription_event(sender, **kwargs):
ip_pool=offer_ip_pool.ip_pool)
config.save()
@receiver(post_save, sender=IPSubnet)
def subnet_event_save(sender, **kwargs):
kwargs["signal_type"] = "save"
subnet_event(sender, **kwargs)
@receiver(post_delete, sender=IPSubnet)
def subnet_event_delete(sender, **kwargs):
kwargs["signal_type"] = "delete"
subnet_event(sender, **kwargs)
subnet_log = logging.getLogger("coin.subnets")
def subnet_event(sender, **kwargs):
"""Fires when a subnet is created, modified or deleted. We tell the
configuration backend to do whatever it needs to do with it.
......@@ -129,5 +143,21 @@ def subnet_event(sender, **kwargs):
config = subnet.configuration
if hasattr(config, 'subnet_event'):
config.subnet_event()
offer = config.offersubscription.offer.name
ref = config.offersubscription.get_subscription_reference()
member = config.offersubscription.member
ip = subnet.inet
if kwargs['signal_type'] == "save":
msg = "[Allocating IP] " + settings.IP_ALLOCATION_MESSAGE
elif kwargs['signal_type'] == "delete":
msg = "[Deallocating IP] " + settings.IP_ALLOCATION_MESSAGE
else:
# Does not happens
msg = ""
subnet_log.debug(msg.format(ip=ip, member=member, offer=offer, ref=ref))
except ObjectDoesNotExist:
pass
......@@ -340,3 +340,7 @@ HANDLE_BALANCE = False
# Add subscription comments in invoice items
INVOICES_INCLUDE_CONFIG_COMMENTS = True
# String template used for the IP allocation log (c.f. coin.subnet loggers
# This will get prefixed by [Allocating IP] or [Desallocating IP]
IP_ALLOCATION_MESSAGE = "{ip} to {member.pk} ({member.username} - {member.first_name} {member.last_name}) (for offer {offer}, {ref})"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment