class Operation(Generic[
Constructor: Operation(source_method, channel, operation)
A convenience wrapper around operation protobufs.
The Operation wrapper normalizes
nebius.api.nebius.common.v1.Operation
and nebius.api.nebius.common.v1alpha1.Operation representations and
provides helpers to:
- inspect operation metadata (id, resource_id, timestamps),
- poll/update the operation state via the corresponding operation service, and
- wait for completion either asynchronously or synchronously.
The wrapper stores an operation service client bound to a
nebius.aio.constant_channel.Constant that points at the provided
source_method and reuses the provided channel for network/auth
behaviors.
Example
Operation from a service action (e.g., creating a bucket):
from nebius.sdk import SDK
from nebius.aio.cli_config import Config
from nebius.api.nebius.storage.v1 import (
BucketServiceClient,
CreateBucketRequest
)
sdk = SDK(config_reader=Config())
service = BucketServiceClient(sdk)
# Create operation from service action
operation = await service.create(CreateBucketRequest(
# fill-in necessary fields
))
# Wait for completion
await operation.wait()
print(f"New bucket ID: {operation.resource_id}")
Operation from list of operations:
from nebius.sdk import SDK
from nebius.aio.cli_config import Config
from nebius.api.nebius.storage.v1 import BucketServiceClient
from nebius.api.nebius.common.v1 import ListOperationsRequest
sdk = SDK(config_reader=Config())
service = BucketServiceClient(sdk)
# Get operation service client from the bucket service
operation_service = service.operation_service()
operations_response = await operation_service.list(ListOperationsRequest(
# fill-in necessary fields
))
# Get first operation from list
if operations_response.operations:
operation = operations_response.operations[0]
# Manual update
await operation.update()
print(f"Operation status: {operation.status()}")
| Parameters | |
| source | the originating service.method name used to build a constant channel for operation management calls |
| channel | channel used for network and auth operations |
| operation | an operation protobuf instance (v1 or v1alpha1) |
| Method | __init__ |
Create an operation wrapper from the operation protobuf. |
| Method | __repr__ |
Return a compact string representation useful for debugging. |
| Method | done |
Return True when the operation has reached a terminal state. |
| Method | raw |
Return the underlying operation protobuf object. |
| Method | status |
Return the operation's current status object or None. |
| Method | successful |
Return True when the operation completed successfully. |
| Method | sync |
Synchronously perform a single update of the operation state. |
| Method | sync |
Synchronously wait for the operation to complete. |
| Async Method | update |
Fetch the latest operation data from the operation service. |
| Async Method | wait |
Asynchronously wait until the operation reaches a terminal state. |
| Property | created |
Return the operation creation timestamp. |
| Property | created |
Return the identity that created the operation (string). |
| Property | description |
Return the operation description as provided by the service. |
| Property | finished |
Return the completion timestamp for the operation or None if the operation hasn't finished yet. |
| Property | id |
Return the operation identifier (string). |
| Property | resource |
Return the resource id associated with the operation. |
| Method | _set |
Replace the wrapped operation object with a new instance. |
| Instance Variable | _channel |
Undocumented |
| Instance Variable | _get |
Undocumented |
| Instance Variable | _operation |
Undocumented |
| Instance Variable | _service |
Undocumented |
str, channel: ClientChannelInterface, operation: OperationPb):
(source)
¶
Create an operation wrapper from the operation protobuf.
Return the underlying operation protobuf object.
Use this to access version-specific fields that are not exposed by the normalized wrapper.
Synchronously perform a single update of the operation state.
This wraps the coroutine update and runs it via the channel's
synchronous runner. A small safety margin is added to the provided
timeout to allow for scheduling overhead.
| Parameters | |
**kwargs:Unpack[ | additional request keyword arguments
see nebius.aio.request_kwargs.RequestKwargs for details. |
Fetch the latest operation data from the operation service.
This coroutine performs a single get operation using the internal operation service client and replaces the wrapped operation object with the returned value.
| Parameters | |
**kwargs:Unpack[ | additional request keyword arguments
see nebius.aio.request_kwargs.RequestKwargs for details. |
float | timedelta = 1, timeout: float | None = None, poll_iteration_timeout: float | UnsetType | None = Unset, poll_per_retry_timeout: float | UnsetType | None = Unset, poll_retries: int | None = None, **kwargs: Unpack[ RequestKwargsForOperation]):
(source)
¶
Asynchronously wait until the operation reaches a terminal state.
The method repeatedly invokes update at the specified
interval until the operation is done or the overall timeout is
reached. Certain transient errors (deadline exceeded) are treated as
ignorable and will be retried.
| Parameters | |
interval:float or timedelta | polling interval (seconds or timedelta) |
timeout:optional float | overall timeout (seconds) for waiting, or None for
infinite timeout, default infinite. |
pollfloat or None | timeout used for each polling iteration, will be
passed as the timeout to each update call. |
pollfloat or None, will be passed as the
per_retry_timeout to each update call. | per-retry timeout for polling requests, will
be passed as the per_retry_timeout to each update call. |
pollint | None | retry count used for polling requests, will be passed as
the retries to each update call. |
**kwargs:Unpack[ | additional request keyword arguments
see nebius.aio.request_kwargs.RequestKwargsForOperation for
details. |
| Raises | |
TimeoutError | when the overall timeout is exceeded |
Return the operation creation timestamp.
If the underlying protobuf does not expose a creation time this helper returns the current time in the local timezone. :rtype: datetime
Replace the wrapped operation object with a new instance.
The replacement is only allowed when the new operation has the same
protobuf class as the currently wrapped object; otherwise an
SDKError is raised.