def zone_available_check(zone, profile): zone_name = Zone.from_display_name(zone) parent_zone = Zone.find(zone_name + '.') if parent_zone is not None and zone_name == parent_zone.name: raise AlreadyExistsError("%s %s already exists" % (ZONE_OBJ_NAME[int( parent_zone.profile)], Zone.to_display_name(zone_name))) return parent_zone
def get_zone(name, profile): zone_name = Zone.to_display_name(name) name = Zone.from_display_name(name).lower() q = Zone.query.filter_by(name=name, profile=profile) zone = q.first() if zone is None: raise InvalidZoneError("%s %s does not exist" % (ZONE_OBJ_NAME[int(profile)], zone_name)) return zone
def get_rr_zone(name, zone, profile, notfound_message=True): if zone is None: if not name.endswith('.'): raise InvalidParameterError('Name must be a FQDN') zone = Zone.find(name) if zone is None: if notfound_message: Messages.info('No zone found for %s' % name) return None else: zone = get_zone(zone, profile) if name.endswith('.') and (not name.endswith('.' + zone.name + '.') and name != zone.name + '.'): raise InvalidParameterError('RR name %s not in zone %s' % (name, zone.name)) return zone