Exemple #1
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; }"""
        )
Exemple #2
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; }")
    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; }"""
        )
Exemple #4
0
 def perform_move(self, address, new_ip, new_hostname):
     old_ipaddress = IPAddress.objects.get(address=address)
     device = old_ipaddress.device
     mac = None
     for r in Record.objects.filter(
             db.Q(name=old_ipaddress.hostname) |
             db.Q(content=old_ipaddress.hostname) |
             db.Q(content=old_ipaddress.address)
         ):
         r.delete()
     for e in DHCPEntry.objects.filter(ip=old_ipaddress.address):
         mac = e.mac
         e.delete()
     old_ipaddress.device = None
     old_ipaddress.save()
     reset_dns(new_hostname, new_ip)
     new_ipaddress, c = IPAddress.concurrent_get_or_create(
             address=new_ip,
         )
     new_ipaddress.device = device
     new_ipaddress.hostname = new_hostname
     new_ipaddress.save()
     if mac:
         entry = DHCPEntry(ip=new_ip, mac=mac)
         entry.save()
     pricing.device_update_cached(device)
Exemple #5
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; }')
Exemple #6
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; }")
Exemple #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, "")
Exemple #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; }')
Exemple #9
0
def _dhcp_create_record(form, request, device):
    ip = form.cleaned_data.get('dhcp_new_ip')
    mac = form.cleaned_data.get('dhcp_new_mac')
    if ip and mac:
        if DHCPEntry.objects.filter(ip=ip).exists():
            messages.warning(request,
                             "A DHCP record for %s already exists." % ip)
        if DHCPEntry.objects.filter(mac=mac).exists():
            messages.warning(request,
                             "A DHCP record for %s already exists." % mac)
        record = DHCPEntry(mac=mac, ip=ip)
        record.save()
        messages.success(request,
                         "A DHCP record for %s and %s added." % (ip, mac))
Exemple #10
0
 def handle(self, filename, *args, **options):
     data = iscconf.parse(open(filename, 'r').read())
     for key, info in data.iteritems():
         if not key[0] == 'host':
             continue
         mac = MACAddressField.normalize(info[('hardware', 'ethernet')])
         for entry in DHCPEntry.objects.filter(mac=mac):
             entry.delete()
         addresses = info[('fixed-address',)]
         if not isinstance(addresses, list):
             addresses = [addresses]
         for address in addresses:
             print('Importing %s = %s' % (address, mac))
             entry = DHCPEntry(ip=address.strip(), mac=mac)
             entry.save()
 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; }'
     )
Exemple #12
0
 def handle(self, filename, *args, **options):
     data = iscconf.parse(open(filename, 'r').read())
     for key, info in data.iteritems():
         if not key[0] == 'host':
             continue
         mac = MACAddressField.normalize(info[('hardware', 'ethernet')])
         for entry in DHCPEntry.objects.filter(mac=mac):
             entry.delete()
         addresses = info[('fixed-address', )]
         if not isinstance(addresses, list):
             addresses = [addresses]
         for address in addresses:
             print('Importing %s = %s' % (address, mac))
             entry = DHCPEntry(ip=address.strip(), mac=mac)
             entry.save()
 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,
         '',
     )
Exemple #14
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,
         '',
     )
Exemple #15
0
def _dhcp_create_record(form, request, device):
    ip = form.cleaned_data.get('dhcp_new_ip')
    mac = form.cleaned_data.get('dhcp_new_mac')
    if ip and mac:
        if DHCPEntry.objects.filter(ip=ip).exists():
            messages.warning(request,
                             "A DHCP record for %s already exists."
                             % ip)
        if DHCPEntry.objects.filter(mac=mac).exists():
            messages.warning(request,
                             "A DHCP record for %s already exists."
                             % mac)
        record = DHCPEntry(mac=mac, ip=ip)
        record.save()
        messages.success(request,
                         "A DHCP record for %s and %s added." %
                         (ip, mac))
Exemple #16
0
def reset_dhcp(ip, mac):
    mac = MACAddressField.normalize(mac)
    ip = str(ip).strip().strip('.')
    entry = DHCPEntry(ip=ip, mac=mac)
    entry.save()
Exemple #17
0
def reset_dhcp(ip, mac):
    mac = MACAddressField.normalize(mac)
    ip = str(ip).strip().strip('.')
    entry = DHCPEntry(ip=ip, mac=mac)
    entry.save()