code: def list_slots(args: argparse.Namespace) -> None:
      task_res = bindings.get_GetTasks(cli.setup_session(args))
      resp = bindings.get_GetAgents(cli.setup_session(args))
  
      allocations = task_res.allocationIdToSummary
  
      c_names = (
          {
              r.containerId: {
                  "name": a.name,
                  "allocation_id": a.allocationId,
              }
              for a in allocations.values()
              for r in (a.resources or {})
              if r.containerId
          }
          if allocations
          else {}
      )
  
      def device_type_string(
          deviceType: typing.Optional[bindings.devicev1Type],
      ) -> str:
          if deviceType == bindings.devicev1Type.CUDA:
              return "cuda"
          if deviceType == bindings.devicev1Type.ROCM:
              return "rocm"
          if deviceType == bindings.devicev1Type.CPU:
              return "cpu"
          return "unknown"
  
      def get_task_name(
          containers: Dict[str, Any], slot: bindings.v1Slot
      ) -> str:
          if not slot.container:
              return "FREE"
  
          if slot.container.permissionDenied:
              return NO_PERMISSIONS
  
          container_id = slot.container.id
  
          if slot.container and container_id in containers:
              return str(containers[container_id]["name"])
  
          if slot.container and (
              "determined-master-deployment" in container_id
              or "determined-db-deployment" in container_id
          ):
              return f"Determined System Task: {container_id}"
  
          if slot.container and (
              "dispatcherrm-inuse-slot-placeholder" in container_id
          ):
              return ""  # slot:task relationship not tracked on HPC clusters, so just show ""
  
          return f"Non-Determined Task: {container_id}"
  
      slots = [
          collections.OrderedDict(
              [
                  ("agent_id", local_id(agent.id)),
                  (
                      "resource_pools",
                      ", ".join(agent.resourcePools)
                      if agent.resourcePools is not None
                      else "",
                  ),
                  ("slot_id", local_id(slot.id or "")),
                  ("enabled", slot.enabled),
                  ("draining", slot.draining),
                  (
                      "allocation_id",
                      c_names[slot.container.id]["allocation_id"]
                      if slot.container and slot.container.id in c_names
                      else ("OCCUPIED" if slot.container else "FREE"),
                  ),
                  ("task_name", get_task_name(c_names, slot)),
                  (
                      "type",
                      device_type_string(
                          (slot.device or bindings.v1Device()).type
                      ),
                  ),
                  (
                      "device",
                      (slot.device or bindings.v1Device()).brand,
                  ),
              ]
          )
          for agent in sorted(
              resp.agents or [], key=operator.attrgetter("id")
          )
          for _key, slot in (agent.slots or {}).items()
      ]
  
      headers = [
          "Agent ID",
          "Resource Pool",
          "Slot ID",
          "Enabled",
          "Draining",
          "Allocation ID",
          "Task Name",
          "Type",
          "Device",
      ]
  
      if args.json:
          determined.cli.render.print_json(slots)
          return
  
      values = [s.values() for s in slots]
  
      render.tabulate_or_csv(headers, values, args.csv)
  
file_path: determined/harness/determined/cli/agent.py
imports: import argparse
  import collections
  import operator
  import os
  import sys
  import typing
  from typing import Any, Callable, Dict, List
  import determined.cli.render
  from determined import cli
  from determined.cli import errors, render
  from determined.cli import task
  from determined.common import api, check
  from determined.common.api import authentication, bindings
  from determined.common.declarative_argparse import Arg, Cmd, Group
label_desc: Use image node_id 3 for calling a global function with example usage: list_slots(args) and returns: str, str, container_id, str, str, str, str, NO_PERMISSIONS, str, str, container_id, str