Source of truth and network automation platform for network infrastructure management.
—
Multi-tenancy support and user management including tenants, groups, permissions, and authentication. Provides role-based access control and organizational separation.
Multi-tenant organization and access control.
class Tenant:
"""
Tenant objects for multi-tenancy support.
Attributes:
name (str): Tenant name
slug (str): URL-safe slug
group (TenantGroup): Tenant group
description (str): Tenant description
comments (str): Comments
tags (list): Associated tags
"""
class TenantGroup:
"""
Hierarchical tenant groups.
Attributes:
name (str): Group name
slug (str): URL-safe slug
parent (TenantGroup): Parent group
description (str): Group description
"""User accounts and authentication.
class User:
"""
Extended user model with Nautobot-specific features.
Attributes:
username (str): Username
email (str): Email address
first_name (str): First name
last_name (str): Last name
is_staff (bool): Staff status
is_active (bool): Active status
is_superuser (bool): Superuser status
date_joined (datetime): Join date
last_login (datetime): Last login
groups (list): User groups
user_permissions (list): User permissions
config_data (dict): User configuration data
"""
class AdminGroup:
"""
Administrative groups for user organization.
Attributes:
name (str): Group name
users (list): Group members
permissions (list): Group permissions
"""
class Token:
"""
API authentication tokens.
Attributes:
user (User): Token owner
created (datetime): Creation timestamp
expires (datetime): Expiration timestamp
key (str): Token key
write_enabled (bool): Write permissions
description (str): Token description
allowed_ips (list): Allowed IP addresses
"""Object-level permissions and access control.
class ObjectPermission:
"""
Object-level permissions for fine-grained access control.
Attributes:
name (str): Permission name
description (str): Permission description
enabled (bool): Whether permission is enabled
object_types (list): Applicable object types
groups (list): Groups with this permission
users (list): Users with this permission
actions (list): Permitted actions (view, add, change, delete)
constraints (dict): Permission constraints
"""from nautobot.tenancy.models import Tenant, TenantGroup
# Create tenant group
tenant_group = TenantGroup.objects.create(
name="Customers",
description="Customer tenants"
)
# Create tenant
tenant = Tenant.objects.create(
name="Acme Corp",
group=tenant_group,
description="Acme Corporation tenant"
)
# Assign tenant to objects
from nautobot.dcim.models import Device
device = Device.objects.get(name="router-01")
device.tenant = tenant
device.save()from nautobot.users.models import User, Token
from django.contrib.auth.models import Group
# Create user
user = User.objects.create_user(
username="network_admin",
email="admin@example.com",
first_name="Network",
last_name="Admin"
)
# Create API token
token = Token.objects.create(
user=user,
description="API access token",
write_enabled=True
)
# Add user to group
admin_group, created = Group.objects.get_or_create(name="Network Administrators")
user.groups.add(admin_group)from nautobot.users.models import ObjectPermission
from nautobot.dcim.models import Device
from django.contrib.contenttypes.models import ContentType
# Create object permission
device_ct = ContentType.objects.get_for_model(Device)
permission = ObjectPermission.objects.create(
name="Device Read Access",
actions=["view"],
constraints={"tenant__name": "Acme Corp"}
)
permission.object_types.add(device_ct)
permission.users.add(user)Install with Tessl CLI
npx tessl i tessl/pypi-nautobot