Exemplo n.º 1
0
    def delete_record(self, context, domain_id, record_id,
                      increment_serial=True):
        domain = self.storage_api.get_domain(context, domain_id)
        record = self.storage_api.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)

        with self.storage_api.delete_record(context, record_id):
            with wrap_backend_call():
                self.backend.delete_record(context, domain, record)

            if increment_serial:
                self._increment_domain_serial(context, domain_id)

        # Send Record deletion notification
        utils.notify(context, 'central', 'record.delete', record)
Exemplo n.º 2
0
    def create_record(self, context, domain_id, values, increment_serial=True):
        domain = self.storage_api.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
        self._enforce_record_quota(context, domain)

        # Ensure the record name and placement is valid
        self._is_valid_record_name(context, domain, values['name'],
                                   values['type'])
        self._is_valid_record_placement(context, domain, values['name'],
                                        values['type'])

        with self.storage_api.create_record(
                context, domain_id, values) as record:
            with wrap_backend_call():
                self.backend.create_record(context, domain, record)

            if increment_serial:
                self._increment_domain_serial(context, domain_id)

        # Send Record creation notification
        utils.notify(context, 'central', 'record.create', record)

        return record
Exemplo n.º 3
0
    def delete_domain(self, context, domain_id):
        domain = self.storage_api.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)

        # Prevent deletion of a zone which has child zones
        criterion = {'parent_domain_id': domain_id}

        if self.storage_api.count_domains(context, criterion) > 0:
            raise exceptions.DomainHasSubdomain('Please delete any subdomains '
                                                'before deleting this domain')

        with self.storage_api.delete_domain(context, domain_id) as domain:
            with wrap_backend_call():
                self.backend.delete_domain(context, domain)

        utils.notify(context, 'central', 'domain.delete', domain)

        return domain
Exemplo n.º 4
0
    def delete_domain(self, context, domain_id):
        domain = self.storage_api.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)

        # Prevent deletion of a zone which has child zones
        criterion = {'parent_domain_id': domain_id}

        if self.storage_api.count_domains(context, criterion) > 0:
            raise exceptions.DomainHasSubdomain('Please delete any subdomains '
                                                'before deleting this domain')

        with self.storage_api.delete_domain(context, domain_id) as domain:
            with wrap_backend_call():
                self.backend.delete_domain(context, domain)

        utils.notify(context, 'central', 'domain.delete', domain)

        return domain
Exemplo n.º 5
0
    def create_record(self, context, domain_id, values, increment_serial=True):
        domain = self.storage_api.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
        self._enforce_record_quota(context, domain)

        # Ensure the record name and placement is valid
        self._is_valid_record_name(context, domain, values['name'],
                                   values['type'])
        self._is_valid_record_placement(context, domain, values['name'],
                                        values['type'])

        with self.storage_api.create_record(context, domain_id,
                                            values) as record:
            with wrap_backend_call():
                self.backend.create_record(context, domain, record)

            if increment_serial:
                self._increment_domain_serial(context, domain_id)

        # Send Record creation notification
        utils.notify(context, 'central', 'record.create', record)

        return record
Exemplo n.º 6
0
    def delete_record(self,
                      context,
                      domain_id,
                      record_id,
                      increment_serial=True):
        domain = self.storage_api.get_domain(context, domain_id)
        record = self.storage_api.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)

        with self.storage_api.delete_record(context, record_id) as record:
            with wrap_backend_call():
                self.backend.delete_record(context, domain, record)

            if increment_serial:
                self._increment_domain_serial(context, domain_id)

        # Send Record deletion notification
        utils.notify(context, 'central', 'record.delete', record)

        return record
Exemplo n.º 7
0
    def delete_tsigkey(self, context, tsigkey_id):
        policy.check('delete_tsigkey', context, {'tsigkey_id': tsigkey_id})

        with self.storage_api.delete_tsigkey(context, tsigkey_id) as tsigkey:
            with wrap_backend_call():
                self.backend.delete_tsigkey(context, tsigkey)

        utils.notify(context, 'central', 'tsigkey.delete', tsigkey)
Exemplo n.º 8
0
    def delete_tsigkey(self, context, tsigkey_id):
        policy.check('delete_tsigkey', context, {'tsigkey_id': tsigkey_id})

        with self.storage_api.delete_tsigkey(context, tsigkey_id) as tsigkey:
            with wrap_backend_call():
                self.backend.delete_tsigkey(context, tsigkey)

        utils.notify(context, 'central', 'tsigkey.delete', tsigkey)
