def update_record(self, context, domain_id, record_id, values, increment_serial=True): domain = self.storage.get_domain(context, domain_id) record = self.storage.get_record(context, record_id) # Ensure the domain_id matches the record's domain_id if domain['id'] != record['domain_id']: raise exceptions.RecordNotFound() target = { 'domain_id': domain_id, 'domain_name': domain['name'], 'record_id': record['id'], 'tenant_id': domain['tenant_id'] } policy.check('update_record', context, target) # Ensure the record name is valid record_name = values['name'] if 'name' in values else record['name'] record_type = values['type'] if 'type' in values else record['type'] self._is_valid_record_name(context, domain, record_name, record_type) # Update the record record = self.storage.update_record(context, record_id, values) try: self.backend.update_record(context, domain, record) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def delete_record(self, context, domain_id, record_id, increment_serial=True): domain = self.storage.get_domain(context, domain_id) record = self.storage.get_record(context, record_id) # Ensure the domain_id matches the record's domain_id if domain['id'] != record['domain_id']: raise exceptions.RecordNotFound() target = { 'domain_id': domain_id, 'domain_name': domain['name'], 'record_id': record['id'], 'tenant_id': domain['tenant_id'] } policy.check('delete_record', context, target) try: self.backend.delete_record(context, domain, record) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def create_record(self, context, domain_id, values, increment_serial=True): domain = self.storage.get_domain(context, domain_id) target = { 'domain_id': domain_id, 'domain_name': domain['name'], 'record_name': values['name'], 'tenant_id': domain['tenant_id'] } policy.check('create_record', context, target) # Ensure the tenant has enough quota to continue quota_criterion = {'domain_id': domain_id} record_count = self.storage.count_records(context, criterion=quota_criterion) self.quota.limit_check(context, domain['tenant_id'], domain_records=record_count) # Ensure the record name is valid self._is_valid_record_name(context, domain, values['name'], values['type']) record = self.storage.create_record(context, domain_id, values) try: self.backend.create_record(context, domain, record) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def create_domain(self, context, values): values['tenant_id'] = context.tenant_id target = { 'tenant_id': values['tenant_id'], 'domain_name': values['name'] } policy.check('create_domain', context, target) # Ensure the tenant has enough quota to continue quota_criterion = {'tenant_id': values['tenant_id']} domain_count = self.storage.count_domains(context, criterion=quota_criterion) self.quota.limit_check(context, values['tenant_id'], domains=domain_count) # Ensure the domain name is valid self._is_valid_domain_name(context, values['name']) # Handle sub-domains appropriately parent_domain = self._is_subdomain(context, values['name']) if parent_domain: if parent_domain['tenant_id'] == values['tenant_id']: # Record the Parent Domain ID values['parent_domain_id'] = parent_domain['id'] else: raise exceptions.Forbidden('Unable to create subdomain in ' 'another tenants domain') # TODO(kiall): Handle super-domains properly # NOTE(kiall): Fetch the servers before creating the domain, this way # we can prevent domain creation if no servers are # configured. servers = self.storage.get_servers(context) if len(servers) == 0: LOG.critical('No servers configured. Please create at least one ' 'server') raise exceptions.NoServersConfigured() # Set the serial number values['serial'] = utils.increment_serial() domain = self.storage.create_domain(context, values) try: self.backend.create_domain(context, domain) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def delete_tsigkey(self, context, tsigkey_id): policy.check('delete_tsigkey', context, {'tsigkey_id': tsigkey_id}) tsigkey = self.storage.get_tsigkey(context, tsigkey_id) try: self.backend.delete_tsigkey(context, tsigkey) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def create_tsigkey(self, context, values): policy.check('create_tsigkey', context) tsigkey = self.storage.create_tsigkey(context, values) try: self.backend.create_tsigkey(context, tsigkey) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def _increment_domain_serial(self, context, domain_id): domain = self.storage.get_domain(context, domain_id) # Increment the serial number values = {'serial': utils.increment_serial(domain['serial'])} domain = self.storage.update_domain(context, domain_id, values) try: self.backend.update_domain(context, domain) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def delete_domain(self, context, domain_id): domain = self.storage.get_domain(context, domain_id) target = { 'domain_id': domain_id, 'domain_name': domain['name'], 'tenant_id': domain['tenant_id'] } policy.check('delete_domain', context, target) try: self.backend.delete_domain(context, domain) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)
def update_domain(self, context, domain_id, values, increment_serial=True): domain = self.storage.get_domain(context, domain_id) target = { 'domain_id': domain_id, 'domain_name': domain['name'], 'tenant_id': domain['tenant_id'] } policy.check('update_domain', context, target) if 'tenant_id' in values: # NOTE(kiall): Ensure the user is allowed to delete a domain from # the original tenant. policy.check('delete_domain', context, target) # NOTE(kiall): Ensure the user is allowed to create a domain in # the new tenant. target = {'domain_id': domain_id, 'tenant_id': values['tenant_id']} policy.check('create_domain', context, target) if 'name' in values and values['name'] != domain['name']: raise exceptions.BadRequest('Renaming a domain is not allowed') if increment_serial: # Increment the serial number values['serial'] = utils.increment_serial(domain['serial']) domain = self.storage.update_domain(context, domain_id, values) try: self.backend.update_domain(context, domain) except exceptions.Backend: # Re-raise Backend exceptions as is.. raise except Exception, e: raise exceptions.Backend('Unknown backend failure: %s' % e)