Created
April 13, 2022 21:20
-
-
Save jathanism/1da1af81985708e8c0987ce8858850a1 to your computer and use it in GitHub Desktop.
Nautobot test job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nautobot.dcim.models import Device | |
from nautobot.dcim.models import Interface | |
from nautobot.dcim.choices import InterfaceTypeChoices | |
from nautobot.ipam.models import VLAN | |
from nautobot.extras.jobs import Job | |
class TestJob(Job): | |
class Meta: | |
description = "Some job jo!" | |
def run(self, data, commit): | |
device = Device.objects.get(name="test_device") | |
vlan = VLAN.objects.filter(site__slug="test_site")[3] | |
vlans = VLAN.objects.filter(site__slug="test_site")[0:10] | |
Interface.objects.filter(device__name="test_device").delete() | |
tags = [f"test{i}" for i in range(10)] | |
for i in range(256): | |
interface, _ = Interface.objects.update_or_create( | |
name = f"interface{i}", | |
device = device, | |
type = InterfaceTypeChoices.TYPE_OTHER, | |
untagged_vlan = vlan | |
) | |
# self.log_success(f"Interface {interface.name} succesfully created") | |
interface.tagged_vlans.set(vlans) | |
# self.log_success(f"Interface {interface.name} added tagged vlans") | |
for tag in tags: | |
# self.log_success(f"Added tag {tag}") | |
interface.tags.add(tag) | |
# self.log_success(f"Interface {interface.name} added tags") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment