예제 #1
0
 def _find(self):
     try:
         return self.__find_util
     except AttributeError:
         from Cerebrum.modules.dns import Utils
         self.__find_util = Utils.Find(self.db, self.default_zone)
         return self.__find_util
예제 #2
0
파일: Subnet.py 프로젝트: chrnux/cerebrum
 def _find(self):
     try:
         return self.__find_util
     except AttributeError:
         # Circular dependencies are bad, m'kay
         from Cerebrum.modules.dns import Utils
         self.__find_util = Utils.Find(self.db, self.default_zone)
         return self.__find_util
예제 #3
0
 def __init__(self, db, logger, default_zone):
     self.logger = logger
     self.db = db
     self.const = Factory.get('Constants')(self.db)
     # TBD: This pre-allocating may interfere with multi-threaded bofhd
     self._arecord = ARecord.ARecord(self.db)
     self._aaaarecord = AAAARecord.AAAARecord(self.db)
     self._host = HostInfo.HostInfo(self.db)
     self._dns_owner = DnsOwner.DnsOwner(self.db)
     self._ip_number = IPNumber.IPNumber(self.db)
     self._ipv6_number = IPv6Number.IPv6Number(self.db)
     self._cname = CNameRecord.CNameRecord(self.db)
     self._validator = IntegrityHelper.Validator(self.db, default_zone)
     self._update_helper = IntegrityHelper.Updater(self.db)
     self._mx_set = DnsOwner.MXSet(self.db)
     self.default_zone = default_zone
     self._find = Utils.Find(self.db, default_zone)
     self._parser = Utils.DnsParser(self.db, default_zone)
예제 #4
0
    def _populate_dnsowner(self, hostname):
        """Create or update a DnsOwner connected to the given project.

        The DnsOwner is given a trait, to affiliate it with this project-OU.

        This should rather be put in the DNS module, but due to its complexity,
        its weird layout, and my lack of IQ points to understand it, I started
        just using its API instead.

        :param str hostname: The given *FQDN* for the host.

        :rtype: DnsOwner object
        :return:
            The DnsOwner object that is created or updated.
        """
        dns_owner = DnsOwner.DnsOwner(self._db)
        dnsfind = Utils.Find(self._db, cereconf.DNS_DEFAULT_ZONE)
        ipv6number = IPv6Number.IPv6Number(self._db)
        aaaarecord = AAAARecord.AAAARecord(self._db)
        ipnumber = IPNumber.IPNumber(self._db)
        arecord = ARecord.ARecord(self._db)

        try:
            dns_owner.find_by_name(hostname)
        except Errors.NotFoundError:
            # TODO: create owner here?
            dns_owner.populate(self.const.DnsZone(cereconf.DNS_DEFAULT_ZONE),
                               hostname)
            dns_owner.write_db()
        # Affiliate with project:
        dns_owner.populate_trait(self.const.trait_project_host,
                                 target_id=self.entity_id)
        dns_owner.write_db()
        for (subnets, ipnum, record, ipstr) in (
                (self.ipv6_subnets, ipv6number, aaaarecord, "IPv6"),
                (self.ipv4_subnets, ipnumber, arecord, "IPv4")):
            # TODO: check if dnsowner already has an ip address.
            try:
                ip = dnsfind.find_free_ip(subnets.next(), no_of_addrs=1)[0]
            except StopIteration:
                raise Errors.NotFoundError("No %s-subnet for project %s" %
                                           (ipstr, self.get_project_id()))
            ipnum.populate(ip)
            ipnum.write_db()
            record.populate(dns_owner.entity_id, ipnum.entity_id)
            record.write_db()
        return dns_owner
예제 #5
0
    def __init__(self, operator_id):
        """Constructor. Since we are using access control, we need the
        authenticated entity's ID as a parameter.

        """
        self.db = Factory.get('Database')()
        self.db.cl_init(change_program='resource_service')
        self.co = Factory.get('Constants')(self.db)
        self.finder = Utils.Find(self.db, self.default_zone)
        self.subnet = Subnet.Subnet(self.db)
        self.aaaa = AAAARecord.AAAARecord(self.db)
        self.ip = IPv6Number.IPv6Number(self.db)

        # TODO: could we save work by only using a single, shared object of
        # the auth class? It is supposed to be thread safe.
        #self.ba = BofhdAuth(self.db)
        self.operator_id = operator_id
예제 #6
0
 def __init__(self, db, default_zone):
     self._db = db
     self._default_zone = default_zone
     self._find = Utils.Find(self._db, default_zone)
예제 #7
0
 def __init__(self, db):
     self._validator = Validator(db, None)
     self._db = db
     self._find = Utils.Find(self._db, None)
예제 #8
0
"""

# TODO: check if something could be removed from here:
import random, hashlib
import string, pickle
from mx.DateTime import RelativeDateTime, now
import twisted.python.log

import cereconf
from Cerebrum import Errors
from Cerebrum.Utils import Factory
from Cerebrum.modules.dns import Utils, Subnet, AAAARecord, IPv6Number

from Cerebrum.modules.cis import Utils
log = Utils.SimpleLogger()


class ResourceService(object):
    """The functionality for the Resource service.

    Note that this main class should be independent of what server we use. It is
    important that each thread gets its own instance of this class, to avoid
    race conditions.

    Another thing to remember is that database connections should be closed.
    This is to avoid having old and idle database connections, as the garbage
    collector can't destroy the instances, due to twisted's reuse of threads.

    """
    # The default DNS zone to use:
 def _find(self):
     try:
         return self.__find_util
     except AttributeError:
         self.__find_util = Utils.Find(self.db, self.default_zone)
         return self.__find_util