Beispiel #1
0
 def to_objectchange(self, action):
     # Annotate the parent VirtualMachine
     return ObjectChange(changed_object=self,
                         object_repr=str(self),
                         action=action,
                         related_object=self.virtual_machine,
                         object_data=serialize_object(self))
Beispiel #2
0
 def to_objectchange(self, action):
     # Annotate the assigned object, if any
     return ObjectChange(changed_object=self,
                         object_repr=str(self),
                         action=action,
                         related_object=self.assigned_object,
                         object_data=serialize_object(self))
Beispiel #3
0
    def to_objectchange(self, action, related_object=None):
        """
        Return a new ObjectChange representing a change made to this object. This will typically be called automatically
        by ChangeLoggingMiddleware.
        """
        from extras.models import ObjectChange
        objectchange = ObjectChange(changed_object=self,
                                    related_object=related_object,
                                    object_repr=str(self),
                                    action=action)
        if hasattr(self, '_prechange_snapshot'):
            objectchange.prechange_data = self._prechange_snapshot
        if action in (ObjectChangeActionChoices.ACTION_CREATE,
                      ObjectChangeActionChoices.ACTION_UPDATE):
            objectchange.postchange_data = serialize_object(self)

        return objectchange
Beispiel #4
0
 def to_objectchange(self, action):
     # Remove MPTT-internal fields
     return ObjectChange(
         changed_object=self,
         object_repr=str(self),
         action=action,
         object_data=serialize_object(self, exclude=['level', 'lft', 'rght', 'tree_id'])
     )
Beispiel #5
0
 def to_objectchange(self, action):
     """
     Return a new ObjectChange representing a change made to this object. This will typically be called automatically
     by extras.middleware.ChangeLoggingMiddleware.
     """
     return ObjectChange(changed_object=self,
                         object_repr=str(self),
                         action=action,
                         object_data=serialize_object(self))
Beispiel #6
0
 def log_change(self, user, request_id, action):
     """
     Reference the parent circuit when recording the change.
     """
     ObjectChange(user=user,
                  request_id=request_id,
                  changed_object=self,
                  related_object=self.circuit,
                  action=action,
                  object_data=serialize_object(self)).save()
Beispiel #7
0
 def log_change(self, user, request_id, action):
     """
     Create a new ObjectChange representing a change made to this object. This will typically be called automatically
     by extras.middleware.ChangeLoggingMiddleware.
     """
     ObjectChange(user=user,
                  request_id=request_id,
                  changed_object=self,
                  action=action,
                  object_data=serialize_object(self)).save()
Beispiel #8
0
    def to_objectchange(self, action):
        # Annotate the parent Device/VM
        try:
            parent_obj = self.device or self.virtual_machine
        except ObjectDoesNotExist:
            parent_obj = None

        return ObjectChange(changed_object=self,
                            object_repr=str(self),
                            action=action,
                            related_object=parent_obj,
                            object_data=serialize_object(self))
Beispiel #9
0
 def to_objectchange(self, action):
     # Annotate the parent Device
     try:
         device = self.device
     except ObjectDoesNotExist:
         # The parent Device has already been deleted
         device = None
     return ObjectChange(changed_object=self,
                         object_repr=str(self),
                         action=action,
                         related_object=device,
                         object_data=serialize_object(self))
Beispiel #10
0
    def to_objectchange(self, action):
        # Annotate the assigned Interface (if any)
        try:
            parent_obj = self.interface
        except ObjectDoesNotExist:
            parent_obj = None

        return ObjectChange(changed_object=self,
                            object_repr=str(self),
                            action=action,
                            related_object=parent_obj,
                            object_data=serialize_object(self))
Beispiel #11
0
    def to_objectchange(self, action):
        # Annotate the parent Circuit
        try:
            related_object = self.circuit
        except Circuit.DoesNotExist:
            # Parent circuit has been deleted
            related_object = None

        return ObjectChange(changed_object=self,
                            object_repr=str(self),
                            action=action,
                            related_object=related_object,
                            object_data=serialize_object(self))
Beispiel #12
0
    def to_objectchange(self, action):
        # Annotate the parent Device/VM
        try:
            parent = getattr(self, 'device', None) or getattr(
                self, 'virtual_machine', None)
        except ObjectDoesNotExist:
            # The parent device/VM has already been deleted
            parent = None

        return ObjectChange(changed_object=self,
                            object_repr=str(self),
                            action=action,
                            related_object=parent,
                            object_data=serialize_object(self))
Beispiel #13
0
 def log_change(self, user, request_id, action):
     """
     Reference the parent circuit when recording the change.
     """
     try:
         related_object = self.circuit
     except Circuit.DoesNotExist:
         # Parent circuit has been deleted
         related_object = None
     ObjectChange(user=user,
                  request_id=request_id,
                  changed_object=self,
                  related_object=related_object,
                  action=action,
                  object_data=serialize_object(self)).save()
Beispiel #14
0
    def log_change(self, user, request_id, action):
        """
        Include the connected Interface (if any).
        """

        # It's possible that an IPAddress can be deleted _after_ its parent Interface, in which case trying to resolve
        # the interface will raise DoesNotExist.
        try:
            parent_obj = self.interface
        except ObjectDoesNotExist:
            parent_obj = None

        ObjectChange(user=user,
                     request_id=request_id,
                     changed_object=self,
                     related_object=parent_obj,
                     action=action,
                     object_data=serialize_object(self)).save()
 def to_objectchange(self, action):
     return ObjectChange(changed_object=self,
                         object_repr=str(self),
                         action=action,
                         related_object=self.device_type,
                         object_data=serialize_object(self))
Beispiel #16
0
    def setUpTestData(cls):
        users = (
            User(username='******'),
            User(username='******'),
            User(username='******'),
        )
        User.objects.bulk_create(users)

        site = Site.objects.create(name='Test Site 1', slug='test-site-1')
        ipaddress = IPAddress.objects.create(address='192.0.2.1/24')

        object_changes = (
            ObjectChange(
                user=users[0],
                user_name=users[0].username,
                request_id=uuid.uuid4(),
                action=ObjectChangeActionChoices.ACTION_CREATE,
                changed_object=site,
                object_repr=str(site),
                object_data={'name': site.name, 'slug': site.slug}
            ),
            ObjectChange(
                user=users[0],
                user_name=users[0].username,
                request_id=uuid.uuid4(),
                action=ObjectChangeActionChoices.ACTION_UPDATE,
                changed_object=site,
                object_repr=str(site),
                object_data={'name': site.name, 'slug': site.slug}
            ),
            ObjectChange(
                user=users[1],
                user_name=users[1].username,
                request_id=uuid.uuid4(),
                action=ObjectChangeActionChoices.ACTION_DELETE,
                changed_object=site,
                object_repr=str(site),
                object_data={'name': site.name, 'slug': site.slug}
            ),
            ObjectChange(
                user=users[1],
                user_name=users[1].username,
                request_id=uuid.uuid4(),
                action=ObjectChangeActionChoices.ACTION_CREATE,
                changed_object=ipaddress,
                object_repr=str(ipaddress),
                object_data={'address': ipaddress.address, 'status': ipaddress.status}
            ),
            ObjectChange(
                user=users[2],
                user_name=users[2].username,
                request_id=uuid.uuid4(),
                action=ObjectChangeActionChoices.ACTION_UPDATE,
                changed_object=ipaddress,
                object_repr=str(ipaddress),
                object_data={'address': ipaddress.address, 'status': ipaddress.status}
            ),
            ObjectChange(
                user=users[2],
                user_name=users[2].username,
                request_id=uuid.uuid4(),
                action=ObjectChangeActionChoices.ACTION_DELETE,
                changed_object=ipaddress,
                object_repr=str(ipaddress),
                object_data={'address': ipaddress.address, 'status': ipaddress.status}
            ),
        )
        ObjectChange.objects.bulk_create(object_changes)