Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie updated by NetworkToCode Cookie Drift Manager Tool #859

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"_drift_manager": {
"template": "https://github.com/nautobot/cookiecutter-nautobot-app.git",
"template_dir": "nautobot-app",
"template_ref": "refs/tags/nautobot-app-v2.4.0",
"template_ref": "refs/tags/nautobot-app-v2.4.1",
"cookie_dir": "",
"branch_prefix": "drift-manager",
"pull_request_strategy": "create",
Expand All @@ -30,7 +30,7 @@
"poetry"
],
"draft": false,
"baked_commit_ref": "69ab82f79f346d3e9e9cf62432bdd6d6b9c53e3f"
"baked_commit_ref": "baf8508b44f904c4c60e5d72dc19abc323508d8c"
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Linting: ruff format"
run: "poetry run invoke ruff --action format"
ruff-lint:
Expand All @@ -37,6 +39,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Linting: ruff"
run: "poetry run invoke ruff --action lint"
check-docs-build:
Expand All @@ -48,6 +52,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Check Docs Build"
run: "poetry run invoke build-and-check-docs"
poetry:
Expand All @@ -59,6 +65,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Checking: poetry lock file"
run: "poetry run invoke lock --check"
yamllint:
Expand All @@ -70,6 +78,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Linting: yamllint"
run: "poetry run invoke yamllint"
check-in-docker:
Expand All @@ -92,6 +102,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Constrain Nautobot version and regenerate lock file"
env:
INVOKE_NAUTOBOT_GOLDEN_CONFIG_LOCAL: "true"
Expand Down Expand Up @@ -147,6 +159,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Constrain Nautobot version and regenerate lock file"
env:
INVOKE_NAUTOBOT_GOLDEN_CONFIG_LOCAL: "true"
Expand Down Expand Up @@ -188,6 +202,8 @@ jobs:
fetch-depth: "0"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.5"
- name: "Check for changelog entry"
run: |
git fetch --no-tags origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Apache Software License 2.0

Copyright (c) 2024, Network to Code, LLC
Copyright (c) 2025, Network to Code, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions changes/+nautobot-app-v2.4.1.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rebaked from the cookie `nautobot-app-v2.4.1`.
6 changes: 4 additions & 2 deletions development/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ services:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
# To expose postgres or redis to the host uncomment the following
# postgres:
# To expose postgres (5432), myql (3306) on db service or redis (6379) to the host uncomment the
# following. Ensure to match the 2 idented spaces which to have the service nested under services.
# db:
# ports:
# - "5432:5432"
# - "3306:3306"
# redis:
# ports:
# - "6379:6379"
7 changes: 7 additions & 0 deletions development/docker-compose.mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ services:
- "development.env"
- "creds.env"
- "development_mysql.env"
beat:
environment:
- "NAUTOBOT_DB_ENGINE=django.db.backends.mysql"
env_file:
- "development.env"
- "creds.env"
- "development_mysql.env"
db:
image: "mysql:8"
command:
Expand Down
14 changes: 3 additions & 11 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys

from nautobot.core.settings import * # noqa: F403 # pylint: disable=wildcard-import,unused-wildcard-import
from nautobot.core.settings_funcs import is_truthy, parse_redis_connection
from nautobot.core.settings_funcs import is_truthy

#
# Debug
Expand Down Expand Up @@ -65,16 +65,8 @@
#

# The django-redis cache is used to establish concurrent locks using Redis.
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": parse_redis_connection(redis_database=0),
"TIMEOUT": 300,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
}
}
# Inherited from nautobot.core.settings
# CACHES = {....}

#
# Celery settings are not defined here because they can be overloaded with
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ nav:
- Extending the App: "dev/extending.md"
- Contributing to the App: "dev/contributing.md"
- Development Environment: "dev/dev_environment.md"
- Release Checklist: "dev/release_checklist.md"
- Architecture Decision Records: "dev/arch_decision.md"
- Code Reference:
- "dev/code_reference/index.md"
Expand Down
132 changes: 7 additions & 125 deletions nautobot_golden_config/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,136 +1,18 @@
"""REST API serializer capabilities for graphql app."""
"""API serializers for nautobot_golden_config."""

# pylint: disable=too-many-ancestors
from nautobot.core.api.serializers import NautobotModelSerializer
from nautobot.dcim.api.serializers import DeviceSerializer
from nautobot.dcim.models import Device
from nautobot.extras.api.mixins import TaggedModelSerializerMixin
from rest_framework import serializers
from nautobot.apps.api import NautobotModelSerializer, TaggedModelSerializerMixin

from nautobot_golden_config import models
from nautobot_golden_config.utilities.config_postprocessing import get_config_postprocessing


class GraphQLSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""Serializer for a GraphQL object."""

data = serializers.JSONField()


class ComplianceFeatureSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for ComplianceFeature object."""
class ComplianceFeatureSerializer(NautobotModelSerializer, TaggedModelSerializerMixin): # pylint: disable=too-many-ancestors
"""ComplianceFeature Serializer."""

class Meta:
"""Set Meta Data for ComplianceFeature, will serialize all fields."""
"""Meta attributes."""

model = models.ComplianceFeature
fields = "__all__"


class ComplianceRuleSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for ComplianceRule object."""

class Meta:
"""Set Meta Data for ComplianceRule, will serialize all fields."""

model = models.ComplianceRule
fields = "__all__"


class ConfigComplianceSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for ConfigCompliance object."""

class Meta:
"""Set Meta Data for ConfigCompliance, will serialize fields."""

model = models.ConfigCompliance
fields = "__all__"


class GoldenConfigSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for GoldenConfig object."""

class Meta:
"""Set Meta Data for GoldenConfig, will serialize all fields."""

model = models.GoldenConfig
fields = "__all__"


class GoldenConfigSettingSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for GoldenConfigSetting object."""

class Meta:
"""Set Meta Data for GoldenConfigSetting, will serialize all fields."""

model = models.GoldenConfigSetting
fields = "__all__"


class ConfigRemoveSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for ConfigRemove object."""

class Meta:
"""Set Meta Data for ConfigRemove, will serialize all fields."""

model = models.ConfigRemove
fields = "__all__"


class ConfigReplaceSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for ConfigReplace object."""

class Meta:
"""Set Meta Data for ConfigReplace, will serialize all fields."""

model = models.ConfigReplace
fields = "__all__"


class ConfigToPushSerializer(DeviceSerializer): # pylint: disable=nb-sub-class-name
"""Serializer for ConfigToPush view."""

config = serializers.SerializerMethodField()

class Meta(DeviceSerializer.Meta):
"""Extend the Device serializer with the configuration after postprocessing."""

fields = "__all__"
model = Device

def get_config(self, obj):
"""Provide the intended configuration ready after postprocessing to the config field."""
request = self.context.get("request")
config_details = models.GoldenConfig.objects.get(device=obj)
return get_config_postprocessing(config_details, request)


class RemediationSettingSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for RemediationSetting object."""

class Meta:
"""Set Meta Data for RemediationSetting, will serialize all fields."""

model = models.RemediationSetting
fields = "__all__"


class ConfigPlanSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):
"""Serializer for ConfigPlan object."""

class Meta:
"""Set Meta Data for ConfigPlan, will serialize all fields."""

model = models.ConfigPlan
fields = "__all__"
read_only_fields = ["device", "plan_type", "feature", "config_set"]


class GenerateIntendedConfigSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""Serializer for GenerateIntendedConfigView."""

intended_config = serializers.CharField(read_only=True)
intended_config_lines = serializers.ListField(read_only=True, child=serializers.CharField())
graphql_data = serializers.JSONField(read_only=True)
diff = serializers.CharField(read_only=True)
diff_lines = serializers.ListField(read_only=True, child=serializers.CharField())
# Option for disabling write for certain fields:
# read_only_fields = []
32 changes: 5 additions & 27 deletions nautobot_golden_config/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
"""API for Custom Jobs ."""
"""Django API urlpatterns declaration for nautobot_golden_config app."""

from django.urls import path
from nautobot.core.api.routers import OrderedDefaultRouter
from nautobot.apps.api import OrderedDefaultRouter

from nautobot_golden_config.api import views

router = OrderedDefaultRouter()
router.APIRootView = views.GoldenConfigRootView
router.register("compliance-feature", views.ComplianceFeatureViewSet)
router.register("compliance-rule", views.ComplianceRuleViewSet)
router.register("config-compliance", views.ConfigComplianceViewSet)
router.register("golden-config", views.GoldenConfigViewSet)
router.register("golden-config-settings", views.GoldenConfigSettingViewSet)
router.register("config-remove", views.ConfigRemoveViewSet)
router.register("config-replace", views.ConfigReplaceViewSet)
router.register("remediation-setting", views.RemediationSettingViewSet)
router.register("config-postprocessing", views.ConfigToPushViewSet)
router.register("config-plan", views.ConfigPlanViewSet)
# add the name of your api endpoint, usually hyphenated model name in plural, e.g. "my-model-classes"
router.register("compliancefeature", views.ComplianceFeatureViewSet)

urlpatterns = [
path(
"sotagg/<uuid:pk>/",
views.SOTAggDeviceDetailView.as_view(),
name="device_detail",
),
path(
"generate-intended-config/",
views.GenerateIntendedConfigView.as_view(),
name="generate_intended_config",
),
]
urlpatterns += router.urls
urlpatterns = router.urls
Loading
Loading