code: def __init__(
      self,
      db: Database,  # BORROWED
      inst_coll_manager: InstanceCollectionManager,
      resource_manager: CloudResourceManager,
      cloud: str,
      name: str,
      machine_name_prefix: str,
      is_pool: bool,
      max_instances: int,
      max_live_instances: int,
      task_manager: aiotools.BackgroundTaskManager,  # BORROWED
  ):
      self.db = db
      self.inst_coll_manager = inst_coll_manager
      self.resource_manager = resource_manager
      self.cloud = cloud
      self.name = name
      self.machine_name_prefix = f"{machine_name_prefix}{self.name}-"
      self.is_pool = is_pool
      self.max_instances = max_instances
      self.max_live_instances = max_live_instances
  
      self.stats_by_instance_version: Dict[
          int, InstanceCollectionStats
      ] = collections.defaultdict(lambda: InstanceCollectionStats())
  
      self.name_instance: Dict[str, Instance] = {}
  
      self.instances_by_last_updated = sortedcontainers.SortedSet(
          key=lambda instance: instance.last_updated
      )
  
      task_manager.ensure_future(self.monitor_instances_loop())
      self.inst_coll_manager.register_instance_collection(self)
  
imports: import asyncio
  import collections
  import logging
  import re
  import secrets
  from typing import Any, Counter, Dict, List, Optional, Tuple
  import sortedcontainers
  from gear import Database
  from gear.time_limited_max_size_cache import TimeLimitedMaxSizeCache
  from hailtop import aiotools
  from hailtop.utils import periodically_call, secret_alnum_string, time_msecs
  from ...globals import INSTANCE_VERSION, live_instance_states
  from ...instance_config import QuantifiedResource
  from ..instance import Instance
  from ..location import CloudLocationMonitor
  from ..resource_manager import CloudResourceManager, UnknownVMState, VMDoesNotExist, VMStateCreating, VMStateRunning, VMStateTerminated
label_desc: Use image node_id 1 to create a new InstanceCollection object  with example: obj = InstanceCollection(db, inst_coll_manager, resource_manager, cloud, name, machine_name_prefix, is_pool, max_instances, max_live_instances, task_manager)