###############################################################################
import database
+import errors
+import sqlite3
DB = "/var/lib/pdns/pdns.db"
# Create the primary DNS class.
class DNS(object):
-"""
-Primary DNS class.
+ """
+ Primary DNS class.
-Uses the database class from imported database module.
-Connects to the PDNS sqlite database.
-"""
+ Uses the database class from imported database module.
+ Connects to the PDNS sqlite database.
+ """
def __init__(self, db):
- self.db = database.Database(db)
+ # Try to connect to database or raise an exception.
+ try:
+ self.db = database.Database(db)
+
+ except sqlite3.OperationalError, e:
+ raise errors.DatabaseException, "Could not open database: %s" % e
+
+
# Get all configured domains.
def get_domains(self):
# Create Domain class.
class Domain(object):
-"""
-Domain class.
+ """
+ Domain class.
-Uses query method from database module to get requested information from domain.
-The domain is specified by it's unique database id.
-"""
+ Uses query method from database module to get requested information from domain.
+ The domain is specified by it's unique database id.
+ """
def __init__(self, dns, domain_id):
self.dns = dns
self.id = domain_id
# Create class for domain records.
class Record(object):
-"""
-Record class
+ """
+ Record class
-It is used to get details about configured records.
-The domain and record is's are specified by their unique database id's.
-"""
+ It is used to get details about configured records.
+ The domain and record is's are specified by their unique database id's.
+ """
def __init__(self, domain, record_id):
self.domain = domain
self.id = record_id
# Create an own class to deal with "SOA" records.
class SOARecord(Record):
-"""
-SOA Record class.
-This is an own class to deal with "SOA" records.
+ """
+ SOA Record class.
+ This is an own class to deal with "SOA" records.
-Uses splitt() to generate a list of the content string from the database.
-Returns the requested entries.
-"""
+ Uses splitt() to generate a list of the content string from the database.
+ Returns the requested entries.
+ """
def __init__(self, domain, record_id):
Record.__init__(self, domain, record_id)
# Check if the content from database is valid (It contains all 7 required information).
if not len(self.soa_attrs) == 7:
- #XXX Add something like an error message or log output.
- pass
+ raise InvalidRecordDataException, "Your SOA record \
+ doesn't contain all required seven elements."
# Primary NS - the domain name of the name server that was the original source of the data.
@property
class ARecord(Record):
pass
-
--- /dev/null
+###############################################################################
+# #
+# pyPDNS - A PDNS administration tool, written in pure python. #
+# Copyright (C) 2012 IPFire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+class DatabaseException(Exception):
+ """
+ Exception if the database doesn't exist.
+ """
+ pass
+
+
+class DomainNotFoundException(Exception):
+ """
+ Exception if an invalid domain has been specified.
+ """
+ pass
+
+
+class RecordNotFoundException(Exception):
+ """
+ Exception if an invalid record has been specified.
+ """
+ pass
+
+
+class InvalidRecordDataException(Exception):
+ """
+ Exception if a record contains invalid data.
+ """
+ pass