예제 #1
0
 def add_sreg_ipv4(self, ip):
     sreg = StaticReg(
         label=random_label(), domain=self.domain, ip_str=ip, ip_type='4',
         system=self.s
     )
     sreg.clean()
     sreg.save()
     return sreg
 class Meta:
     always_return_data = True
     queryset = StaticReg.objects.all()
     fields = StaticReg.get_api_fields() + ['views', 'system']
     authorization = Authorization()
     allowed_methods = allowed_methods
     resource_name = 'staticreg'
예제 #3
0
 def test1_no_system(self):
     label = "8888foo"
     domain = self.f_c
     ip_str = "10.0.0.1"
     ip_type = '4'
     r = StaticReg(
         label=label, domain=domain, ip_str=ip_str, ip_type=ip_type,
         system=None
     )
     self.assertRaises(ValidationError, r.save)
 def test1_no_system(self):
     label = "8888foo"
     domain = self.f_c
     ip_str = "188::15:22:33:44:55:66"
     ip_type = '6'
     r = StaticReg(label=label,
                   domain=domain,
                   ip_str=ip_str,
                   ip_type=ip_type,
                   system=None)
     self.assertRaises(ValidationError, r.clean)
 def do_add(self, label, domain, ip_str, system, ip_type='4'):
     r = StaticReg(
         label=label, domain=domain, ip_str=ip_str,
         ip_type=ip_type, system=system
     )
     r.clean()
     r.save()
     return r
def sreg_import(system, blob):
    if 'pk' in blob:
        try:
            sreg = StaticReg.objects.get(pk=blob['pk'])
            return sreg_update(sreg, blob)
        except StaticReg.DoesNotExist:
            raise BadImportData(
                bad_blob=blob,
                msg='Could not find the Static Registration with primary key '
                '{0}.'.format(blob['pk']))
    else:
        recurse_confirm_no_pk(blob)
        sreg = StaticReg(system=system)
        return sreg_update(sreg, blob)
예제 #7
0
 def do_add_sreg(self, label, domain, ip_str, ip_type='4'):
     r = StaticReg(
         label=label, domain=domain, ip_str=ip_str,
         ip_type=ip_type, system=self.n
     )
     r.clean()
     r.save()
     repr(r)
     return r
예제 #8
0
 def add_sreg_ipv4(self, ip):
     sreg = StaticReg(label=random_label(),
                      domain=self.domain,
                      ip_str=ip,
                      ip_type='4',
                      system=self.s)
     sreg.clean()
     sreg.save()
     return sreg
    def test_bad_nameserver_soa_state_case_1_4(self):
        # This is Case 1 ... with StaticRegs's
        reverse_root_domain = create_fake_zone("14.in-addr.arpa", suffix="")
        root_domain = create_fake_zone("asdf14")
        for ns in root_domain.nameserver_set.all():
            ns.delete()

        # At his point we should have a domain at the root of a zone with no
        # other records in it.

        # Let's create a child domain and try to add a record there.
        Domain.objects.create(name="10.14.in-addr.arpa",
                              soa=reverse_root_domain.soa)

        # Adding a record shouldn't be allowed because there is no NS record on
        # the zone's root domain.
        sreg = StaticReg(label="asdf",
                         domain=root_domain,
                         ip_str="14.10.1.1",
                         ip_type="4",
                         system=self.s)
        self.assertRaises(ValidationError, sreg.save)
def _combine(bundle,
             transaction_managed=False,
             rollback=False,
             use_reversion=True):
    """
    Returns one sreg and DHCP output for that SREG.

    If rollback is True the sreg will be created and then rolleback, but before
    the rollback all its HWAdapters will be polled for their DHCP output.
    """
    bundle['errors'] = None
    bundle['old-dhcp-output'] = get_all_dhcp_for_system(bundle['system'])
    sreg = StaticReg(label=bundle['a'].label,
                     domain=bundle['a'].domain,
                     ip_str=bundle['ip'],
                     system=bundle['system'],
                     description='Migrated SREG',
                     ip_type=bundle['a'].ip_type)

    try:
        bundle['new-dhcp-output'] = (
            "<span class='no-dhcp-output'>No new DHCP output</span>")
        view_names = [v.name for v in bundle['a'].views.all()]
        try:
            bundle['a'].delete(check_cname=False, call_prune_tree=False)
        except ValidationError, e:
            rollback = True
            bundle['errors'] = 'Error while deleting the A record.' + str(e)
            return

        try:
            bundle['ptr'].delete()
        except ValidationError, e:
            rollback = True
            bundle['errors'] = 'Error while deleting the PTR record.' + str(e)
            return
    def test_sreg_cname_exists(self):
        # Duplicate test?
        label = "tesafstyfoo"
        data = "wadfakt"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        cn, _ = CNAME.objects.get_or_create(
            label=label, domain=dom, target=data)
        cn.full_clean()
        cn.save()

        sreg = StaticReg(
            label=label, domain=dom, ip_str="10.0.0.2", ip_type='4',
            system=self.s)

        self.assertRaises(ValidationError, sreg.clean)
        cn.label = "differentlabel"
        cn.save()
        sreg.clean()
        sreg.save()
예제 #12
0
 def do_add(self, label, domain, ip_str, ip_type='4'):
     r = StaticReg(
         label=label, domain=domain, ip_str=ip_str, ip_type=ip_type,
         system=self.n
     )
     r.clean()
     r.save()
     r.details()
     r.get_edit_url()
     r.get_delete_url()
     r.get_absolute_url()
     repr(r)
     return r