nautobot / nautobot-plugin-ssot-arista-cloudvision

Single Source of Truth synchronization between Nautobot and Arista CloudVision
Other
9 stars 7 forks source link

Add arista_toplogy_pod in custom_field #127

Closed nsicard514 closed 1 year ago

nsicard514 commented 1 year ago

Environment

Proposed Functionality

# pylint: disable=invalid-name
"""Nautobot signal handler functions for aristavc_sync."""

from django.apps import apps as global_apps
from nautobot.extras.choices import CustomFieldTypeChoices

def post_migrate_create_custom_fields(apps=global_apps, **kwargs):
    """Callback function for post_migrate() -- create CustomField records."""
    ContentType = apps.get_model("contenttypes", "ContentType")
    Device = apps.get_model("dcim", "Device")
    CustomField = apps.get_model("extras", "CustomField")

    for device_cf_dict in [
        {
            "name": "arista_eostrain",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "EOS Train",
        },
        {
            "name": "arista_eos",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "EOS Version",
        },
        {
            "name": "arista_ztp",
            "type": CustomFieldTypeChoices.TYPE_BOOLEAN,
            "label": "ztp",
        },
        {
            "name": "arista_pimbidir",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "pimbidir",
        },
        {
            "name": "arista_pim",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "pim",
        },
        {
            "name": "arista_bgp",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "bgp",
        },
        {
            "name": "arista_mpls",
            "type": CustomFieldTypeChoices.TYPE_BOOLEAN,
            "label": "mpls",
        },
        {
            "name": "arista_systype",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "systype",
        },
        {
            "name": "arista_mlag",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "mlag",
        },
        {
            "name": "arista_tapagg",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "TAP Aggregation",
        },
        {
            "name": "arista_sflow",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "sFlow",
        },
        {
            "name": "arista_terminattr",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "TerminAttr Version",
        },
        {
            "name": "arista_topology_network_type",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "Topology Network Type",
        },
        {
            "name": "arista_topology_type",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "Topology Type",
        },
        {
            "name": "arista_topology_pod",
            "type": CustomFieldTypeChoices.TYPE_TEXT,
            "label": "Topology pod",
        },
    ]:
        print("-------------------------------------------")
        print(device_cf_dict)
        field, created = CustomField.objects.get_or_create(
            name=device_cf_dict["name"],
            defaults=device_cf_dict,
            slug=device_cf_dict["name"],
        )
        print(field, created)
        field.content_types.set([ContentType.objects.get_for_model(Device)])

def post_migrate_create_manufacturer(apps=global_apps, **kwargs):
    """Callback function for post_migrate() -- create Arista Manufacturer."""
    Manufacturer = apps.get_model("dcim", "Manufacturer")
    Manufacturer.objects.get_or_create(name="Arista", slug="arista")

def post_migrate_create_platform(apps=global_apps, **kwargs):
    """Callback function for post_migrate() -- create Arista Platform."""
    Platform = apps.get_model("dcim", "Platform")
    Manufacturer = apps.get_model("dcim", "Manufacturer")
    Platform.objects.get_or_create(
        name="arista.eos.eos",
        slug="arista_eos",
        napalm_driver="eos",
        manufacturer=Manufacturer.objects.get(slug="arista"),
    )

Use Case

Switch A - Switch B (pod1) Switch C - Switch D (pod2) Switch E - Switch F (pod3) I want to have two free interfaces of my pod1, so to know which switches is my pod 1 , I search for pod1 in the field arista_topology_rack.

The pod1 information is provide from cloudvision configuration. image

jdrew82 commented 1 year ago

Hey @nsicard514 is this a dupe of #126 but a different tag?

nsicard514 commented 1 year ago

Hey,

Yes exactly

jdrew82 commented 1 year ago

OK, can we please close this one then and just make a note about the other field in that issue?