code: def terminate_workflow(self, name):
      client = self._client.get()
      try:
          workflow = (
              client.CustomObjectsApi().get_namespaced_custom_object(
                  group=self._group,
                  version=self._version,
                  namespace=self._namespace,
                  plural="workflows",
                  name=name,
              )
          )
      except client.rest.ApiException as e:
          raise ArgoClientException(
              json.loads(e.body)["message"]
              if e.body is not None
              else e.reason
          )
  
      if workflow["status"]["finishedAt"] is not None:
          raise ArgoClientException(
              "Cannot terminate an execution that has already finished."
          )
      if workflow["spec"].get("shutdown") == "Terminate":
          raise ArgoClientException(
              "Execution has already been terminated."
          )
  
      try:
          body = {"spec": workflow["spec"]}
          body["spec"]["shutdown"] = "Terminate"
          return (
              client.CustomObjectsApi().patch_namespaced_custom_object(
                  group=self._group,
                  version=self._version,
                  namespace=self._namespace,
                  plural="workflows",
                  name=name,
                  body=body,
              )
          )
      except client.rest.ApiException as e:
          raise ArgoClientException(
              json.loads(e.body)["message"]
              if e.body is not None
              else e.reason
          )
  
imports: import json
  import os
  import sys
  from metaflow.exception import MetaflowException
  from metaflow.plugins.kubernetes.kubernetes_client import KubernetesClient
label_desc: Use image node_id 8 for calling the ArgoClient obj's underlying member method code with example usage: obj.terminate_workflow(name) and returns: client