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


Python DesignateContext.all_tenants方法代码示例

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


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

示例1: process_notification

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import all_tenants [as 别名]
    def process_notification(self, context, event_type, payload):
        # Do something with the notification.. e.g:
        zone_id = cfg.CONF[self.name].zone_id
        zone_name = cfg.CONF[self.name].zone_name

        record_name = '%s.%s' % (payload['instance_id'], zone_name)

        context = DesignateContext().elevated()
        context.all_tenants = True
        # context.edit_managed_records = True

        for fixed_ip in payload['fixed_ips']:
            recordset_values = {
                'zone_id': zone_id,
                'name': record_name,
                'type': 'A' if fixed_ip['version'] == 4 else 'AAAA'
            }

            record_values = {
                'data': fixed_ip['address'],
            }

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

            self.central_api.create_record(context, zone_id, recordset['id'],
                                           Record(**record_values))
开发者ID:mrlesmithjr,项目名称:designate,代码行数:29,代码来源:sample.py

示例2: _delete

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

        :param zone_id: The ID of the designate zone.
        :param resource_id: The managed resource ID
        :param resource_type: The managed resource type
        :param criterion: Criterion to search and destroy records
        """
        criterion = criterion or {}

        context = DesignateContext().elevated()
        context.all_tenants = True
        context.edit_managed_records = True

        criterion.update({
            'zone_id': zone_id,
            'managed': True,
            '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 = self.central_api.find_records(context, criterion)

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

            self.central_api.delete_record(context,
                                           zone_id,
                                           record['recordset_id'],
                                           record['id'])
开发者ID:openstack,项目名称:designate,代码行数:36,代码来源:base.py

示例3: _create

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import all_tenants [as 别名]
    def _create(self, addresses, extra, zone_id, 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
        """
        if not managed:
            LOG.warning(_LW(
                'Deprecation notice: Unmanaged designate-sink records are '
                'being deprecated please update the call '
                'to remove managed=False'))
        LOG.debug('Using Zone ID: %s' % zone_id)
        zone = self.get_zone(zone_id)
        LOG.debug('Zone: %r' % zone)

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

        context = DesignateContext().elevated()
        context.all_tenants = True
        context.edit_managed_records = True

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

            for fmt in cfg.CONF[self.name].get('format'):
                recordset_values = {
                    'zone_id': zone['id'],
                    'name': fmt % 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' %
                          (zone['id'], recordset['id'], record_values))
                self.central_api.create_record(context,
                                               zone['id'],
                                               recordset['id'],
                                               Record(**record_values))
开发者ID:TimSimmons,项目名称:designate,代码行数:61,代码来源:base.py

示例4: _create

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import all_tenants [as 别名]
    def _create(self, addresses, extra, zone_id, 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
        """
        if not managed:
            LOG.warning(
                _LW(
                    "Deprecation notice: Unmanaged designate-sink records are "
                    "being deprecated please update the call "
                    "to remove managed=False"
                )
            )
        LOG.debug("Using Zone ID: %s", zone_id)
        zone = self.get_zone(zone_id)
        LOG.debug("Domain: %r", zone)

        data = extra.copy()
        LOG.debug("Event data: %s", data)
        data["zone"] = zone["name"]

        context = DesignateContext().elevated()
        context.all_tenants = True
        context.edit_managed_records = True

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

            for fmt in cfg.CONF[self.name].get("format"):
                recordset_values = {
                    "zone_id": zone["id"],
                    "name": fmt % 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", zone["id"], recordset["id"], record_values)
                self.central_api.create_record(context, zone["id"], recordset["id"], Record(**record_values))
开发者ID:carriercomm,项目名称:designate,代码行数:61,代码来源:base.py

示例5: _create

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import all_tenants [as 别名]
    def _create(self, addresses, extra, zone_id, resource_type=None,
                resource_id=None):
        """
        Create 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 zone_id: The ID of the designate zone.
        :param resource_type: The managed resource type
        :param resource_id: The managed resource ID
        """
        LOG.debug('Using Zone ID: %s', zone_id)
        zone = self.get_zone(zone_id)
        LOG.debug('Domain: %r', zone)

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

        context = DesignateContext().elevated()
        context.all_tenants = True
        context.edit_managed_records = True

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

            if addr['version'] == 4:
                format = self._get_formatv4()
            else:
                format = self._get_formatv6()

            for fmt in format:
                recordset_values = {
                    'zone_id': zone['id'],
                    'name': fmt % event_data,
                    'type': 'A' if addr['version'] == 4 else 'AAAA'}

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

                record_values = {
                    'data': addr['address'],
                    'managed': True,
                    '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',
                          zone['id'], recordset['id'], record_values)
                self.central_api.create_record(context,
                                               zone['id'],
                                               recordset['id'],
                                               Record(**record_values))
开发者ID:openstack,项目名称:designate,代码行数:59,代码来源:base.py

示例6: _delete

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

        :param zone_id: The ID of the designate zone.
        :param managed: Is it a managed resource
        :param resource_id: The managed resource ID
        :param resource_type: The managed resource type
        :param criterion: Criterion to search and destroy records
        """
        if not managed:
            LOG.warning(
                'Deprecation notice: Unmanaged designate-sink records are '
                'being deprecated please update the call '
                'to remove managed=False')
        criterion = criterion or {}

        context = DesignateContext().elevated()
        context.all_tenants = True
        context.edit_managed_records = True

        criterion.update({'zone_id': zone_id})

        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 = self.central_api.find_records(context, criterion)

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

            self.central_api.delete_record(context,
                                           zone_id,
                                           record['recordset_id'],
                                           record['id'])
开发者ID:mrlesmithjr,项目名称:designate,代码行数:44,代码来源:base.py

示例7: _delete

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

        :param criterion: Criterion to search and destroy records
        """
        if not managed:
            LOG.warning(
                _LW(
                    "Deprecation notice: Unmanaged designate-sink records are "
                    "being deprecated please update the call "
                    "to remove managed=False"
                )
            )
        criterion = criterion or {}

        context = DesignateContext().elevated()
        context.all_tenants = True
        context.edit_managed_records = True

        criterion.update({"zone_id": zone_id})

        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 = self.central_api.find_records(context, criterion)

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

            self.central_api.delete_record(context, zone_id, record["recordset_id"], record["id"])
开发者ID:carriercomm,项目名称:designate,代码行数:41,代码来源:base.py

示例8: process_notification

# 需要导入模块: from designate.context import DesignateContext [as 别名]
# 或者: from designate.context.DesignateContext import all_tenants [as 别名]
    def process_notification(self, context, event_type, payload):
        """Process floating IP notifications from Neutron"""

        LOG.info('%s received notification - %s' %
                 (self.get_canonical_name(), event_type))

        # We need a context that will allow us to manipulate records that are
        # flagged as managed, so we can't use the context that was provided
        # with the notification.
        elevated_context = DesignateContext(tenant=context['tenant']).elevated()
        elevated_context.all_tenants = True
        elevated_context.edit_managed_records = True

        # Create an object from the original context so we can use it with the
        # RPC API calls.  We want this limited to the single tenant so we can
        # use it to find their domains.
        orig_context = DesignateContext(tenant=context['tenant']).elevated()

        # When an instance is deleted, we never get a floating IP update event,
        # we just get notified that the underlying port was deleted.  In that
        # case look for it under the other key.
        if event_type.startswith('port.delete'):
            self._disassociate_port_id(context=elevated_context,
                                       port_id=payload['port_id'])

        if event_type.startswith('floatingip.'):
            # A floating IP can only be associated with a single instance at a
            # time, so the first thing we always do is remove any existing
            # association when we get an update.  This is always safe whether
            # or not we're deleting it or reassigning it.
            if 'floatingip' in payload:
                # floatingip.update.end
                floating_ip = payload['floatingip']['floating_ip_address']
                floating_ip_id = payload['floatingip']['id']
            elif 'floatingip_id' in payload:
                # floatingip.delete.end
                floating_ip = None
                floating_ip_id = payload['floatingip_id']

            self._disassociate_floating_ip(context=elevated_context,
                                           floating_ip_id=floating_ip_id,
                                           )

        # If it turns out that the event is an update and it has a fixed ip in
        # the update, then we create the new record.
        if event_type.startswith('floatingip.update'):
            if payload['floatingip']['fixed_ip_address']:
                domain = self._pick_tenant_domain(orig_context,
                                                  default_regex=cfg.CONF[self.name].default_regex,
                                                  require_default_regex=cfg.CONF[self.name].require_default_regex,
                                                  )
                if domain is None:
                    LOG.info('No domains found for tenant %s(%s), ignoring Floating IP update for %s' %
                             (context['tenant_name'], context['tenant_id'], floating_ip))
                else:
                    LOG.debug('Using domain %s(%s) for tenant %s(%s)' %
                              (domain.name, domain.id,
                               context['tenant_name'], context['tenant_id']))

                    kc = keystone_c.Client(token=context['auth_token'],
                                           tenant_id=context['tenant_id'],
                                           region_name=cfg.CONF[self.name].region_name,
                                           auth_url=cfg.CONF[self.name].keystone_auth_uri)

                    port_id = payload['floatingip']['port_id']
                    instance_info = self._get_instance_info(kc, port_id)

                    extra = payload.copy()
                    extra.update({'instance_name': instance_info['name'],
                                  'instance_short_name': instance_info['name'].partition('.')[0],
                                  'domain': domain.name})
                    self._associate_floating_ip(context=elevated_context,
                                                domain_id=domain.id,
                                                extra=extra,
                                                floating_ip_id=floating_ip_id,
                                                floating_ip=floating_ip,
                                                port_id=port_id)
开发者ID:matthewfischer,项目名称:cirrus-designate-sink-handler,代码行数:79,代码来源:cirrus_floating_ip_handler.py


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