Mendapatkan detail operasi

Mengambil informasi mendetail tentang suatu operasi.

Mempelajari lebih lanjut

Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:

Contoh kode

Python

Untuk melakukan autentikasi ke VMware Engine, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

from google.cloud import vmwareengine_v1
from google.longrunning.operations_pb2 import GetOperationRequest


def get_operation_by_name(operation_name: str) -> Operation:
    """
    Retrieve detailed information about an operation.

    Args:
        operation_name: name identifying an operation you want to check.
            Expected format: projects/{project_id}/locations/{region}/operations/{operation_id}

    Returns:
        Operation object with details.
    """
    client = vmwareengine_v1.VmwareEngineClient()
    request = GetOperationRequest()
    request.name = operation_name
    return client.get_operation(request)


def get_operation(project_id: str, region: str, operation_id: str) -> Operation:
    """
    Retrieve detailed information about an operation.

    Args:
        project_id: name of the project running the operation.
        region: name of the region in which the operation is running.
        operation_id: identifier of the operation.

    Returns:
        Operation object with details.
    """
    return get_operation_by_name(
        f"projects/{project_id}/locations/{region}/operations/{operation_id}"
    )

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud.