Parcourir la source

Merge branch 'ip-assignement-log' of https://code.ffdn.org/ARN/coin into arnprod

ljf il y a 7 ans
Parent
commit
fdcfc86e65
2 fichiers modifiés avec 35 ajouts et 0 suppressions
  1. 31 0
      coin/configuration/models.py
  2. 4 0
      coin/settings_base.py

+ 31 - 0
coin/configuration/models.py

@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 from __future__ import unicode_literals
 
 
+import logging
+
 from django.db import models
 from django.db import models
 from polymorphic import PolymorphicModel
 from polymorphic import PolymorphicModel
 from coin.offers.models import OfferSubscription
 from coin.offers.models import OfferSubscription
@@ -94,8 +96,19 @@ def offer_subscription_event(sender, **kwargs):
                                 ip_pool=offer_ip_pool.ip_pool)
                                 ip_pool=offer_ip_pool.ip_pool)
             config.save()
             config.save()
 
 
+
 @receiver(post_save, sender=IPSubnet)
 @receiver(post_save, sender=IPSubnet)
+def subnet_event_save(sender, **kwargs):
+    kwargs["signal_type"] = "save"
+    subnet_event(sender, **kwargs)
+
+
 @receiver(post_delete, sender=IPSubnet)
 @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):
 def subnet_event(sender, **kwargs):
     """Fires when a subnet is created, modified or deleted.  We tell the
     """Fires when a subnet is created, modified or deleted.  We tell the
     configuration backend to do whatever it needs to do with it.
     configuration backend to do whatever it needs to do with it.
@@ -129,5 +142,23 @@ def subnet_event(sender, **kwargs):
         config = subnet.configuration
         config = subnet.configuration
         if hasattr(config, 'subnet_event'):
         if hasattr(config, 'subnet_event'):
             config.subnet_event()
             config.subnet_event()
+
+        offer = config.offersubscription.offer.name
+        subref = config.offersubscription.get_subscription_reference()
+        member = config.offersubscription.member
+        ip = subnet.inet
+
+        if kwargs['signal_type'] == "save":
+            msg = "Allocating IP %s to member %s (%s - %s %s) (for offer %s, %s)"
+        elif kwargs['signal_type'] == "delete":
+            msg = "Deallocating IP %s from member %s (%s - %s %s) (was offer %s, %s)"
+        else:
+            # Does not happens
+            msg = ""
+
+        subnet_log.info(msg % (ip, str(member.pk),
+                        member.username, member.first_name, member.last_name,
+                        offer, subref))
+
     except ObjectDoesNotExist:
     except ObjectDoesNotExist:
         pass
         pass

+ 4 - 0
coin/settings_base.py

@@ -206,6 +206,10 @@ LOGGING = {
         "coin.billing": {
         "coin.billing": {
             'handlers': ['console'],
             'handlers': ['console'],
             'level': 'INFO',
             'level': 'INFO',
+        },
+        "coin.subnets": {
+            'handlers': ['console'],
+            'level': 'INFO',
         }
         }
     }
     }
 }
 }