Exemplo n.º 9
0
    def delete_server(self, context, server_id):
        policy.check('delete_server', context, {'server_id': server_id})

        with self.storage_api.delete_server(context, server_id) as server:
            # TODO(kiall): Update backend with the new server..
            pass

        utils.notify(context, 'central', 'server.delete', server)
Exemplo n.º 10
0
    def create_tsigkey(self, context, values):
        policy.check('create_tsigkey', context)

        with self.storage_api.create_tsigkey(context, values) as tsigkey:
            with wrap_backend_call():
                self.backend.create_tsigkey(context, tsigkey)

        utils.notify(context, 'central', 'tsigkey.create', tsigkey)

        return tsigkey
Exemplo n.º 11
0
    def create_tsigkey(self, context, values):
        policy.check('create_tsigkey', context)

        with self.storage_api.create_tsigkey(context, values) as tsigkey:
            with wrap_backend_call():
                self.backend.create_tsigkey(context, tsigkey)

        utils.notify(context, 'central', 'tsigkey.create', tsigkey)

        return tsigkey
Exemplo n.º 12
0
    def create_server(self, context, values):
        policy.check('create_server', context)

        with self.storage_api.create_server(context, values) as server:
            # TODO(kiall): Update backend with the new server..
            pass

        utils.notify(context, 'central', 'server.create', server)

        return server
Exemplo n.º 13
0
    def create_domain(self, context, values):
        # TODO(kiall): Refactor this method into *MUCH* smaller chunks.
        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_api.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_api.find_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()

        with self.storage_api.create_domain(context, values) as domain:
            with wrap_backend_call():
                self.backend.create_domain(context, domain)

        utils.notify(context, 'central', 'domain.create', domain)

        return domain
Exemplo n.º 14
0
    def update_tsigkey(self, context, tsigkey_id, values):
        policy.check('update_tsigkey', context, {'tsigkey_id': tsigkey_id})

        with self.storage_api.update_tsigkey(
                context, tsigkey_id, values) as tsigkey:
            with wrap_backend_call():
                self.backend.update_tsigkey(context, tsigkey)

        utils.notify(context, 'central', 'tsigkey.update', tsigkey)

        return tsigkey
Exemplo n.º 15
0
    def update_server(self, context, server_id, values):
        policy.check('update_server', context, {'server_id': server_id})

        with self.storage_api.update_server(
                context, server_id, values) as server:
            # TODO(kiall): Update backend with the new details..
            pass

        utils.notify(context, 'central', 'server.update', server)

        return server
Exemplo n.º 16
0
    def create_server(self, context, values):
        policy.check('create_server', context)

        with self.storage_api.create_server(context, values) as server:
            # Update backend with the new server..
            with wrap_backend_call():
                self.backend.create_server(context, server)

        utils.notify(context, 'central', 'server.create', server)

        return server
Exemplo n.º 17
0
    def create_server(self, context, values):
        policy.check('create_server', context)

        with self.storage_api.create_server(context, values) as server:
            # Update backend with the new server..
            with wrap_backend_call():
                self.backend.create_server(context, server)

        utils.notify(context, 'central', 'server.create', server)

        return server
Exemplo n.º 18
0
    def update_tsigkey(self, context, tsigkey_id, values):
        policy.check('update_tsigkey', context, {'tsigkey_id': tsigkey_id})

        with self.storage_api.update_tsigkey(context, tsigkey_id,
                                             values) as tsigkey:
            with wrap_backend_call():
                self.backend.update_tsigkey(context, tsigkey)

        utils.notify(context, 'central', 'tsigkey.update', tsigkey)

        return tsigkey
Exemplo n.º 19
0
    def update_server(self, context, server_id, values):
        policy.check('update_server', context, {'server_id': server_id})

        with self.storage_api.update_server(
                context, server_id, values) as server:
            # Update backend with the new details..
            with wrap_backend_call():
                self.backend.update_server(context, server)

        utils.notify(context, 'central', 'server.update', server)

        return server
Exemplo n.º 20
0
    def update_server(self, context, server_id, values):
        policy.check('update_server', context, {'server_id': server_id})

        with self.storage_api.update_server(context, server_id,
                                            values) as server:
            # Update backend with the new details..
            with wrap_backend_call():
                self.backend.update_server(context, server)

        utils.notify(context, 'central', 'server.update', server)

        return server
Exemplo n.º 21
0
    def create_domain(self, context, values):
        # TODO(kiall): Refactor this method into *MUCH* smaller chunks.
        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
        self._enforce_domain_quota(context, values['tenant_id'])

        # 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_api.find_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()

        with self.storage_api.create_domain(context, values) as domain:
            with wrap_backend_call():
                self.backend.create_domain(context, domain)

        utils.notify(context, 'central', 'domain.create', domain)

        return domain
Exemplo n.º 22
0
    def delete_server(self, context, server_id):
        policy.check('delete_server', context, {'server_id': server_id})

        # don't delete last of servers
        servers = self.storage_api.find_servers(context)
        if len(servers) == 1 and server_id == servers[0]['id']:
            raise exceptions.LastServerDeleteNotAllowed(
                "Not allowed to delete last of servers")

        with self.storage_api.delete_server(context, server_id) as server:
            # Update backend with the new server..
            with wrap_backend_call():
                self.backend.delete_server(context, server)

        utils.notify(context, 'central', 'server.delete', server)
Exemplo n.º 23
0
    def delete_server(self, context, server_id):
        policy.check('delete_server', context, {'server_id': server_id})

        # don't delete last of servers
        servers = self.storage_api.find_servers(context)
        if len(servers) == 1 and server_id == servers[0]['id']:
            raise exceptions.LastServerDeleteNotAllowed(
                "Not allowed to delete last of servers")

        with self.storage_api.delete_server(context, server_id) as server:
            # Update backend with the new server..
            with wrap_backend_call():
                self.backend.delete_server(context, server)

        utils.notify(context, 'central', 'server.delete', server)
Exemplo n.º 24
0
    def touch_domain(self, context, domain_id):
        domain = self.storage_api.get_domain(context, domain_id)

        target = {
            'domain_id': domain_id,
            'domain_name': domain['name'],
            'tenant_id': domain['tenant_id']
        }

        policy.check('touch_domain', context, target)

        domain = self._increment_domain_serial(context, domain_id)

        utils.notify(context, 'central', 'domain.touch', domain)

        return domain
Exemplo n.º 25
0
    def touch_domain(self, context, domain_id):
        domain = self.storage_api.get_domain(context, domain_id)

        target = {
            'domain_id': domain_id,
            'domain_name': domain['name'],
            'tenant_id': domain['tenant_id']
        }

        policy.check('touch_domain', context, target)

        domain = self._increment_domain_serial(context, domain_id)

        utils.notify(context, 'central', 'domain.touch', domain)

        return domain
Exemplo n.º 26
0
    def update_record(self,
                      context,
                      domain_id,
                      record_id,
                      values,
                      increment_serial=True):
        domain = self.storage_api.get_domain(context, domain_id)
        record = self.storage_api.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)
        self._is_valid_record_placement(context, domain, record_name,
                                        record_type, record_id)

        # Update the record
        with self.storage_api.update_record(context, record_id,
                                            values) as record:
            with wrap_backend_call():
                self.backend.update_record(context, domain, record)

            if increment_serial:
                self._increment_domain_serial(context, domain_id)

        # Send Record update notification
        utils.notify(context, 'central', 'record.update', record)

        return record
Exemplo n.º 27
0
    def update_record(self, context, domain_id, record_id, values,
                      increment_serial=True):
        domain = self.storage_api.get_domain(context, domain_id)
        record = self.storage_api.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)
        self._is_valid_record_placement(context, domain, record_name,
                                        record_type, record_id)

        # Update the record
        with self.storage_api.update_record(
                context, record_id, values) as record:
            with wrap_backend_call():
                self.backend.update_record(context, domain, record)

            if increment_serial:
                self._increment_domain_serial(context, domain_id)

        # Send Record update notification
        utils.notify(context, 'central', 'record.update', record)

        return record
Exemplo n.º 28
0
    def update_domain(self, context, domain_id, values, increment_serial=True):
        # TODO(kiall): Refactor this method into *MUCH* smaller chunks.
        domain = self.storage_api.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'])

        with self.storage_api.update_domain(
                context, domain_id, values) as domain:
            with wrap_backend_call():
                self.backend.update_domain(context, domain)

        utils.notify(context, 'central', 'domain.update', domain)

        return domain
Exemplo n.º 29
0
    def update_domain(self, context, domain_id, values, increment_serial=True):
        # TODO(kiall): Refactor this method into *MUCH* smaller chunks.
        domain = self.storage_api.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'])

        with self.storage_api.update_domain(context, domain_id,
                                            values) as domain:
            with wrap_backend_call():
                self.backend.update_domain(context, domain)

        utils.notify(context, 'central', 'domain.update', domain)

        return domain