Example #1
0
 def test_basic_entry(self):
     entry = DHCPEntry(ip="127.0.0.1", mac="deadbeefcafe")
     entry.save()
     config = generate_dhcp_config()
     # remove first line with the date and last line
     config = "\n".join(config.splitlines()[1:-1])
     self.assertEqual(config, "host 127.0.0.1 { fixed-address 127.0.0.1; " "hardware ethernet DE:AD:BE:EF:CA:FE; }")
Example #2
0
    def test_network_config_entry(self):
        dc = DataCenter(name='dc1')
        dc.save()
        net = Network(
            name='net',
            address='127.0.0.0/24',
            data_center=dc,
            dhcp_config='ziew',
        )
        net.save()
        entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
        entry.save()
        config = generate_dhcp_config(dc=dc, with_networks=True)
        # remove first line with the date and last line
        config = '\n'.join(config.splitlines()[1:-1])
        self.assertEqual(
            config, """\
shared-network "net" {
    subnet 127.0.0.0 netmask 255.255.255.0 {
ziew
    }
}

host 127.0.0.1 { fixed-address 127.0.0.1; hardware ethernet DE:AD:BE:EF:CA:FE; }"""
        )
    def test_network_config_entry(self):
        dc = DataCenter(name='dc1')
        dc.save()
        net = Network(
            name='net',
            address='127.0.0.0/24',
            data_center=dc,
            dhcp_config='ziew',
        )
        net.save()
        entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
        entry.save()
        config = generate_dhcp_config(dc=dc, with_networks=True)
        # remove first line with the date and last line
        config = '\n'.join(config.splitlines()[1:-1])
        self.assertEqual(
            config,
            """\
shared-network "net" {
    subnet 127.0.0.0 netmask 255.255.255.0 {
ziew
    }
}

host 127.0.0.1 { fixed-address 127.0.0.1; hardware ethernet DE:AD:BE:EF:CA:FE; }"""
        )
Example #4
0
 def test_basic_entry(self):
     entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
     entry.save()
     config = generate_dhcp_config()
     # remove first line with the date and last line
     config = '\n'.join(config.splitlines()[1:-1])
     self.assertEqual(
         config, 'host 127.0.0.1 { fixed-address 127.0.0.1; '
         'hardware ethernet DE:AD:BE:EF:CA:FE; }')
Example #5
0
 def test_datacenter_entry(self):
     dc = DataCenter(name="dc1")
     dc.save()
     net = Network(name="net", address="127.0.0.0/24", data_center=dc)
     net.save()
     entry = DHCPEntry(ip="127.0.0.1", mac="deadbeefcafe")
     entry.save()
     config = generate_dhcp_config(dc=dc)
     # remove first line with the date and last line
     config = "\n".join(config.splitlines()[1:-1])
     self.assertEqual(config, "host 127.0.0.1 { fixed-address 127.0.0.1; " "hardware ethernet DE:AD:BE:EF:CA:FE; }")
Example #6
0
def dhcp_config(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    if request.GET.get('dc'):
        dc = DataCenter.objects.get(name__iexact=request.GET['dc'])
    else:
        dc = None
    address = remote_addr(request)
    return HttpResponse(
        generate_dhcp_config(dc=dc, server_address=address),
        content_type="text/plain",
    )
Example #7
0
 def test_other_datacenter_entry(self):
     dc = DataCenter(name="dc1")
     dc.save()
     dc2 = DataCenter(name="dc2")
     dc2.save()
     net = Network(name="net", address="127.0.0.0/24", data_center=dc)
     net.save()
     entry = DHCPEntry(ip="127.0.0.1", mac="deadbeefcafe")
     entry.save()
     config = generate_dhcp_config(dc=dc2)
     # remove first line with the date and last line
     config = "\n".join(config.splitlines()[1:-1])
     self.assertEqual(config, "")
Example #8
0
 def test_datacenter_entry(self):
     dc = DataCenter(name='dc1')
     dc.save()
     net = Network(name='net', address='127.0.0.0/24', data_center=dc)
     net.save()
     entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
     entry.save()
     config = generate_dhcp_config(dc=dc)
     # remove first line with the date and last line
     config = '\n'.join(config.splitlines()[1:-1])
     self.assertEqual(
         config, 'host 127.0.0.1 { fixed-address 127.0.0.1; '
         'hardware ethernet DE:AD:BE:EF:CA:FE; }')
 def test_datacenter_entry(self):
     dc = DataCenter(name='dc1')
     dc.save()
     net = Network(name='net', address='127.0.0.0/24', data_center=dc)
     net.save()
     entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
     entry.save()
     config = generate_dhcp_config(dc=dc)
     # remove first line with the date and last line
     config = '\n'.join(config.splitlines()[1:-1])
     self.assertEqual(
         config,
         'host 127.0.0.1 { fixed-address 127.0.0.1; '
         'hardware ethernet DE:AD:BE:EF:CA:FE; }'
     )
Example #10
0
 def test_other_datacenter_entry(self):
     dc = DataCenter(name='dc1')
     dc.save()
     dc2 = DataCenter(name='dc2')
     dc2.save()
     net = Network(name='net', address='127.0.0.0/24', data_center=dc)
     net.save()
     entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
     entry.save()
     config = generate_dhcp_config(dc=dc2)
     # remove first line with the date and last line
     config = '\n'.join(config.splitlines()[1:-1])
     self.assertEqual(
         config,
         '',
     )
Example #11
0
 def test_other_datacenter_entry(self):
     dc = DataCenter(name='dc1')
     dc.save()
     dc2 = DataCenter(name='dc2')
     dc2.save()
     net = Network(name='net', address='127.0.0.0/24', data_center=dc)
     net.save()
     entry = DHCPEntry(ip='127.0.0.1', mac='deadbeefcafe')
     entry.save()
     config = generate_dhcp_config(dc=dc2)
     # remove first line with the date and last line
     config = '\n'.join(config.splitlines()[1:-1])
     self.assertEqual(
         config,
         '',
     )
Example #12
0
def dhcp_config(request):
    if not api.is_authenticated(request):
        return HttpResponseForbidden('API key required.')
    if request.GET.get('dc'):
        dc = DataCenter.objects.get(name__iexact=request.GET['dc'])
    else:
        dc = None
    with_networks = bool(request.GET.get('with_networks', False))
    address = remote_addr(request)
    return HttpResponse(
        generate_dhcp_config(
            dc=dc,
            server_address=address,
            with_networks=with_networks,
        ),
        content_type="text/plain",
    )
Example #13
0
 def handle(self, server_address=None, *args, **options):
     # Avoid an import loop
     from ralph.dnsedit.dhcp_conf import generate_dhcp_config
     print(generate_dhcp_config(server_address=server_address))
Example #14
0
 def handle(self, server_address=None, *args, **options):
     # Avoid an import loop
     from ralph.dnsedit.dhcp_conf import generate_dhcp_config
     print(generate_dhcp_config(server_address=server_address))