mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-09 05:12:18 -06:00
* Add sync_interval to DataSource * Enqueue a SyncDataSourceJob when needed after saving a DataSource * Fix logic for clearing pending jobs on interval change * Fix lingering background tasks after modifying DataSource
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from core.choices import *
|
|
from core.models import DataFile, DataSource
|
|
from netbox.api.fields import ChoiceField, RelatedObjectCountField
|
|
from netbox.api.serializers import NetBoxModelSerializer
|
|
from netbox.utils import get_data_backend_choices
|
|
|
|
__all__ = (
|
|
'DataFileSerializer',
|
|
'DataSourceSerializer',
|
|
)
|
|
|
|
|
|
class DataSourceSerializer(NetBoxModelSerializer):
|
|
type = ChoiceField(
|
|
choices=get_data_backend_choices()
|
|
)
|
|
status = ChoiceField(
|
|
choices=DataSourceStatusChoices,
|
|
read_only=True
|
|
)
|
|
|
|
# Related object counts
|
|
file_count = RelatedObjectCountField('datafiles')
|
|
|
|
class Meta:
|
|
model = DataSource
|
|
fields = [
|
|
'id', 'url', 'display_url', 'display', 'name', 'type', 'source_url', 'enabled', 'status', 'description',
|
|
'sync_interval', 'parameters', 'ignore_rules', 'comments', 'custom_fields', 'created', 'last_updated',
|
|
'last_synced', 'file_count',
|
|
]
|
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
|
|
|
|
|
class DataFileSerializer(NetBoxModelSerializer):
|
|
source = DataSourceSerializer(
|
|
nested=True,
|
|
read_only=True
|
|
)
|
|
|
|
class Meta:
|
|
model = DataFile
|
|
fields = [
|
|
'id', 'url', 'display_url', 'display', 'source', 'path', 'last_updated', 'size', 'hash',
|
|
]
|
|
brief_fields = ('id', 'url', 'display', 'path')
|