Ejemplo n.º 1
0
    def setUpTestData(cls):

        rirs = (
            RIR(name='RIR 1', slug='rir-1'),
            RIR(name='RIR 2', slug='rir-2'),
        )
        RIR.objects.bulk_create(rirs)

        aggregates = (
            Aggregate(prefix=IPNetwork('10.0.0.0/8'), rir=rirs[0]),
            Aggregate(prefix=IPNetwork('172.16.0.0/12'), rir=rirs[0]),
            Aggregate(prefix=IPNetwork('192.168.0.0/16'), rir=rirs[0]),
        )
        Aggregate.objects.bulk_create(aggregates)

        cls.create_data = [
            {
                'prefix': '100.0.0.0/8',
                'rir': rirs[1].pk,
            },
            {
                'prefix': '101.0.0.0/8',
                'rir': rirs[1].pk,
            },
            {
                'prefix': '102.0.0.0/8',
                'rir': rirs[1].pk,
            },
        ]
Ejemplo n.º 2
0
    def setUpTestData(cls):

        rirs = (
            RIR(name='RIR 1', slug='rir-1'),
            RIR(name='RIR 2', slug='rir-2'),
        )
        RIR.objects.bulk_create(rirs)

        Aggregate.objects.bulk_create([
            Aggregate(prefix=IPNetwork('10.1.0.0/16'), rir=rirs[0]),
            Aggregate(prefix=IPNetwork('10.2.0.0/16'), rir=rirs[0]),
            Aggregate(prefix=IPNetwork('10.3.0.0/16'), rir=rirs[0]),
        ])

        cls.form_data = {
            'prefix': IPNetwork('10.99.0.0/16'),
            'rir': rirs[1].pk,
            'date_added': datetime.date(2020, 1, 1),
            'description': 'A new aggregate',
            'tags': 'Alpha,Bravo,Charlie',
        }

        cls.csv_data = (
            "prefix,rir",
            "10.4.0.0/16,RIR 1",
            "10.5.0.0/16,RIR 1",
            "10.6.0.0/16,RIR 1",
        )

        cls.bulk_edit_data = {
            'rir': rirs[1].pk,
            'date_added': datetime.date(2020, 1, 1),
            'description': 'New description',
        }
Ejemplo n.º 3
0
    def mutate_and_get_payload(cls, input, context, info):
        rir = input.get('rir')

        temp = Aggregate()

        if not_none(rir):
            temp.rir = RIR.objects.get(pk=from_global_id(rir)[1])

        fields = ['family', 'prefix', 'date_added', 'description']
        return NewAggregate(aggregate=set_and_save(fields, input, temp))
Ejemplo n.º 4
0
    def setUp(self):
        user = create_test_user(permissions=['ipam.view_aggregate'])
        self.client = Client()
        self.client.force_login(user)

        rir = RIR(name='RIR 1', slug='rir-1')
        rir.save()

        Aggregate.objects.bulk_create([
            Aggregate(family=4, prefix=IPNetwork('10.1.0.0/16'), rir=rir),
            Aggregate(family=4, prefix=IPNetwork('10.2.0.0/16'), rir=rir),
            Aggregate(family=4, prefix=IPNetwork('10.3.0.0/16'), rir=rir),
        ])
Ejemplo n.º 5
0
    def setUpTestData(cls):

        rirs = (
            RIR(name='RIR 1', slug='rir-1'),
            RIR(name='RIR 2', slug='rir-2'),
            RIR(name='RIR 3', slug='rir-3'),
        )
        RIR.objects.bulk_create(rirs)

        aggregates = (
            Aggregate(prefix='10.1.0.0/16',
                      rir=rirs[0],
                      date_added='2020-01-01'),
            Aggregate(prefix='10.2.0.0/16',
                      rir=rirs[0],
                      date_added='2020-01-02'),
            Aggregate(prefix='10.3.0.0/16',
                      rir=rirs[1],
                      date_added='2020-01-03'),
            Aggregate(prefix='2001:db8:1::/48',
                      rir=rirs[1],
                      date_added='2020-01-04'),
            Aggregate(prefix='2001:db8:2::/48',
                      rir=rirs[2],
                      date_added='2020-01-05'),
            Aggregate(prefix='2001:db8:3::/48',
                      rir=rirs[2],
                      date_added='2020-01-06'),
        )
        Aggregate.objects.bulk_create(aggregates)
Ejemplo n.º 6
0
    def setUpTestData(cls):

        rirs = (
            RIR(name='RIR 1', slug='rir-1'),
            RIR(name='RIR 2', slug='rir-2'),
            RIR(name='RIR 3', slug='rir-3'),
        )
        RIR.objects.bulk_create(rirs)

        tenant_groups = (
            TenantGroup(name='Tenant group 1', slug='tenant-group-1'),
            TenantGroup(name='Tenant group 2', slug='tenant-group-2'),
            TenantGroup(name='Tenant group 3', slug='tenant-group-3'),
        )
        for tenantgroup in tenant_groups:
            tenantgroup.save()

        tenants = (
            Tenant(name='Tenant 1', slug='tenant-1', group=tenant_groups[0]),
            Tenant(name='Tenant 2', slug='tenant-2', group=tenant_groups[1]),
            Tenant(name='Tenant 3', slug='tenant-3', group=tenant_groups[2]),
        )
        Tenant.objects.bulk_create(tenants)

        aggregates = (
            Aggregate(prefix='10.1.0.0/16',
                      rir=rirs[0],
                      tenant=tenants[0],
                      date_added='2020-01-01'),
            Aggregate(prefix='10.2.0.0/16',
                      rir=rirs[0],
                      tenant=tenants[1],
                      date_added='2020-01-02'),
            Aggregate(prefix='10.3.0.0/16',
                      rir=rirs[1],
                      tenant=tenants[2],
                      date_added='2020-01-03'),
            Aggregate(prefix='2001:db8:1::/48',
                      rir=rirs[1],
                      tenant=tenants[0],
                      date_added='2020-01-04'),
            Aggregate(prefix='2001:db8:2::/48',
                      rir=rirs[2],
                      tenant=tenants[1],
                      date_added='2020-01-05'),
            Aggregate(prefix='2001:db8:3::/48',
                      rir=rirs[2],
                      tenant=tenants[2],
                      date_added='2020-01-06'),
        )
        Aggregate.objects.bulk_create(aggregates)
Ejemplo n.º 7
0
    def test_get_utilization(self):
        rir = RIR.objects.create(name='RIR 1', slug='rir-1')
        aggregate = Aggregate(prefix=netaddr.IPNetwork('10.0.0.0/8'), rir=rir)
        aggregate.save()

        # 25% utilization
        Prefix.objects.bulk_create((
            Prefix(prefix=netaddr.IPNetwork('10.0.0.0/12')),
            Prefix(prefix=netaddr.IPNetwork('10.16.0.0/12')),
            Prefix(prefix=netaddr.IPNetwork('10.32.0.0/12')),
            Prefix(prefix=netaddr.IPNetwork('10.48.0.0/12')),
        ))
        self.assertEqual(aggregate.get_utilization(), 25)

        # 50% utilization
        Prefix.objects.bulk_create(
            (Prefix(prefix=netaddr.IPNetwork('10.64.0.0/10')), ))
        self.assertEqual(aggregate.get_utilization(), 50)

        # 100% utilization
        Prefix.objects.bulk_create(
            (Prefix(prefix=netaddr.IPNetwork('10.128.0.0/9')), ))
        self.assertEqual(aggregate.get_utilization(), 100)