Exemplo n.º 1
0
    def setup_bbr(self, site, rack, vlan, site_no, node_id, asset_tag, sw):
        bbr_name = "bbr-%s.in.ffho.net" % site.slug

        try:
            bbr = Device.objects.get(name=bbr_name)
            self.log_info("Backbone router %s already present, carrying on." %
                          bbr_name)

            return bbr
        except Device.DoesNotExist:
            pass

        bbr_type = DeviceType.objects.get(manufacturer__name='PCEngines',
                                          model='APU2c4-19"')

        bbr = Device(
            device_type=bbr_type,
            device_role=DeviceRole.objects.get(name='Backbone router'),
            platform=Platform.objects.get(name='Linux'),
            name=bbr_name,
            asset_tag=asset_tag,
            status=DeviceStatusChoices.STATUS_PLANNED,
            site=site,
            rack=rack,
            position=rack.u_height - 4,
            face=DeviceFaceChoices.FACE_FRONT,
        )

        bbr.save()
        self.log_success("Created backbone router %s" % bbr)

        # Set bond0 mode to tagged-all, bundle enp<n>s0 into it and connect enp<n>s0  to switchport 10 + n
        bbr_bond0 = Interface.objects.get(device=bbr, name="bond0")
        bbr_bond0.mode = InterfaceModeChoices.MODE_TAGGED_ALL
        bbr_bond0.save()

        # Link enp1s0 and enp2s0 to switch port 10 and 11 respectivly
        for n in [1, 2]:
            bbr_port = Interface.objects.get(device=bbr, name="enp%ds0" % n)
            sw_port = Interface.objects.get(device=sw, name=str(10 + n))
            cable = Cable(termination_a=sw_port,
                          termination_b=bbr_port,
                          status=CableStatusChoices.STATUS_PLANNED)
            cable.save()

            bbr_port.lag = bbr_bond0
            bbr_port.save()

        self.log_success("Linked %s to %s" % (bbr, sw))

        # Disable enp3s0
        enp3s0 = Interface.objects.get(device=bbr, name="enp3s0")
        enp3s0.enabled = False
        enp3s0.save()

        # Set up Mgmt vlan interface + IP
        bbr_mgmt_iface = Interface(
            device=bbr,
            name="vlan%d" % vlan.vid,
            type=InterfaceTypeChoices.TYPE_VIRTUAL,
        )
        bbr_mgmt_iface.save()

        bbr_mgmt_ip = IPAddress(address="172.30.%d.1/24" % site_no,
                                interface=bbr_mgmt_iface)
        bbr_mgmt_ip.save()

        self.log_success("Configured %s on interface %s of %s" %
                         (bbr_mgmt_ip, bbr_mgmt_iface, bbr))

        # Set up loopback IPs
        bbr_lo_iface = Interface.objects.get(device=bbr, name="lo")
        ipv4 = IPAddress(address="10.132.255.%s/32" % node_id,
                         interface=bbr_lo_iface)
        ipv4.save()

        ipv6 = IPAddress(address="2a03:2260:2342:ffff::%s/128" % node_id,
                         interface=bbr_lo_iface)
        ipv6.save()

        bbr.primary_ip4 = ipv4
        bbr.primary_ip6 = ipv6
        bbr.save()
        self.log_success("Configured %s + %s on lo interface of %s" %
                         (ipv4, ipv6, bbr))
Exemplo n.º 2
0
    def run(self, data, commit):

        services_list = [
            {
                'id_s': 's2',
                'port': 22,
                'name': 'SSHv2',
                'protocol': 'tcp'
            },
            {
                'id_s': 's1',
                'port': 22,
                'name': 'SSHv1',
                'protocol': 'tcp'
            },
            {
                'id_s': 't',
                'port': 23,
                'name': 'Telnet',
                'protocol': 'tcp'
            },
            {
                'id_s': 'y',
                'port': 443,
                'name': 'YANG',
                'protocol': 'tcp'
            },
            {
                'id_s': 'r',
                'port': 443,
                'name': 'REST',
                'protocol': 'tcp'
            },
        ]

        dev_role = DeviceRole.objects.get(slug='access-switch')
        device_new = Device(
            name=data['dev_name'],
            device_type=data['dev_model'],
            site=data['site'],
            rack=data['rack'],
            position=data['position'],
            device_role=dev_role,
            serial=data['dev_serial'],
        )
        device_new.save()

        device_new.custom_field_data['fMonitoring'] = data['monitoring']
        device_new.custom_field_data['fBackup'] = data['backup']
        device_new.save()

        output = []
        for iServ in data['services']:
            output.append(iServ)
            print(output)
            res = [row for row in services_list if row['id_s'] == iServ]
            s1 = Service(
                device=device_new,
                name=res[0]['name'],
                ports=[res[0]['port']],
                protocol=res[0]['protocol'],
            )
            s1.save()

        dev_mgmt_int = Interface(
            device=device_new,
            name=data['mgmt_int_name'],
            type='virtual',
        )
        dev_mgmt_int.save()

        ipa_type = ContentType.objects.get(app_label='dcim', model='interface')
        ipa = IPAddress(
            address=data['mgmt_int_ip'],
            assigned_object_id=dev_mgmt_int.id,
            assigned_object_type=ipa_type,
        )
        ipa.save()

        device_new.primary_ip4 = ipa

        device_new.save()

        self.log_success(f"Created new Juniper device: {device_new}")
        return ''.join(output)
