コード例 #1
0
ファイル: middleware.py プロジェクト: ionrock/designate
    def __init__(self, application, tenant_id=None, user_id=None):
        super(TestContextMiddleware, self).__init__(application)

        LOG.critical(_LC('Starting designate testcontext middleware'))
        LOG.critical(_LC('**** DO NOT USE IN PRODUCTION ****'))

        self.default_tenant_id = tenant_id
        self.default_user_id = user_id
コード例 #2
0
ファイル: __init__.py プロジェクト: mudrykaa/designate
    def delete_domain(self, context, domain):
        try:
            domain_ref = self._get(tables.domains, domain['id'],
                                   exceptions.DomainNotFound,
                                   id_col=tables.domains.c.designate_id)
        except exceptions.DomainNotFound:
            # If the Domain is already gone, that's ok. We're deleting it
            # anyway, so just log and continue.
            LOG.critical(_LC('Attempted to delete a domain which is '
                             'not present in the backend. ID: %s') %
                         domain['id'])
            return

        self._delete(tables.domains, domain['id'],
                     exceptions.DomainNotFound,
                     id_col=tables.domains.c.designate_id)

        # Ensure the records are deleted
        query = tables.records.delete()\
            .where(tables.records.c.domain_id == domain_ref['id'])
        self.session.execute(query)

        # Ensure domainmetadata is deleted
        query = tables.domain_metadata.delete()\
            .where(tables.domain_metadata.c.domain_id == domain_ref['id'])
        self.session.execute(query)
コード例 #3
0
ファイル: pool.py プロジェクト: sunny-verma/designate
 def generate_file(self, file):
     try:
         pools = self.central_api.find_pools(self.context)
     except messaging.exceptions.MessagingTimeout:
         LOG.critical(_LC("No response received from designate-central. "
                          "Check it is running, and retry"))
     with open(file, 'w') as stream:
         yaml.dump(
             DesignateAdapter.render('YAML', pools),
             stream,
             default_flow_style=False
         )
コード例 #4
0
ファイル: __init__.py プロジェクト: rvadim/designate
    def delete_record(self, context, domain, recordset, record):
        try:
            record_m = self._get_record(record["id"])
        except exceptions.RecordNotFound:
            # If the Record is already gone, that's ok. We're deleting it
            # anyway, so just log and continue.
            LOG.critical(
                _LC("Attempted to delete a record which is " "not present in the backend. ID: %s") % record["id"]
            )
        else:
            record_m.delete(self.session)

        self._update_soa(domain)
コード例 #5
0
ファイル: pool.py プロジェクト: sunny-verma/designate
    def show_config(self, pool_id):
        try:
            pool = self.central_api.find_pool(self.context, {"id": pool_id})

            print('Pool Configuration:')
            print('-------------------')

            print(yaml.dump(DesignateAdapter.render('YAML', pool),
                  default_flow_style=False))

        except messaging.exceptions.MessagingTimeout:
            LOG.critical(_LC("No response received from designate-central. "
                             "Check it is running, and retry"))
コード例 #6
0
ファイル: __init__.py プロジェクト: mudrykaa/designate
 def delete_record(self, context, domain, recordset, record):
     try:
         record_ref = self._get(tables.records, record['id'],
                                exceptions.RecordNotFound,
                                id_col=tables.records.c.designate_id)
     except exceptions.RecordNotFound:
         # If the Record is already gone, that's ok. We're deleting it
         # anyway, so just log and continue.
         LOG.critical(_LC('Attempted to delete a record which is '
                          'not present in the backend. ID: %s') %
                      record['id'])
     else:
         self._delete(tables.records, record_ref['id'],
                      exceptions.RecordNotFound)
コード例 #7
0
ファイル: __init__.py プロジェクト: rvadim/designate
    def delete_tsigkey(self, context, tsigkey):
        """Delete a TSIG Key"""
        try:
            # Delete this TSIG Key itself
            tsigkey_m = self._get_tsigkey(tsigkey["id"])
            tsigkey_m.delete(self.session)
        except exceptions.TsigKeyNotFound:
            # If the TSIG Key is already gone, that's ok. We're deleting it
            # anyway, so just log and continue.
            LOG.critical(
                _LC("Attempted to delete a TSIG key which is " "not present in the backend. ID: %s") % tsigkey["id"]
            )
            return

        # Delete this TSIG Key from every domain's metadata
        self.session.query(models.DomainMetadata).filter_by(kind="TSIG-ALLOW-AXFR", content=tsigkey["name"]).delete()
コード例 #8
0
ファイル: __init__.py プロジェクト: ISCAS-VDI/designate-base
    def delete_zone(self, context, zone):
        # TODO(kiall): We should make this match create_zone with regard to
        #              transactions.
        try:
            self._get(tables.domains, zone['id'], exceptions.ZoneNotFound,
                      id_col=tables.domains.c.designate_id)
        except exceptions.ZoneNotFound:
            # If the Zone is already gone, that's ok. We're deleting it
            # anyway, so just log and continue.
            LOG.critical(_LC('Attempted to delete a zone which is '
                             'not present in the backend. ID: %s') %
                         zone['id'])
            return

        self._delete(tables.domains, zone['id'],
                     exceptions.ZoneNotFound,
                     id_col=tables.domains.c.designate_id)
コード例 #9
0
ファイル: pool.py プロジェクト: sunny-verma/designate
 def export_from_config(self, file):
     try:
         pools = self.central_api.find_pools(self.context)
     except messaging.exceptions.MessagingTimeout:
         LOG.critical(_LC("No response received from designate-central. "
                          "Check it is running, and retry"))
     r_pools = objects.PoolList()
     for pool in pools:
         r_pool = objects.Pool.from_config(CONF, pool.id)
         r_pool.id = pool.id
         r_pool.ns_records = pool.ns_records
         r_pool.attributes = pool.attributes
         r_pools.append(r_pool)
     with open(file, 'w') as stream:
         yaml.dump(
             DesignateAdapter.render('YAML', r_pools),
             stream,
             default_flow_style=False
         )
コード例 #10
0
ファイル: __init__.py プロジェクト: rvadim/designate
    def delete_domain(self, context, domain):
        try:
            domain_m = self._get_domain(domain["id"])
        except exceptions.DomainNotFound:
            # If the Domain is already gone, that's ok. We're deleting it
            # anyway, so just log and continue.
            LOG.critical(
                _LC("Attempted to delete a domain which is " "not present in the backend. ID: %s") % domain["id"]
            )
            return

        domain_m.delete(self.session)

        # Ensure the records are deleted
        query = self.session.query(models.Record)
        query.filter_by(domain_id=domain_m.id).delete()

        # Ensure domainmetadata is deleted
        query = self.session.query(models.DomainMetadata)
        query.filter_by(domain_id=domain_m.id).delete()
コード例 #11
0
ファイル: __init__.py プロジェクト: mudrykaa/designate
    def delete_tsigkey(self, context, tsigkey):
        """Delete a TSIG Key"""
        try:
            # Delete this TSIG Key itself
            self._delete(
                tables.tsigkeys, tsigkey['id'],
                exceptions.TsigKeyNotFound,
                id_col=tables.tsigkeys.c.designate_id)
        except exceptions.TsigKeyNotFound:
            # If the TSIG Key is already gone, that's ok. We're deleting it
            # anyway, so just log and continue.
            LOG.critical(_LC('Attempted to delete a TSIG key which is '
                             'not present in the backend. ID: %s') %
                         tsigkey['id'])
            return

        query = tables.domain_metadata.delete()\
            .where(tables.domain_metadata.c.kind == 'TSIG-ALLOW-AXFR')\
            .where(tables.domain_metadata.c.content == tsigkey['name'])
        self.session.execute(query)
コード例 #12
0
ファイル: pool.py プロジェクト: sunny-verma/designate
    def update(self, file, delete, dry_run):
        print('Updating Pools Configuration')
        print('****************************')

        output_msg = ['']

        with open(file, 'r') as stream:
            xpools = yaml.safe_load(stream)

        if dry_run:
            output_msg.append("The following changes will occur:")
            output_msg.append("*********************************")

        for xpool in xpools:
            try:
                if 'id' in xpool:
                    try:
                        pool = self.central_api.get_pool(
                            self.context, xpool['id'])
                    except Exception:
                        LOG.critical(
                            _LC("Bad ID Supplied for pool %s"), xpool['name'])
                        continue
                else:
                    pool = self.central_api.find_pool(
                        self.context, {"name": xpool['name']})

                LOG.info(_LI('Updating existing pool: %s'), pool)

                # TODO(kiall): Move the below into the pool object

                pool = DesignateAdapter.parse('YAML', xpool, pool)

                if dry_run:
                    output_msg.append("Update Pool: %s" % pool)
                else:
                    pool = self.central_api.update_pool(self.context, pool)

            except exceptions.PoolNotFound:
                pool = DesignateAdapter.parse('YAML', xpool, objects.Pool())
                # pool = objects.Pool.from_dict(xpool)
                if dry_run:
                    output_msg.append("Create Pool: %s" % pool)
                else:
                    LOG.info(_LI('Creating new pool: %s'), pool)
                    self.central_api.create_pool(self.context, pool)
            except messaging.exceptions.MessagingTimeout:
                LOG.critical(_LC("No response received from designate-central."
                                 " Check it is running, and retry"))

        if delete:
            pools = self.central_api.find_pools(self.context)
            pools_in_db = {pool.name for pool in pools}
            pools_in_yaml = {xpool['name'] for xpool in xpools}

            pools_to_delete = pools_in_db - pools_in_yaml

            for pool in pools_to_delete:
                try:
                    p = self.central_api.find_pool(
                        self.context,
                        criterion={'name': pool})

                    if dry_run:
                        output_msg.append("Delete Pool: %s" % p)

                    else:
                        LOG.info(_LI('Deleting %s'), p)
                        self.central_api.delete_pool(self.context, p.id)

                except messaging.exceptions.MessagingTimeout:
                    LOG.critical(_LC("No response received from "
                                     "designate-central. "
                                     "Check it is running, and retry"))

        for line in output_msg:
            print(line)