Exemplo n.º 1
0
    def test_internal(self):
        data = wrap_groups([{
            'name':
            'NORDUnet',
            'type':
            'internal',
            'local-address':
            '192.168.3.5',
            'neighbor': [{
                'name': '192.168.3.1',
                'description': 'se-tug',
            }, {
                'name': '192.168.3.2',
                'description': 'se-fre',
            }]
        }])

        peerings = junos.parse_bgp_sessions(data)
        self.assertEqual(len(peerings), 2)
        peering1 = peerings[0]
        self.assertEqual(peering1.type, 'internal')
        self.assertEqual(peering1.group, 'NORDUnet')
        self.assertEqual(peering1.description, 'se-tug')
        self.assertEqual(peering1.local_address, '192.168.3.5')
        self.assertEqual(peering1.remote_address, '192.168.3.1')
        self.assertIsNone(peering1.as_number)

        peering2 = peerings[1]
        self.assertEqual(peering2.type, 'internal')
        self.assertEqual(peering2.group, 'NORDUnet')
        self.assertEqual(peering2.description, 'se-fre')
        self.assertEqual(peering2.local_address, '192.168.3.5')
        self.assertEqual(peering2.remote_address, '192.168.3.2')
        self.assertIsNone(peering2.as_number)
Exemplo n.º 2
0
    def test_no_type(self):
        data = wrap_groups([{
            'name': 'Weird',
            'neighbor': [{
                'name': '192.168.4.12',
            }]
        }])

        peerings = junos.parse_bgp_sessions(data)
        self.assertEqual(len(peerings), 1)
        peering = peerings[0]

        self.assertEqual(peering.group, 'Weird')
        self.assertEqual(peering.remote_address, '192.168.4.12')
        self.assertIsNone(peering.type)
        self.assertIsNone(peering.description)
        self.assertIsNone(peering.as_number)
        self.assertIsNone(peering.local_address)
Exemplo n.º 3
0
    def test_external(self):
        data = wrap_groups([{
            'name':
            'NRN-customer',
            'type':
            'external',
            'neighbor': [{
                'name': '192.168.4.11',
                'description': 'DeIC',
                'peer-as': '1835'
            }]
        }])

        peerings = junos.parse_bgp_sessions(data)
        self.assertEqual(len(peerings), 1)
        peering = peerings[0]

        self.assertEqual(peering.group, 'NRN-customer')
        self.assertEqual(peering.type, 'external')
        self.assertEqual(peering.description, 'DeIC')
        self.assertEqual(peering.remote_address, '192.168.4.11')
        self.assertEqual(peering.as_number, '1835')
        self.assertIsNone(peering.local_address)
Exemplo n.º 4
0
def junos_device_to_nerds(device, device_data, api):
    chassis_data = None
    try:
        chassis_data = api.post(
            '/devices/device/{}/rpc/jrpc:rpc-get-chassis-inventory/_operations/get-chassis-inventory'
            .format(device))
    except Exception as e:
        logger.warning('Could not get chassis inventory for %s. Error: %s',
                       device, e)

    router = junos.parse_router(device_data, chassis_data)
    ifdata = api.get(
        '/devices/device/{}/config/configuration/interfaces?deep'.format(
            device))
    router.interfaces = junos.parse_interfaces(ifdata)

    bgpdata = api.get(
        '/devices/device/{}/config/configuration/protocols/bgp?deep'.format(
            device))
    router.bgp_peerings = junos.parse_bgp_sessions(bgpdata)

    # logical systems
    logical_ifdata = api.get(
        '/devices/device/{}/config/configuration/logical-systems?select=name;interfaces(*)'
        .format(device),
        collection=True)
    junos.parse_logical_interfaces(logical_ifdata, router.interfaces)

    logical_bgpdata = api.get(
        '/devices/device/{}/config/configuration/logical-systems?select=name;protocols/bgp(*)'
        .format(device),
        collection=True)
    router.bgp_peerings += junos.parse_logical_bgp_sessions(logical_bgpdata)

    if device not in router.name:
        logger.warning('%s ==> %s', device, router.name)
    return to_nerds(router.name, 'nso_juniper', router.to_json())
Exemplo n.º 5
0
 def test_empty(self):
     data = {}
     peerings = junos.parse_bgp_sessions(data)
     self.assertEqual(peerings, [])