def _get_host(self, host_id): """Helper method for getting the DnsOwner for the given host ID, which can either be an IP address, an A record or a CName alias.""" finder = Find(self.db, self.default_zone) tmp = host_id.split(".") if host_id.find(":") == -1 and tmp[-1].isdigit(): # host_id is an IP owner_id = finder.find_target_by_parsing(host_id, IP_NUMBER) else: owner_id = finder.find_target_by_parsing(host_id, DNS_OWNER) # Check if it is a Cname, if so: update the owner_id try: cname_record = CNameRecord(self.db) cname_record.find_by_cname_owner_id(owner_id) owner_id = cname_record.target_owner_id except Errors.NotFoundError: pass dns_owner = DnsOwner.DnsOwner(self.db) try: dns_owner.find(owner_id) except Errors.NotFoundError: raise CerebrumError('Unknown host: %s' % host_id) return dns_owner
def _get_host(self, host_id): """Helper method for getting the DnsOwner for the given host ID, which can either be an IP address, an A record or a CName alias.""" finder = Find(self.db, self.default_zone) tmp = host_id.split(".") if host_id.find(":") == -1 and tmp[-1].isdigit(): # host_id is an IP owner_id = finder.find_target_by_parsing(host_id, IP_NUMBER) else: owner_id = finder.find_target_by_parsing(host_id, DNS_OWNER) # Check if it is a Cname, if so: update the owner_id try: cname_record = CNameRecord(self.db) cname_record.find_by_cname_owner_id(owner_id) owner_id = cname_record.target_owner_id except Errors.NotFoundError: pass dns_owner = DnsOwner.DnsOwner(self.db) try: dns_owner.find(owner_id) except Errors.NotFoundError: raise CerebrumError('Unknown host: %r' % host_id) return dns_owner
def add_cname_record(db, cname_record_name, target_name, fail_on_exists=True): """ Creates a CNAME-record. If fail_on_exists=False, it will simply return without doing anything, if the CNAME-record already exists. This is due to the method being used by OU._setup_project_hosts, which can be run several times for the same project when it is reconfigured. :param db: A Cerebrum-database instance :type db: Cerebrum.Database :param cname_record_name: FQDN of the CNAME-record :type cname_record_name: str :param target_name: FQDN of the target domain :type target_name: str :param fail_on_exists: True or False :type fail_on_exists: bool """ cname = CNameRecord(db) dns_owner = DnsOwner(db) constants = Factory.get('Constants') try: dns_owner.find_by_name(target_name) proxy_dns_owner_ref = dns_owner.entity_id except Errors.NotFoundError: raise Errors.NotFoundError('%s does not exist.' % target_name) dns_owner.clear() try: dns_owner.find_by_name(cname_record_name) except Errors.NotFoundError: dns_owner.populate(constants.DnsZone(cereconf.DNS_DEFAULT_ZONE), cname_record_name) dns_owner.write_db() cname_dns_owner_ref = dns_owner.entity_id try: cname.find_by_cname_owner_id(cname_dns_owner_ref) if fail_on_exists: raise Errors.RealityError('CNAME %s already exists.' % cname_record_name) except Errors.NotFoundError: cname.populate(cname_dns_owner_ref, proxy_dns_owner_ref) cname.write_db()
def add_cname_record(db, cname_record_name, target_name, fail_on_exists=True): """ Creates a CNAME-record. If fail_on_exists=False, it will simply return without doing anything, if the CNAME-record already exists. This is due to the method being used by OU._setup_project_hosts, which can be run several times for the same project when it is reconfigured. :param db: A Cerebrum-database instance :type db: Cerebrum.database.Database :param cname_record_name: FQDN of the CNAME-record :type cname_record_name: str :param target_name: FQDN of the target domain :type target_name: str :param fail_on_exists: True or False :type fail_on_exists: bool """ cname = CNameRecord(db) dns_owner = DnsOwner(db) constants = Factory.get('Constants') try: dns_owner.find_by_name(target_name) proxy_dns_owner_ref = dns_owner.entity_id except Errors.NotFoundError: raise Errors.NotFoundError('%s does not exist.' % target_name) dns_owner.clear() try: dns_owner.find_by_name(cname_record_name) except Errors.NotFoundError: dns_owner.populate(constants.DnsZone(cereconf.DNS_DEFAULT_ZONE), cname_record_name) dns_owner.write_db() cname_dns_owner_ref = dns_owner.entity_id try: cname.find_by_cname_owner_id(cname_dns_owner_ref) if fail_on_exists: raise Errors.RealityError('CNAME %s already exists.' % cname_record_name) except Errors.NotFoundError: cname.populate(cname_dns_owner_ref, proxy_dns_owner_ref) cname.write_db()