Source of truth and network automation platform for network infrastructure management.
—
Advanced features including custom fields, relationships, jobs, webhooks, templates, secrets management, and configuration contexts. Enables customization and automation workflows for network operations.
Flexible status and role system for objects.
class Status:
"""
Status objects for lifecycle management.
Attributes:
name (str): Status name
slug (str): URL-safe slug
color (str): Status color (hex)
description (str): Status description
content_types (list): Applicable content types
"""
class StatusField:
"""Status field for models."""
class StatusModel:
"""Base class for status-aware models."""
class Role:
"""
Role objects for functional classification.
Attributes:
name (str): Role name
slug (str): URL-safe slug
color (str): Role color (hex)
description (str): Role description
content_types (list): Applicable content types
weight (int): Role weight for ordering
"""
class RoleField:
"""Role field for models."""Flexible tagging system for object organization.
class Tag:
"""
Tags for object categorization and organization.
Attributes:
name (str): Tag name
slug (str): URL-safe slug
color (str): Tag color (hex)
description (str): Tag description
content_types (list): Applicable content types
"""
class TaggedItem:
"""
Tagged item associations.
Attributes:
tag (Tag): Associated tag
content_type (ContentType): Tagged object type
object_id (UUID): Tagged object ID
content_object (object): Tagged object
"""Runtime-configurable custom fields for any model.
class CustomField:
"""
Custom field definitions for extending models.
Attributes:
type (str): Field type (text, integer, boolean, date, etc.)
name (str): Field name
label (str): Field display label
description (str): Field description
required (bool): Whether field is required
filter_logic (str): Filter logic for searches
default (str): Default value
weight (int): Field ordering weight
validation_minimum (int): Minimum value validation
validation_maximum (int): Maximum value validation
validation_regex (str): Regex validation pattern
choices (list): Available choices for choice fields
content_types (list): Applicable content types
"""
class CustomFieldChoice:
"""
Choices for custom choice fields.
Attributes:
field (CustomField): Parent custom field
value (str): Choice value
weight (int): Choice ordering weight
"""
class CustomFieldModel:
"""Base class for models supporting custom fields."""
class ComputedField:
"""
Computed field definitions for calculated values.
Attributes:
content_type (ContentType): Target content type
slug (str): Field slug
label (str): Field display label
description (str): Field description
template (str): Jinja2 template for computation
fallback_value (str): Fallback value if computation fails
weight (int): Field ordering weight
"""Background job execution system for automation workflows.
class Job:
"""
Background job definitions for automation.
Attributes:
name (str): Job name
description (str): Job description
installed (bool): Whether job is installed
enabled (bool): Whether job is enabled
is_job_hook_receiver (bool): Whether job receives hooks
soft_time_limit (int): Soft time limit in seconds
time_limit (int): Hard time limit in seconds
grouping (str): Job grouping
slug (str): Job slug
source (str): Job source
git_repository (GitRepository): Source Git repository
job_class_name (str): Job class name
module_name (str): Job module name
"""
class JobResult:
"""
Job execution results and status.
Attributes:
obj_type (ContentType): Job content type
name (str): Job name
created (datetime): Creation timestamp
completed (datetime): Completion timestamp
user (User): User who ran the job
status (str): Job status (pending, running, completed, errored, failed)
data (dict): Job input data
job_id (UUID): Celery job ID
result (dict): Job result data
traceback (str): Error traceback if failed
job_kwargs (dict): Job keyword arguments
schedule (ScheduledJob): Associated scheduled job
"""
class JobLogEntry:
"""
Job execution log entries.
Attributes:
job_result (JobResult): Associated job result
log_level (str): Log level (debug, info, success, warning, error, critical)
grouping (str): Log grouping
message (str): Log message
created (datetime): Log timestamp
line_number (int): Log line number
"""
class JobButton:
"""
Job UI buttons for object actions.
Attributes:
name (str): Button name
job (Job): Associated job
enabled (bool): Whether button is enabled
text (str): Button text
content_types (list): Applicable content types
group_name (str): Button group
weight (int): Button ordering weight
button_class (str): CSS button class
confirmation (bool): Whether to show confirmation dialog
"""
class JobHook:
"""
Job hooks for event-driven automation.
Attributes:
name (str): Hook name
job (Job): Associated job
enabled (bool): Whether hook is enabled
content_types (list): Applicable content types
type_create (bool): Trigger on object creation
type_update (bool): Trigger on object update
type_delete (bool): Trigger on object deletion
"""Scheduled job execution and queue management.
class JobQueue:
"""
Job execution queues.
Attributes:
name (str): Queue name
enabled (bool): Whether queue is enabled
description (str): Queue description
"""
class JobQueueAssignment:
"""
Job to queue assignments.
Attributes:
job (Job): Associated job
queue (JobQueue): Assigned queue
enabled (bool): Whether assignment is enabled
"""
class ScheduledJob:
"""
Scheduled job execution definitions.
Attributes:
name (str): Scheduled job name
task (str): Task name
job_class (str): Job class name
job_model (Job): Associated job model
enabled (bool): Whether schedule is enabled
crontab (str): Cron expression
interval (str): Interval specification
one_off (bool): Whether job runs once
start_time (datetime): Schedule start time
user (User): User context for job execution
approval_required (bool): Whether approval is required
total_run_count (int): Total execution count
date_changed (datetime): Last modification date
description (str): Schedule description
kwargs (dict): Job arguments
queue (str): Execution queue
"""
class ScheduledJobs:
"""Scheduled job management utilities."""Git-based data source integration.
class GitRepository:
"""
Git repositories for data source integration.
Attributes:
name (str): Repository name
slug (str): URL-safe slug
remote_url (str): Git remote URL
branch (str): Git branch
current_head (str): Current HEAD commit
provided_contents (list): Content types provided
secrets_group (SecretsGroup): Associated secrets
username (str): Git username
token (str): Git token/password
_token (str): Encrypted token
"""Configuration context and schema management.
class ConfigContext:
"""
Configuration context for objects.
Attributes:
name (str): Context name
weight (int): Context priority weight
description (str): Context description
is_active (bool): Whether context is active
schema (ConfigContextSchema): Validation schema
data (dict): Context data (JSON)
locations (list): Applicable locations
roles (list): Applicable roles
device_types (list): Applicable device types
platforms (list): Applicable platforms
cluster_groups (list): Applicable cluster groups
clusters (list): Applicable clusters
tenants (list): Applicable tenants
tags (list): Required tags
"""
class ConfigContextModel:
"""Base class for models supporting configuration context."""
class ConfigContextSchema:
"""
JSON schemas for configuration context validation.
Attributes:
name (str): Schema name
description (str): Schema description
data_schema (dict): JSON schema definition
slug (str): URL-safe slug
"""Custom relationships between objects.
class Relationship:
"""
Custom relationships between objects.
Attributes:
name (str): Relationship name
slug (str): URL-safe slug
description (str): Relationship description
type (str): Relationship type (one-to-one, one-to-many, many-to-many)
source_type (ContentType): Source object type
source_label (str): Source side label
source_hidden (bool): Whether source side is hidden
source_filter (dict): Source object filter
destination_type (ContentType): Destination object type
destination_label (str): Destination side label
destination_hidden (bool): Whether destination side is hidden
destination_filter (dict): Destination object filter
symmetric (bool): Whether relationship is symmetric
required_on (str): Which side requires the relationship
advanced_ui (bool): Whether to use advanced UI
"""
class RelationshipAssociation:
"""
Relationship associations between objects.
Attributes:
relationship (Relationship): Relationship definition
source_type (ContentType): Source object type
source_id (UUID): Source object ID
source (object): Source object
destination_type (ContentType): Destination object type
destination_id (UUID): Destination object ID
destination (object): Destination object
"""
class RelationshipModel:
"""Base class for models supporting relationships."""Contact and team management for object associations.
class Contact:
"""
Contact information for object associations.
Attributes:
name (str): Contact name
phone (str): Phone number
email (str): Email address
address (str): Mailing address
comments (str): Additional comments
teams (list): Associated teams
"""
class ContactAssociation:
"""
Contact associations with objects.
Attributes:
contact (Contact): Associated contact
associated_object_type (ContentType): Associated object type
associated_object_id (UUID): Associated object ID
associated_object (object): Associated object
role (Role): Contact role
"""
class Team:
"""
Teams for contact organization.
Attributes:
name (str): Team name
phone (str): Team phone number
email (str): Team email address
address (str): Team address
comments (str): Team comments
contacts (list): Team members
"""Secure storage and management of sensitive information.
class Secret:
"""
Secure storage of sensitive information.
Attributes:
name (str): Secret name
slug (str): URL-safe slug
description (str): Secret description
provider (str): Secrets provider
parameters (dict): Provider-specific parameters
tags (list): Associated tags
"""
class SecretsGroup:
"""
Grouping of related secrets.
Attributes:
name (str): Group name
slug (str): URL-safe slug
description (str): Group description
secrets (list): Associated secrets
"""
class SecretsGroupAssociation:
"""
Secrets group associations.
Attributes:
group (SecretsGroup): Secrets group
secret (Secret): Associated secret
access_type (str): Access type (generic, environment-variable, etc.)
secret_type (str): Secret type (username, password, token, etc.)
"""Template system for data export and formatting.
class ExportTemplate:
"""
Export templates for data formatting.
Attributes:
content_type (ContentType): Target content type
name (str): Template name
description (str): Template description
template_code (str): Jinja2 template code
mime_type (str): Output MIME type
file_extension (str): Output file extension
as_attachment (bool): Whether to download as attachment
"""
class GraphQLQuery:
"""
Saved GraphQL queries.
Attributes:
name (str): Query name
slug (str): URL-safe slug
description (str): Query description
query (str): GraphQL query string
variables (dict): Query variables
"""
class CustomLink:
"""
Custom links for objects.
Attributes:
name (str): Link name
content_type (ContentType): Target content type
weight (int): Link ordering weight
group_name (str): Link group
button_class (str): CSS button class
new_window (bool): Whether to open in new window
link_text (str): Link text template
link_url (str): Link URL template
"""Webhook system for external integrations.
class Webhook:
"""
Webhooks for external system integration.
Attributes:
name (str): Webhook name
content_types (list): Applicable content types
enabled (bool): Whether webhook is enabled
type_create (bool): Trigger on object creation
type_update (bool): Trigger on object update
type_delete (bool): Trigger on object deletion
payload_url (str): Webhook URL
http_method (str): HTTP method (GET, POST, PUT, PATCH, DELETE)
http_content_type (str): Content type header
additional_headers (str): Additional HTTP headers
body_template (str): Request body template
secret (str): Webhook secret
ssl_verification (bool): Whether to verify SSL certificates
ca_file_path (str): CA file path for SSL verification
"""File attachment and management system.
class FileAttachment:
"""
File attachments for objects.
Attributes:
content_type (ContentType): Attached object type
object_id (UUID): Attached object ID
content_object (object): Attached object
file (FileField): Attached file
name (str): File name
created (datetime): Upload timestamp
"""
class ImageAttachment:
"""
Image attachments for objects.
Attributes:
content_type (ContentType): Attached object type
object_id (UUID): Attached object ID
content_object (object): Attached object
image (ImageField): Attached image
name (str): Image name
created (datetime): Upload timestamp
"""
class FileProxy:
"""File proxy for handling file operations."""Object metadata management.
class MetadataType:
"""
Metadata type definitions.
Attributes:
name (str): Metadata type name
description (str): Type description
data_type (str): Data type (text, integer, boolean, etc.)
content_types (list): Applicable content types
"""
class MetadataChoice:
"""
Choices for metadata fields.
Attributes:
metadata_type (MetadataType): Parent metadata type
value (str): Choice value
weight (int): Choice ordering weight
"""
class ObjectMetadata:
"""
Object metadata associations.
Attributes:
metadata_type (MetadataType): Metadata type
content_type (ContentType): Object type
object_id (UUID): Object ID
content_object (object): Object
scoped_fields (list): Scoped field values
value (str): Metadata value
"""Dynamic object grouping based on filters.
class DynamicGroup:
"""
Dynamic object grouping based on filter criteria.
Attributes:
name (str): Group name
slug (str): URL-safe slug
description (str): Group description
content_type (ContentType): Group content type
filter (dict): Group filter criteria
children (list): Child groups
parent (DynamicGroup): Parent group
"""
class DynamicGroupMembership:
"""
Dynamic group membership tracking.
Attributes:
group (DynamicGroup): Dynamic group
parent_type (ContentType): Parent object type
parent_id (UUID): Parent object ID
parent_object (object): Parent object
operator (str): Membership operator
weight (int): Membership weight
"""
class StaticGroupAssociation:
"""
Static group associations.
Attributes:
associated_object_type (ContentType): Associated object type
associated_object_id (UUID): Associated object ID
associated_object (object): Associated object
"""User view customization and sharing.
class SavedView:
"""
Saved views for customized object lists.
Attributes:
name (str): View name
slug (str): URL-safe slug
description (str): View description
content_type (ContentType): View content type
view (dict): View configuration
is_shared (bool): Whether view is shared
is_global_default (bool): Whether view is global default
"""
class UserSavedViewAssociation:
"""
User associations with saved views.
Attributes:
user (User): Associated user
saved_view (SavedView): Associated saved view
is_default (bool): Whether view is user default
"""External system integration framework.
class ExternalIntegration:
"""
External system integration definitions.
Attributes:
name (str): Integration name
remote_url (str): External system URL
verify_ssl (bool): Whether to verify SSL certificates
timeout (int): Request timeout in seconds
extra_config (dict): Additional configuration
secrets_group (SecretsGroup): Associated secrets
http_method (str): Default HTTP method
headers (dict): Default headers
"""
class HealthCheckTestModel:
"""Health check framework for system monitoring."""Object notes and annotations.
class Note:
"""
Notes and annotations for objects.
Attributes:
assigned_object_type (ContentType): Note target type
assigned_object_id (UUID): Note target ID
assigned_object (object): Note target object
user (User): Note author
created (datetime): Creation timestamp
slug (str): URL-safe slug
note (str): Note content
"""from nautobot.extras.models import CustomField
from nautobot.dcim.models import Device
# Create custom field
asset_tag_field = CustomField.objects.create(
type="text",
name="asset_tag",
label="Asset Tag",
description="Physical asset tag number",
required=True
)
# Add to device content type
from django.contrib.contenttypes.models import ContentType
device_ct = ContentType.objects.get_for_model(Device)
asset_tag_field.content_types.add(device_ct)
# Use custom field
device = Device.objects.get(name="router-01")
device.cf["asset_tag"] = "AST-001"
device.save()
# Query by custom field
devices_with_tag = Device.objects.filter(cf__asset_tag="AST-001")from nautobot.extras.jobs import Job
from nautobot.dcim.models import Device
class DeviceHealthCheck(Job):
class Meta:
name = "Device Health Check"
description = "Check device health status"
def run(self):
self.log_info("Starting device health check")
devices = Device.objects.filter(status__name="Active")
healthy_count = 0
for device in devices:
# Health check logic here
if self.check_device_health(device):
healthy_count += 1
self.log_success(f"Device {device.name} is healthy")
else:
self.log_failure(f"Device {device.name} has issues")
result = f"Health check complete: {healthy_count}/{len(devices)} devices healthy"
self.log_info(result)
return result
def check_device_health(self, device):
# Custom health check logic
return Truefrom nautobot.extras.models import Relationship, RelationshipAssociation
from nautobot.dcim.models import Device
from django.contrib.contenttypes.models import ContentType
# Create relationship
device_ct = ContentType.objects.get_for_model(Device)
backup_relationship = Relationship.objects.create(
name="device-backup",
type="one-to-one",
source_type=device_ct,
source_label="Primary Device",
destination_type=device_ct,
destination_label="Backup Device"
)
# Create association
primary_device = Device.objects.get(name="router-01")
backup_device = Device.objects.get(name="router-02")
RelationshipAssociation.objects.create(
relationship=backup_relationship,
source=primary_device,
destination=backup_device
)from nautobot.extras.models import Webhook
from django.contrib.contenttypes.models import ContentType
from nautobot.dcim.models import Device
# Create webhook
device_ct = ContentType.objects.get_for_model(Device)
webhook = Webhook.objects.create(
name="Device Change Notification",
payload_url="https://api.example.com/nautobot-webhook",
http_method="POST",
enabled=True,
type_create=True,
type_update=True,
type_delete=True,
body_template='{"event": "{{ event_type }}", "device": "{{ data.name }}"}',
secret="webhook-secret-key"
)
webhook.content_types.add(device_ct)from nautobot.extras.models import ConfigContext
# Create configuration context
config_context = ConfigContext.objects.create(
name="SNMP Config",
weight=1000,
data={
"snmp": {
"community": "public",
"version": "2c",
"contact": "admin@example.com"
}
}
)
# Apply to specific roles
from nautobot.extras.models import Role
router_role = Role.objects.get(name="Router")
config_context.roles.add(router_role)
# Access context on device
device = Device.objects.get(name="router-01")
context_data = device.get_config_context()
snmp_config = context_data.get("snmp", {})Install with Tessl CLI
npx tessl i tessl/pypi-nautobot@2.4.1