def _build_wanted_replicas_by_tier(self):
        weighted_replicas = self._build_weighted_replicas_by_tier()
        dispersed_replicas = {
            t: {
                'min': math.floor(r),
                'max': math.ceil(r),
            } for (t, r) in
            self._build_max_replicas_by_tier(bound=float).items()
        }

        # watch out for device limited tiers
        num_devices = defaultdict(int)
        for d in self._iter_devs():
            if d['weight'] <= 0:
                continue
            for t in (d.get('tiers') or tiers_for_dev(d)):
                num_devices[t] += 1
            num_devices[()] += 1

        tier2children = self._build_tier2children()

        wanted_replicas = defaultdict(float)

        def place_replicas(tier, replicanths):
            if replicanths > num_devices[tier]:
                raise exceptions.RingValidationError(
                    'More than replicanths (%s) than devices (%s) '
                    'in tier (%s)' % (replicanths, num_devices[tier], tier))
            wanted_replicas[tier] = replicanths
            sub_tiers = sorted(tier2children[tier])
            if not sub_tiers:
                return

            to_place = defaultdict(float)
            remaining = replicanths
            tiers_to_spread = sub_tiers
            device_limited = False

            while True:
                rel_weight = remaining / sum(weighted_replicas[t]
                                             for t in tiers_to_spread)
                for t in tiers_to_spread:
                    replicas = to_place[t] + (
                        weighted_replicas[t] * rel_weight)
                    if replicas < dispersed_replicas[t]['min']:
                        replicas = dispersed_replicas[t]['min']
                    elif (replicas > dispersed_replicas[t]['max'] and
                          not device_limited):
                        replicas = dispersed_replicas[t]['max']
                    if replicas > num_devices[t]:
                        replicas = num_devices[t]
                    to_place[t] = replicas

                remaining = replicanths - sum(to_place.values())

                if remaining < -1e-10:
                    tiers_to_spread = [
                        t for t in sub_tiers
                        if to_place[t] > dispersed_replicas[t]['min']
                    ]
                elif remaining > 1e-10:
                    tiers_to_spread = [
                        t for t in sub_tiers
                        if (num_devices[t] > to_place[t] <
                            dispersed_replicas[t]['max'])
                    ]
                    if not tiers_to_spread:
                        device_limited = True
                        tiers_to_spread = [
                            t for t in sub_tiers
                            if to_place[t] < num_devices[t]
                        ]
                else:
                    # remaining is "empty"
                    break

            for t in sub_tiers:
                self.logger.debug('Planning %s on %s',
                                  to_place[t], t)
                place_replicas(t, to_place[t])

        # place all replicas in the cluster tier
        place_replicas((), self.replicas)

        # belts & suspenders/paranoia -  at every level, the sum of
        # wanted_replicas should be very close to the total number of
        # replicas for the ring
        tiers = ['cluster', 'regions', 'zones', 'servers', 'devices']
        for i, tier_name in enumerate(tiers):
            replicas_at_tier = sum(wanted_replicas[t] for t in
                                   wanted_replicas if len(t) == i)
            if abs(self.replicas - replicas_at_tier) > 1e-10:
                raise exceptions.RingValidationError(
                    '%s != %s at tier %s' % (
                        replicas_at_tier, self.replicas, tier_name))

        return wanted_replicas
Adds authorization header to request metadata.
dataset/ETHPy150Open openstack/swift/swift/common/ring/builder.py/RingBuilder._build_wanted_replicas_by_tier--crossover with--dataset/ETHPy150Open GoogleCloudPlatform/gcloud-python/gcloud/bigtable/client.py/_MetadataPlugin.__call__