'Returns a copy of cluster metadata with partitions added'

def with_partitions(self, partitions_to_add):

    new_metadata = ClusterMetadata(**self.config)
    new_metadata._brokers = copy.deepcopy(self._brokers)
    new_metadata._partitions = copy.deepcopy(self._partitions)
    new_metadata._broker_partitions = copy.deepcopy(self._broker_partitions)
    new_metadata._groups = copy.deepcopy(self._groups)
    new_metadata.internal_topics = copy.deepcopy(self.internal_topics)
    new_metadata.unauthorized_topics = copy.deepcopy(self.unauthorized_topics)
    for partition in partitions_to_add:
        new_metadata._partitions[partition.topic][partition.partition] = partition
        if ((partition.leader is not None) and (partition.leader != (-1))):
            new_metadata._broker_partitions[partition.leader].add(TopicPartition(partition.topic, partition.partition))
    return new_metadata
