コード例 #1
0
ファイル: domain.py プロジェクト: ajeetraina/maas
 def update_dnsdata(self, params):
     domain = self._get_domain_or_permission_error(params)
     dnsdata = DNSData.objects.get(id=params['dnsdata_id'],
                                   dnsresource_id=params['dnsresource_id'])
     form = DNSDataForm(data=params, instance=dnsdata)
     if form.is_valid():
         form.save()
     else:
         raise ValidationError(form.errors)
     return self.full_dehydrate(domain)
コード例 #2
0
ファイル: domain.py プロジェクト: ajeetraina/maas
 def create_dnsdata(self, params):
     domain = self._get_domain_or_permission_error(params)
     dnsresource, _ = DNSResource.objects.get_or_create(domain=domain,
                                                        name=params['name'])
     params['dnsresource'] = dnsresource.id
     form = DNSDataForm(data=params)
     if form.is_valid():
         form.save()
     else:
         raise ValidationError(form.errors)
コード例 #3
0
 def test_accepts_ttl_equal_none(self):
     name = factory.make_name("dnsdata")
     (rrtype, rrdata) = factory.pick_rrset()
     dnsrr = factory.make_DNSResource(no_ip_addresses=True)
     ttl = random.randint(1, 10000)
     form = DNSDataForm({
         "name": name,
         "dnsresource": dnsrr.id,
         "ttl": ttl,
         "rrtype": rrtype,
         "rrdata": rrdata,
     })
     self.assertTrue(form.is_valid(), form.errors)
     dnsdata = form.save()
     form = DNSDataForm(instance=dnsdata, data={"ttl": None})
     self.assertTrue(form.is_valid(), form.errors)
     dnsdata = form.save()
     self.assertEqual(dnsrr.id, dnsdata.dnsresource.id)
     self.assertEqual(rrtype, dnsdata.rrtype)
     self.assertEqual(rrdata, dnsdata.rrdata)
     self.assertEqual(None, dnsdata.ttl)
コード例 #4
0
 def test__creates_dnsdata(self):
     name = factory.make_name("dnsdata")
     (rrtype, rrdata) = factory.pick_rrset()
     dnsrr = factory.make_DNSResource(no_ip_addresses=True)
     form = DNSDataForm({
         "name": name,
         "dnsresource": dnsrr.id,
         "rrtype": rrtype,
         "rrdata": rrdata,
     })
     self.assertTrue(form.is_valid(), form.errors)
     dnsdata = form.save()
     self.assertEqual(dnsrr.id, dnsdata.dnsresource.id)
     self.assertEqual(rrtype, dnsdata.rrtype)
     self.assertEqual(rrdata, dnsdata.rrdata)
コード例 #5
0
ファイル: test_dnsdata.py プロジェクト: zhangrb/maas
 def test__updates_dnsdata(self):
     dnsdata = factory.make_DNSData()
     (rrtype, rrdata) = factory.pick_rrset()
     new_ttl = random.randint(1, 1000)
     form = DNSDataForm(instance=dnsdata,
                        data={
                            "rrtype": rrtype,
                            "rrdata": rrdata,
                            "ttl": new_ttl,
                        })
     self.assertTrue(form.is_valid(), form.errors)
     form.save()
     dnsdata = reload_object(dnsdata)
     self.assertEqual(rrtype, dnsdata.rrtype)
     self.assertEqual(rrdata, dnsdata.rrdata)
     self.assertEqual(new_ttl, dnsdata.ttl)
コード例 #6
0
ファイル: dnsresourcerecords.py プロジェクト: karp773/maas
    def update(self, request, id):
        """Update dnsresourcerecord.

        :param rrtype: Resource Type
        :param rrdata: Resource Data (everything to the right of Type.)

        Returns 403 if the user does not have permission to update the
        dnsresourcerecord.
        Returns 404 if the dnsresourcerecord is not found.
        """
        dnsdata = DNSData.objects.get_dnsdata_or_404(id, request.user,
                                                     NodePermission.admin)
        data = request.data.copy()
        data['dnsresource'] = dnsdata.dnsresource.id
        form = DNSDataForm(instance=dnsdata, data=data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
コード例 #7
0
    def update(self, request, id):
        """@description-title Update a DNS resource record
        @description Update a DNS resource record with the given id.

        @param (int) "{id}" [required=true] The DNS resource record id.

        @param (string) "rrtype" [required=false] Resource type.

        @param (string) "rrdata" [required=false] Resource data (everything to
        the right of type.)

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the updated DNS
        resource record object.
        @success-example "success-json" [exkey=dnsresourcerecords-update]
        placeholder text

        @error (http-status-code) "403" 403
        @error (content) "no-perms" The user does not have permission to update
        the requested DNS resource record.

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested DNS resource record is not
        found.
        @error-example "not-found"
            Not Found
        """
        dnsdata = DNSData.objects.get_dnsdata_or_404(
            id, request.user, NodePermission.admin
        )
        data = request.data.copy()
        data["dnsresource"] = dnsdata.dnsresource.id
        form = DNSDataForm(instance=dnsdata, data=data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
コード例 #8
0
 def test__doesnt_require_name_on_update(self):
     dnsdata = factory.make_DNSData()
     form = DNSDataForm(instance=dnsdata, data={})
     self.assertTrue(form.is_valid(), form.errors)