当前位置: 首页>>代码示例>>Python>>正文


Python DesignateContext.get_admin_context方法代码示例

本文整理汇总了Python中designate.context.DesignateContext.get_admin_context方法的典型用法代码示例。如果您正苦于以下问题:Python DesignateContext.get_admin_context方法的具体用法?Python DesignateContext.get_admin_context怎么用?Python DesignateContext.get_admin_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在designate.context.DesignateContext的用法示例。


在下文中一共展示了DesignateContext.get_admin_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: periodic_sync

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def periodic_sync(self):
        """
        :return: None
        """
        # NOTE(kiall): Only run this periodic task on the pool leader
        if self._pool_election.is_leader:
            context = DesignateContext.get_admin_context(all_tenants=True)

            LOG.debug("Starting Periodic Synchronization")

            criterion = {
                'pool_id': CONF['service:pool_manager'].pool_id,
                'status': '!%s' % ERROR_STATUS
            }

            periodic_sync_seconds = \
                CONF['service:pool_manager'].periodic_sync_seconds

            if periodic_sync_seconds is not None:
                # Generate the current serial, will provide a UTC Unix TS.
                current = utils.increment_serial()
                criterion['serial'] = ">%s" % (current - periodic_sync_seconds)

            zones = self.central_api.find_zones(context, criterion)

            try:
                for zone in zones:
                    # TODO(kiall): If the zone was created within the last
                    #              periodic_sync_seconds, attempt to recreate
                    #              to fill in targets which may have failed.
                    self.update_zone(context, zone)

            except Exception:
                LOG.exception(_LE('An unhandled exception in periodic '
                                  'synchronization occurred.'))
开发者ID:CingHu,项目名称:designate,代码行数:37,代码来源:service.py

示例2: _delete

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def _delete(self, managed=True, resource_id=None, resource_type='instance',
                criterion={}):
        """
        Handle a generic delete of a fixed ip within a domain

        :param criterion: Criterion to search and destroy records
        """
        context = DesignateContext.get_admin_context()

        if managed:
            criterion.update({
                'managed': managed,
                'managed_plugin_name': self.get_plugin_name(),
                'managed_plugin_type': self.get_plugin_type(),
                'managed_resource_id': resource_id,
                'managed_resource_type': resource_type
            })

        records = central_api.find_records(context,
                                           cfg.CONF[self.name].domain_id,
                                           criterion)

        for record in records:
            LOG.debug('Deleting record %s' % record['id'])

            central_api.delete_record(context, cfg.CONF[self.name].domain_id,
                                      record['id'])
开发者ID:bluzader,项目名称:designate,代码行数:29,代码来源:base.py

示例3: periodic_recovery

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def periodic_recovery(self):
        """
        :return: None
        """
        # TODO(kiall): Replace this inter-process-lock with a distributed
        #              lock, likely using the tooz library - see bug 1445127.
        with lockutils.lock('periodic_recovery', external=True, delay=30):
            context = DesignateContext.get_admin_context(all_tenants=True)

            LOG.debug("Starting Periodic Recovery")

            try:
                # Handle Deletion Failures
                domains = self._get_failed_domains(context, DELETE_ACTION)

                for domain in domains:
                    self.delete_domain(context, domain)

                # Handle Creation Failures
                domains = self._get_failed_domains(context, CREATE_ACTION)

                for domain in domains:
                    self.create_domain(context, domain)

                # Handle Update Failures
                domains = self._get_failed_domains(context, UPDATE_ACTION)

                for domain in domains:
                    self.update_domain(context, domain)

            except Exception:
                LOG.exception(_LE('An unhandled exception in periodic '
                                  'recovery occurred'))
开发者ID:rtapadar,项目名称:designate,代码行数:35,代码来源:service.py

示例4: load_pool

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def load_pool(self, pool_id):
        # Build the Pool (and related) Object from Config
        context = DesignateContext.get_admin_context()

        pool = None
        has_targets = False

        while not has_targets:
            try:
                pool = self.central_api.get_pool(context, pool_id)

                if len(pool.targets) > 0:
                    has_targets = True
                else:
                    LOG.error("No targets for %s found.", pool)
                    time.sleep(5)

            # Pool data may not have migrated to the DB yet
            except exceptions.PoolNotFound:
                LOG.error("Pool ID %s not found.", pool_id)
                time.sleep(5)
            # designate-central service may not have started yet
            except messaging.exceptions.MessagingTimeout:
                time.sleep(0.2)

        return self._setup_target_backends(pool)
开发者ID:mrlesmithjr,项目名称:designate,代码行数:28,代码来源:service.py

示例5: start

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def start(self):

        # Build the Pool (and related) Object from Config
        context = DesignateContext.get_admin_context()
        pool_id = CONF['service:pool_manager'].pool_id

        has_targets = False

        # TODO(kiall): This block of code should be replaced with a cleaner,
        #              limited version. e.g. should retry for X minutes, and
        #              backoff rather than fixed retry intervals.
        while not has_targets:
            try:
                self.pool = self.central_api.get_pool(context, pool_id)

                if len(self.pool.targets) > 0:
                    has_targets = True
                else:
                    LOG.error(_LE("No targets for %s found."), self.pool)
                    time.sleep(5)

            # Pool data may not have migrated to the DB yet
            except exceptions.PoolNotFound:
                LOG.error(_LE("Pool ID %s not found."), pool_id)
                time.sleep(5)
            # designate-central service may not have started yet
            except messaging.exceptions.MessagingTimeout:
                time.sleep(0.2)
            # designate-central failed in an unknown way, don't allow another
            # failing / not started service to cause pool-manager to crash.
            except Exception:
                LOG.exception(_LE("An unknown exception occurred while "
                                  "fetching pool details"))
                time.sleep(5)

        # Create the necessary Backend instances for each target
        self._setup_target_backends()

        for target in self.pool.targets:
            self.target_backends[target.id].start()

        super(Service, self).start()

        # Setup a Leader Election, use for ensuring certain tasks are executed
        # on exactly one pool-manager instance at a time]
        self._pool_election = coordination.LeaderElection(
            self._coordinator, '%s:%s' % (self.service_name, self.pool.id))
        self._pool_election.start()

        if CONF['service:pool_manager'].enable_recovery_timer:
            interval = CONF['service:pool_manager'].periodic_recovery_interval
            LOG.info(_LI('Starting periodic recovery timer every'
                         ' %(interval)s s') % {'interval': interval})
            self.tg.add_timer(interval, self.periodic_recovery, interval)

        if CONF['service:pool_manager'].enable_sync_timer:
            interval = CONF['service:pool_manager'].periodic_sync_interval
            LOG.info(_LI('Starting periodic synchronization timer every'
                         ' %(interval)s s') % {'interval': interval})
            self.tg.add_timer(interval, self.periodic_sync, interval)
开发者ID:ISCAS-VDI,项目名称:designate-base,代码行数:62,代码来源:service.py

示例6: periodic_recovery

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def periodic_recovery(self):
        """
        :return: None
        """
        # NOTE(kiall): Only run this periodic task on the pool leader
        if self._pool_election.is_leader:
            context = DesignateContext.get_admin_context(all_tenants=True)

            LOG.debug("Starting Periodic Recovery")

            try:
                # Handle Deletion Failures
                zones = self._get_failed_zones(context, DELETE_ACTION)

                for zone in zones:
                    self.delete_zone(context, zone)

                # Handle Creation Failures
                zones = self._get_failed_zones(context, CREATE_ACTION)

                for zone in zones:
                    self.create_zone(context, zone)

                # Handle Update Failures
                zones = self._get_failed_zones(context, UPDATE_ACTION)

                for zone in zones:
                    self.update_zone(context, zone)

            except Exception:
                LOG.exception(_LE('An unhandled exception in periodic '
                                  'recovery occurred'))
开发者ID:CingHu,项目名称:designate,代码行数:34,代码来源:service.py

示例7: test_invalid_event_type

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def test_invalid_event_type(self):
        context = DesignateContext.get_admin_context(all_tenants=True)
        if not hasattr(self, 'plugin'):
            raise NotImplementedError
        event_type = 'invalid'

        self.assertNotIn(event_type, self.plugin.get_event_types())

        with testtools.ExpectedException(ValueError):
            self.plugin.process_notification(context, event_type, 'payload')
开发者ID:NeCTAR-RC,项目名称:designate,代码行数:12,代码来源:__init__.py

示例8: __init__

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def __init__(self, target):
        super(Backend, self).__init__()

        self.target = target
        self.options = target.options
        self.masters = target.masters

        # TODO(kiall): Context's should never be shared accross requests.
        self.admin_context = DesignateContext.get_admin_context()
        self.admin_context.all_tenants = True
开发者ID:infobloxopen,项目名称:designate,代码行数:12,代码来源:base.py

示例9: __init__

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def __init__(self):
        # Get a storage connection
        storage_driver = cfg.CONF['service:mdns'].storage_driver
        self.storage = storage.get_storage(storage_driver)
        self.admin_context = DesignateContext.get_admin_context(
            all_tenants=True)

        # Fake request is used to send a response when we cannot decipher the
        # request.
        self._fake_request = dns.message.make_query('unknown', dns.rdatatype.A)
开发者ID:NeCTAR-RC,项目名称:designate,代码行数:12,代码来源:handler.py

示例10: _create

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def _create(self, addresses, extra, managed=True,
                resource_type=None, resource_id=None):
        """
        Create a a record from addresses

        :param addresses: Address objects like
                          {'version': 4, 'ip': '10.0.0.1'}
        :param extra: Extra data to use when formatting the record
        :param managed: Is it a managed resource
        :param resource_type: The managed resource type
        :param resource_id: The managed resource ID
        """
        LOG.debug('Using DomainID: %s' % cfg.CONF[self.name].domain_id)
        domain = self.get_domain(cfg.CONF[self.name].domain_id)
        LOG.debug('Domain: %r' % domain)

        data = extra.copy()
        LOG.debug('Event data: %s' % data)
        data['domain'] = domain['name']

        context = DesignateContext.get_admin_context(all_tenants=True)

        for addr in addresses:
            event_data = data.copy()
            event_data.update(get_ip_data(addr))

            recordset_values = {
                'domain_id': domain['id'],
                'name': self._get_format() % event_data,
                'type': 'A' if addr['version'] == 4 else 'AAAA'}

            recordset = self._find_or_create_recordset(
                context, **recordset_values)

            record_values = {
                'data': addr['address']}

            if managed:
                record_values.update({
                    'managed': managed,
                    'managed_plugin_name': self.get_plugin_name(),
                    'managed_plugin_type': self.get_plugin_type(),
                    'managed_resource_type': resource_type,
                    'managed_resource_id': resource_id})

            LOG.debug('Creating record in %s / %s with values %r' %
                      (domain['id'], recordset['id'], record_values))
            self.central_api.create_record(context,
                                           domain['id'],
                                           recordset['id'],
                                           Record(**record_values))
开发者ID:NeCTAR-RC,项目名称:designate,代码行数:53,代码来源:base.py

示例11: start

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def start(self):

        # Build the Pool (and related) Object from Config
        context = DesignateContext.get_admin_context()
        pool_id = CONF['service:pool_manager'].pool_id

        has_targets = False

        while not has_targets:
            try:
                self.pool = self.central_api.get_pool(context, pool_id)

                if len(self.pool.targets) > 0:
                    has_targets = True
                else:
                    LOG.error(_LE("No targets for %s found."), self.pool)
                    time.sleep(5)

            # Pool data may not have migrated to the DB yet
            except exceptions.PoolNotFound:
                LOG.error(_LE("Pool ID %s not found."), pool_id)
                time.sleep(5)
            # designate-central service may not have started yet
            except messaging.exceptions.MessagingTimeout:
                time.sleep(0.2)

        # Create the necessary Backend instances for each target
        self._setup_target_backends()

        for target in self.pool.targets:
            self.target_backends[target.id].start()

        super(Service, self).start()

        # Setup a Leader Election, use for ensuring certain tasks are executed
        # on exactly one pool-manager instance at a time]
        self._pool_election = coordination.LeaderElection(
            self._coordinator, '%s:%s' % (self.service_name, self.pool.id))
        self._pool_election.start()

        if CONF['service:pool_manager'].enable_recovery_timer:
            interval = CONF['service:pool_manager'].periodic_recovery_interval
            LOG.info(_LI('Starting periodic recovery timer every'
                         ' %(interval)s s') % {'interval': interval})
            self.tg.add_timer(interval, self.periodic_recovery, interval)

        if CONF['service:pool_manager'].enable_sync_timer:
            interval = CONF['service:pool_manager'].periodic_sync_interval
            LOG.info(_LI('Starting periodic synchronization timer every'
                         ' %(interval)s s') % {'interval': interval})
            self.tg.add_timer(interval, self.periodic_sync, interval)
开发者ID:andrewspiers,项目名称:designate,代码行数:53,代码来源:service.py

示例12: __init__

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def __init__(self, target):
        super(Backend, self).__init__()

        self.target = target
        self.options = target.options
        self.masters = target.masters
        self.host = self.options.get('host', '127.0.0.1')
        self.port = int(self.options.get('port', 53))

        # TODO(kiall): Context's should never be shared across requests.
        self.admin_context = DesignateContext.get_admin_context()
        self.admin_context.all_tenants = True

        # Options for sending NOTIFYs
        self.timeout = CONF['service:pool_manager'].poll_timeout
        self.retry_interval = CONF['service:pool_manager'].poll_retry_interval
        self.max_retries = CONF['service:pool_manager'].poll_max_retries
        self.delay = CONF['service:pool_manager'].poll_delay
开发者ID:mrlesmithjr,项目名称:designate,代码行数:20,代码来源:base.py

示例13: main

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
def main():
    args = parse_args()
    logging.setup('cirrus_floatingip')
    LOG.logger.setLevel('DEBUG')
    load_config(args.config_file)

    kc = keystone_c.Client(
        username=args.username,
        password=args.password,
        tenant_name=args.tenantname,
        auth_url=args.authurl,
        endpoint_type=args.endpoint_type,
        region_name=args.regionname)

    policy.init()
    rpc.init(cfg.CONF)
    context = DesignateContext.get_admin_context(tenant=kc.auth_tenant_id)

    handler = cirrus.CirrusFloatingIPHandler()

    args.func(kc, handler, context, args)
开发者ID:lllucius,项目名称:cirrus-designate-sink-handler,代码行数:23,代码来源:cli.py

示例14: _create_reverse_record

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
 def _create_reverse_record(self, context, managed, host_fqdn, interface):
     LOG.info('Create reverse record for interface: %s and address: %s', interface['label'], interface['address'])
     host_reverse_fqdn = self._get_reverse_fqdn(interface['address'], interface['version'])
     LOG.info('Create reverse record: %s', host_reverse_fqdn)
     reverse_domains = self._get_reverse_domains(host_reverse_fqdn)
     admin_context = DesignateContext.get_admin_context(all_tenants=True)
     for reverse_domain in reverse_domains:
         LOG.info('Create reverse record for domain: %s', reverse_domain.name)
         try:
             recordset = self.central_api.create_recordset(admin_context,
                                                           reverse_domain.id,
                                                           RecordSet(name=host_reverse_fqdn, type='PTR'))
         except exceptions.DuplicateRecordSet:
             LOG.warn('The reverse record: %s was already registered', host_reverse_fqdn)
         else:
             record_values = dict(managed, data=host_fqdn)
             LOG.debug('Creating reverse record in %s / %s with values %r',
                       reverse_domain.id, recordset['id'], record_values)
             self.central_api.create_record(admin_context,
                                            reverse_domain.id,
                                            recordset['id'],
                                            Record(**record_values))
开发者ID:TDAF,项目名称:designate-enhancedhandler,代码行数:24,代码来源:base.py

示例15: _create

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import get_admin_context [as 别名]
    def _create(self, addresses, extra, managed=True,
                resource_type=None, resource_id=None):
        """
        Create a a record from addresses

        :param addresses: Address objects like
                          {'version': 4, 'ip': '10.0.0.1'}
        :param extra: Extra data to use when formatting the record
        :param managed: Is it a managed resource
        :param resource_type: The managed resource type
        :param resource_id: The managed resource ID
        """
        LOG.debug('Using DomainID: %s' % cfg.CONF[self.name].domain_id)
        domain = self.get_domain(cfg.CONF[self.name].domain_id)
        LOG.debug('Domain: %r' % domain)

        data = extra.copy()
        data['domain'] = domain['name']

        context = DesignateContext.get_admin_context()

        for addr in addresses:
            record_data = data.copy()
            record_data.update(get_ip_data(addr))

            record_name = self._get_format() % record_data
            record_values = {
                'type': 'A' if addr['version'] == 4 else 'AAAA',
                'name': record_name,
                'data': addr['address']}
            if managed:
                record_values.update({
                    'managed': managed,
                    'managed_plugin_name': self.get_plugin_name(),
                    'managed_plugin_type': self.get_plugin_type(),
                    'managed_resource_type': resource_type,
                    'managed_resource_id': resource_id})
            central_api.create_record(context, domain['id'], record_values)
开发者ID:joeracker,项目名称:designate,代码行数:40,代码来源:base.py


注:本文中的designate.context.DesignateContext.get_admin_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。