code: def cloud_work_stage_to_work_status_stage(
      stage: V1LightningworkState,
  ) -> str:
      """Maps the Work stage names from the cloud backend to the status names in the Lightning framework."""
      mapping = {
          V1LightningworkState.STOPPED: WorkStageStatus.STOPPED,
          V1LightningworkState.PENDING: WorkStageStatus.PENDING,
          V1LightningworkState.NOT_STARTED: WorkStageStatus.PENDING,
          V1LightningworkState.IMAGE_BUILDING: WorkStageStatus.PENDING,
          V1LightningworkState.RUNNING: WorkStageStatus.RUNNING,
          V1LightningworkState.FAILED: WorkStageStatus.FAILED,
      }
      if stage not in mapping:
          raise ValueError(
              f"Cannot map the lightning-cloud work state {stage} to the lightning status stage."
          )
      return mapping[stage]
  
imports: import inspect
  import json
  import logging
  import os
  import random
  import string
  import urllib
  from time import monotonic, sleep, time
  from typing import List, Optional
  from lightning_cloud.openapi import AppinstancesIdBody, Externalv1LightningappInstance, Externalv1Lightningwork, V1BuildSpec, V1Drive, V1DriveSpec, V1DriveStatus, V1DriveType, V1Flowserver, V1LightningappInstanceState, V1LightningappRestartPolicy, V1LightningworkClusterDriver, V1LightningworkDrives, V1LightningworkSpec, V1LightningworkState, V1ListLightningworkResponse, V1Metadata, V1NetworkConfig, V1PackageManager, V1PythonDependencyInfo, V1SourceType, V1UserRequestedComputeConfig
  from lightning_cloud.openapi.rest import ApiException
  from lightning.app.core import LightningApp, LightningWork
  from lightning.app.core.queues import QueuingSystem
  from lightning.app.runners.backends.backend import Backend
  from lightning.app.storage import Drive, Mount
  from lightning.app.utilities.enum import WorkStageStatus, WorkStopReasons, make_status
  from lightning.app.utilities.exceptions import LightningPlatformException
  from lightning.app.utilities.network import LightningClient, _check_service_url_is_ready
  from lightning_cloud.openapi import SpecLightningappInstanceIdWorksBody, WorksIdBody
label_desc: Use image node_id 1 for calling a global function with example usage: cloud_work_stage_to_work_status_stage(stage) and returns: mapping