Exemplo n.º 3
0
    def setup_swtich(self, site, rack, pp, panel_ports, vlan, site_no,
                     asset_tag):
        sw_name = "sw-%s-01.in.ffho.net" % site.slug

        try:
            sw = Device.objects.get(name=sw_name)
            self.log_info("Switch %s already present, carrying on." % sw_name)

            return sw
        except Device.DoesNotExist:
            pass

        sw_type = DeviceType.objects.get(manufacturer__name='Netonix',
                                         model='WS-12-250-AC')

        sw = Device(device_type=sw_type,
                    device_role=DeviceRole.objects.get(name='Switch'),
                    platform=Platform.objects.get(name='Netonix'),
                    name=sw_name,
                    asset_tag=asset_tag,
                    status=DeviceStatusChoices.STATUS_PLANNED,
                    site=site,
                    rack=rack,
                    position=rack.u_height - 2,
                    face=DeviceFaceChoices.FACE_FRONT)

        sw.save()
        self.log_success("Created switch %s" % sw)

        # Link switch ports for panel ports
        for n in range(1, int(panel_ports) + 1):
            cable = Cable(termination_a=Interface.objects.get(device=sw,
                                                              name=str(n)),
                          termination_b=FrontPort.objects.get(device=pp,
                                                              name=str(n)),
                          status=CableStatusChoices.STATUS_PLANNED)
            cable.save()

        # Disable interfaces which aren't connected
        unused_ifaces = [13, 14]
        if panel_ports < 10:
            unused_ifaces.extend(list(range(int(panel_ports + 1), 10)))
        unused_ifaces = [str(x) for x in sorted(unused_ifaces)]
        for n in unused_ifaces:
            iface = Interface.objects.get(device=sw, name=n)
            iface.enabled = False
            iface.save()

        self.log_success("Disabled switch unsued ports %s" %
                         ",".join(unused_ifaces))

        # Set up Mgmt port
        sw_mgmt_port = Interface.objects.get(device=sw, name="10")
        sw_mgmt_port.mode = InterfaceModeChoices.MODE_ACCESS
        sw_mgmt_port.untagged_vlan = vlan
        sw_mgmt_port.description = "Mgmt"
        sw_mgmt_port.save()

        self.log_success("Set mgmt interface 10 to untagged VLAN %s" % vlan)

        # Set po1 tagged-all and bundle ports 11 + 12 into it
        sw_po1 = Interface.objects.get(device=sw, name='po1')
        sw_po1.mode = InterfaceModeChoices.MODE_TAGGED_ALL
        sw_po1.save()

        for n in [11, 12]:
            sw_port = Interface.objects.get(device=sw, name=str(n))
            sw_port.lag = sw_po1
            sw_port.save()

        self.log_success("Linked first %s ports of %s to %s" %
                         (panel_ports, sw, pp))

        # Set up Mgmt vlan interface + IP
        sw_mgmt_iface = Interface(
            device=sw,
            name="vlan%d" % vlan.vid,
            type=InterfaceTypeChoices.TYPE_VIRTUAL,
        )
        sw_mgmt_iface.save()

        sw_mgmt_ip = IPAddress(address="172.30.%d.10/24" % site_no,
                               interface=sw_mgmt_iface)
        sw_mgmt_ip.save()

        sw.primary_ip4 = sw_mgmt_ip
        sw.save()

        self.log_success("Configured %s on interface %s of %s" %
                         (sw_mgmt_ip, sw_mgmt_iface, sw))

        return sw