(
        self,
        mors,  # type: Iterable[vim.ManagedEntity]
        metric_ids,  # type: List[vim.PerformanceManager.MetricId]
        resource_type,  # type: Type[vim.ManagedEntity]
    )
Iterates over mor and generate batches with a fixed number of metrics to query.
        Querying multiple resource types in the same call is error prone if we query a cluster metric. Indeed,
        cluster metrics result in an unpredictable number of internal metric queries which all count towards
        max_query_metrics. Therefore often collecting a single cluster metric can make the whole call to fail. That's
        why we should never batch cluster metrics with anything else.
Iterates over mor and generate batches with a fixed number of metrics to query.
        Querying multiple resource types in the same call is error prone if we query a cluster metric. Indeed,
        cluster metrics result in an unpredictable number of internal metric queries which all count towards
        max_query_metrics. Therefore often collecting a single cluster metric can make the whole call to fail. That's
        why we should never batch cluster metrics with anything else.
Iterates over mor and generate batches with a fixed number of metrics to query . Querying multiple resource types in the same call is error prone if we query a cluster metric . Indeed cluster metrics result in an unpredictable number of internal metric queries which all count towards max_query_metrics . Therefore often collecting a single cluster metric can make the whole call to fail . That s why we should never batch cluster metrics with anything else .
def make_batch(
        self,
        mors,  # type: Iterable[vim.ManagedEntity]
        metric_ids,  # type: List[vim.PerformanceManager.MetricId]
        resource_type,  # type: Type[vim.ManagedEntity]
    ):  # type: (...) -> Generator[MorBatch, None, None]
        """Iterates over mor and generate batches with a fixed number of metrics to query.
        Querying multiple resource types in the same call is error prone if we query a cluster metric. Indeed,
        cluster metrics result in an unpredictable number of internal metric queries which all count towards
        max_query_metrics. Therefore often collecting a single cluster metric can make the whole call to fail. That's
        why we should never batch cluster metrics with anything else.
        """
        # Safeguard, let's avoid collecting multiple resources in the same call
        mors_filtered = [m for m in mors if isinstance(m, resource_type)]  # type: List[vim.ManagedEntity]

        if resource_type == vim.ClusterComputeResource:
            # Cluster metrics are unpredictable and a single call can max out the limit. Always collect them one by one.
            max_batch_size = 1  # type: float
        elif resource_type in REALTIME_RESOURCES or self._config.max_historical_metrics < 0:
            # Queries are not limited by vCenter
            max_batch_size = self._config.metrics_per_query
        else:
            # Collection is limited by the value of `max_query_metrics`
            if self._config.metrics_per_query < 0:
                max_batch_size = self._config.max_historical_metrics
            else:
                max_batch_size = min(self._config.metrics_per_query, self._config.max_historical_metrics)

        batch = defaultdict(list)  # type: MorBatch
        batch_size = 0
        for m in mors_filtered:
            for metric_id in metric_ids:
                if batch_size == max_batch_size:
                    yield batch
                    batch = defaultdict(list)
                    batch_size = 0
                batch[m].append(metric_id)
                batch_size += 1
        # Do not yield an empty batch
        if batch:
            yield batch
def make_batch ( self , mors , # type: Iterable[vim.ManagedEntity] metric_ids , # type: List[vim.PerformanceManager.MetricId] resource_type , # type: Type[vim.ManagedEntity] ) : # type: (...) -> Generator[MorBatch, None, None] # Safeguard, let's avoid collecting multiple resources in the same call mors_filtered = [ m for m in mors if isinstance ( m , resource_type ) ] # type: List[vim.ManagedEntity] if resource_type == vim . ClusterComputeResource : # Cluster metrics are unpredictable and a single call can max out the limit. Always collect them one by one. max_batch_size = 1 # type: float elif resource_type in REALTIME_RESOURCES or self . _config . max_historical_metrics < 0 : # Queries are not limited by vCenter max_batch_size = self . _config . metrics_per_query else : # Collection is limited by the value of `max_query_metrics` if self . _config . metrics_per_query < 0 : max_batch_size = self . _config . max_historical_metrics else : max_batch_size = min ( self . _config . metrics_per_query , self . _config . max_historical_metrics ) batch = defaultdict ( list ) # type: MorBatch batch_size = 0 for m in mors_filtered : for metric_id in metric_ids : if batch_size == max_batch_size : yield batch batch = defaultdict ( list ) batch_size = 0 batch [ m ] . append ( metric_id ) batch_size += 1 # Do not yield an empty batch if batch : yield batch