Verified Commit d66c2ed4 authored by Adrian Schollmeyer's avatar Adrian Schollmeyer
Browse files

Add hausaufgang scripts


Signed-off-by: Adrian Schollmeyer's avatarNexAdn <nex@nexadn.de>
parent ffd2ba9a
#!/usr/bin/env python3
from django.utils.text import slugify
from circuits.models import *
from dcim.models import *
from ipam.models import *
from extras.scripts import *
class AddHausaufgang(Script):
class Meta:
name = "Neuer Hausaufgang"
description = "Erstelle einen neuen Hausaufgang mit Userports"
block = ObjectVar(
label = "Block",
queryset = Site.objects.filter(
tags__name__in = [ "block" ]
)
)
label = StringVar(
label = "Bezeichner",
description = "Form: A/B/.../Q/CJD",
regex = "^([ABCDEHIKLNPQ]|CJD)( .*)?$"
)
userports = TextVar(
label = "Userport-Bezeichner",
description = "Ein Bezeichner pro Zeile"
)
def run(self, data, commit):
site = data["block"]
patchpanel_label = data["label"]
userports = data["userports"]
patchpanel = Device(
name = "Hausaufgang " + patchpanel_label,
device_role = DeviceRole.objects.get(name = "Hausaufgang"),
device_type = DeviceType.objects.get(model = "Hausaufgang"),
site = site
)
patchpanel.save()
self.log_success("Created Patchpanel: {}".format(patchpanel))
for userport_label in userports.splitlines():
rear_port = RearPort(
name = "Hausaufgang {} {} Rear".format(patchpanel_label,
userport_label),
device = patchpanel,
positions = 1,
type = PORT_TYPE_8P8C
)
rear_port.save()
front_port = FrontPort(
name = "Hausaufgang {} {}".format(patchpanel_label,
userport_label),
device = patchpanel,
rear_port = rear_port,
rear_port_position = 1,
type = PORT_TYPE_8P8C
)
front_port.save()
#circuit = Circuit(
# cid = "Userport {} {}".format(patchpanel_label,
# userport_label),
# provider = Provider.objects.get(name = "Userport"),
# type = CircuitType.objects.get(name = "Userport")
#)
#circuit.save()
#circuit_termination = CircuitTermination(
# circuit = circuit,
# term_side = 'A',
# site = site,
# port_speed = 1000000
#)
#circuit_termination.save()
#conn = Cable(
# termination_a = front_port,
# termination_b = circuit_termination
#)
#conn.save()
self.log_info("Created Userport " + userport_label)
self.log_success("Added interfaces to Patchpanel")
class ConnectUserports(Script):
class Meta:
name = "(disabled) Connect userport to patchpanels"
description = "Bulk connect userports to a patchpanel"
patchpanel = ObjectVar(
label = "Patchpanel",
queryset = Device.objects.filter(
device_role__name = "Patchpanel Kupfer"
)
)
aufgang = ObjectVar(
label = "Hausaufgang",
queryset = Device.objects.filter(
device_role__name = "Hausaufgang"
)
)
connections = TextVar(
label = "Connections",
description =
"One connection per line. Form: [Userport name] | [Hausaufgang name]"
)
def run(self, data, commit):
self.log_error("I currently do nothing!")
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment