예제 #1
0
def device_related_pre_save(sender, instance, raw, using, **kwargs):
    """
    A hook for creating ``HistoryChange`` entry when a component is changed.
    """

    try:
        device = instance.device
    except Device.DoesNotExist:
        device = None
    ignore = {
        'dns_info',
        'hostname',
        'last_puppet',
        'last_seen',
        'network_id',
        'number',
        'snmp_community',
    }
    for field, orig, new in _field_changes(instance, ignore=ignore):
        HistoryChange(
            device=device,
            field_name=field,
            old_value=unicode(orig),
            new_value=unicode(new),
            user=device.saving_user if device else None,
            component=unicode(instance),
            component_id=instance.id,
            plugin=device.saving_plugin if device else '',
        ).save()
예제 #2
0
def device_post_save(sender, instance, raw, using, **kwargs):
    """A hook for creating ``HistoryChange`` entries when a device changes."""
    dirty = set()
    for field, orig, new in _field_changes(instance,
                                           ignore={
                                               'last_seen', 'cached_cost',
                                               'cached_price', 'raw',
                                               'uptime_seconds',
                                               'uptime_timestamp'
                                           }):
        dirty.add(field)
        HistoryChange(
            device=instance,
            field_name=field,
            old_value=unicode(orig),
            new_value=unicode(new),
            user=instance.saving_user,
            comment=instance.save_comment,
            plugin=instance.saving_plugin,
        ).save()
    if {
            'venture', 'venture_role', 'position', 'chassis_position',
            'parent', 'model'
    } & dirty:
        update_txt_records(instance)
예제 #3
0
def role_property_value_pre_save(sender, instance, raw, using, **kwargs):
    for field, orig, new in _field_changes(instance):
        HistoryChange.objects.create(
            device=instance.device,
            field_name="%s (property)" % instance.property.symbol,
            old_value=unicode(orig),
            new_value=unicode(new),
            user=instance.saving_user,
        )
예제 #4
0
def component_modelgroup_pre_save(sender, instance, raw, using, **kwargs):
    """
    A hook for creating ``HistoryModelChange`` entries when a component
    model group changes.
    """

    for field, orig, new in _field_changes(instance):
        HistoryModelChange(
            component_model_group=instance,
            field_name=field,
            old_value=unicode(orig),
            new_value=unicode(new),
            user=instance.saving_user,
        ).save()
예제 #5
0
def device_model_pre_save(sender, instance, raw, using, **kwargs):
    """
    A hook for creating ``HistoryModelChange`` entries when a device
    model changes.
    """

    for field, orig, new in _field_changes(instance):
        HistoryModelChange(
            device_model=instance,
            field_name=field,
            old_value=unicode(orig),
            new_value=unicode(new),
            user=instance.saving_user,
        ).save()
예제 #6
0
def device_post_save(sender, instance, raw, using, **kwargs):
    """A hook for creating ``HistoryChange`` entries when a device changes."""
    dirty = set()
    for field, orig, new in _field_changes(instance, ignore={
            'last_seen', 'cached_cost', 'cached_price', 'raw',
            'uptime_seconds', 'uptime_timestamp'}):
        dirty.add(field)
        HistoryChange(
            device=instance,
            field_name=field,
            old_value=unicode(orig),
            new_value=unicode(new),
            user=instance.saving_user,
            comment=instance.save_comment,
            plugin=instance.saving_plugin,
        ).save()
    if {'venture', 'venture_role', 'position', 'chassis_position',
            'parent', 'model'} & dirty:
        update_txt_records(instance)