示例#1
0
    def save(self):
        for view in self.getRecordViews():
            nsupobj = nsupdate.NSUpdate('127.0.0.1',
                                        str(self.domain),
                                        view=view)
            #['foo', 3600, 'IN', 'A', ['192.168.1.1', '172.16.1.1']]#record style
            add_data = [
                [
                    self.record,
                    int(self.ttl), self.rdclass,
                    str(self.rdtype), [
                        self.ip,
                    ]
                ],
            ]
            if self.id != None:
                old_r = Record.objects.get(id=self.id)
                del_data = [
                    [
                        old_r.record,
                        int(old_r.ttl), old_r.rdclass,
                        str(old_r.rdtype), [
                            old_r.ip,
                        ]
                    ],
                ]
                nsupobj.removeRecord(del_data)

            nsupobj.addRecord(add_data)
            nsupobj.commitChanges()

        super(Record, self).save()
示例#2
0
 def test_removeRecord(self):
     self._initnamedconf()
     recordlist = [['foo', 3600, 'IN', 'A', ['192.168.1.1', '172.16.1.1']],
                   ['bar', 3600, 'IN', 'CNAME', ['foo']],
                   ['', 86400, 'IN', 'MX', ['10 foo']]]
     nsupobj = nsupdate.NSUpdate('127.0.0.1', 'example.com.', view='hdview')
     nsupobj.addRecord(recordlist)
     nsupobj.commitChanges()
     recordlist = [['', 86400, 'IN', 'MX', ['10 foo']]]
     nsupobj.removeRecord(recordlist)
     recordlist = ['bar']
     nsupobj.removeRecord(recordlist, True)
     nsupobj.commitChanges()
     record_a = nsupobj.queryRecord('foo.example.com.', rdtype='A')
     record_a.sort()
     self.assertEqual(record_a, ['172.16.1.1', '192.168.1.1'])
     deleted = False
     try:
         record_cname = nsupobj.queryRecord('bar.example.com.',
                                            rdtype='CNAME')
     except nsupdate.NSUpdateException:
         deleted = True
     self.assertTrue(deleted)
     deleted = False
     try:
         record_mx = nsupobj.queryRecord('example.com.', rdtype='MX')
     except nsupdate.NSUpdateException:
         deleted = True
     self.assertTrue(deleted)
示例#3
0
 def test_queryRecord(self):
     self._initnamedconf()
     recordlist = [['foo', 3600, 'IN', 'A', ['192.168.1.1', '172.16.1.1']],
                   ['bar', 3600, 'IN', 'CNAME', ['foo']],
                   ['', 86400, 'IN', 'MX', ['10 foo']]]
     nsupobj = nsupdate.NSUpdate('127.0.0.1', 'example.com.', view='hdview')
     nsupobj.addRecord(recordlist)
     nsupobj.commitChanges()
     record_a = nsupobj.queryRecord('foo.example.com', rdtype='A')
     record_a.sort()
     self.assertEqual(record_a, ['172.16.1.1', '192.168.1.1'])
     record_cname = nsupobj.queryRecord('bar.example.com.', rdtype='CNAME')
     self.assertEqual(record_cname, ['foo.example.com.'])
     record_mx = nsupobj.queryRecord('example.com.', rdtype='MX')
     self.assertEqual(record_mx, ['10 foo.example.com.'])
示例#4
0
    def test_deleteRecord(self):
        self._init_sys()
        nc = NamedConf()
        nc.addAcl('yanxu-any', [
            '127.0.0.1',
        ])
        nc.addView('beijing', [
            'yanxu-any',
        ])
        nc.addView('shanghai', [
            'yanxu-any',
        ])
        log.debug(nc.loadViewKey('beijing'))
        nc.addDomain(['sina.com.cn', 'mail.sina.com.cn'])
        nc.save()
        nc.named_restart()

        self.assertTrue(
            os.path.isfile(os.path.join(sysconf.namedconf,
                                        'view/beijing.conf')))
        self.assertTrue(
            os.path.isfile(
                os.path.join(sysconf.namedconf, 'view/shanghai.conf')))

        record1 = Record.objects.create(domain=self.domain1,
                                        record='www',
                                        ttl='3600',
                                        ip='10.210.132.70',
                                        rdclass='IN',
                                        rdtype=self.rt1,
                                        recordgroup=self.rg1)
        nsupobj = nsupdate.NSUpdate('127.0.0.1',
                                    str(self.domain1),
                                    view='beijing')
        record_result = nsupobj.queryRecord('www.sina.com.cn.', 'A')
        self.assertEqual(record_result, ['10.210.132.70'])

        record2 = Record.objects.get(id=1)
        record2.delete()

        try:
            record_result = nsupobj.queryRecord('www.sina.com.cn.', 'A')
        except nsupdate.NSUpdateException, e:
            self.assertTrue(str(e).find("Name Not Exist") != -1)
示例#5
0
    def delete(self):
        for view in self.getRecordViews():
            nsupobj = nsupdate.NSUpdate('127.0.0.1',
                                        str(self.domain),
                                        view=view)
            del_data = [
                [
                    self.record,
                    int(self.ttl), self.rdclass,
                    str(self.rdtype), [
                        self.ip,
                    ]
                ],
            ]
            #['foo', 3600, 'IN', 'A', ['192.168.1.1', '172.16.1.1']]#record style
            nsupobj.removeRecord(del_data)
            nsupobj.commitChanges()

        super(Record, self).delete()