|
15 | 15 |
|
16 | 16 | # Code generated by the Google Gen AI SDK generator DO NOT EDIT. |
17 | 17 |
|
| 18 | +import functools |
18 | 19 | import json |
19 | 20 | import logging |
20 | | -from typing import Any, Optional, Union |
| 21 | +from typing import Any, Iterator, Optional, Union |
21 | 22 | from urllib.parse import urlencode |
22 | 23 |
|
23 | 24 | from google.genai import _api_module |
24 | 25 | from google.genai import _common |
25 | 26 | from google.genai._common import get_value_by_path as getv |
26 | 27 | from google.genai._common import set_value_by_path as setv |
| 28 | +from google.genai.pagers import Pager |
27 | 29 |
|
| 30 | +from . import _agent_engines_utils |
28 | 31 | from . import types |
29 | 32 |
|
30 | 33 | logger = logging.getLogger("vertexai_genai.sandboxsnapshots") |
31 | 34 |
|
| 35 | +logger.setLevel(logging.INFO) |
| 36 | + |
32 | 37 |
|
33 | 38 | def _CreateAgentEngineSandboxSnapshotConfig_to_vertex( |
34 | 39 | from_object: Union[dict[str, Any], object], |
@@ -144,14 +149,21 @@ def _ListSandboxEnvironmentSnapshotsRequestParameters_to_vertex( |
144 | 149 | class SandboxSnapshots(_api_module.BaseModule): |
145 | 150 | """Sandbox environment snapshot commands.""" |
146 | 151 |
|
147 | | - def create( |
| 152 | + def _create( |
148 | 153 | self, |
149 | 154 | *, |
150 | 155 | source_sandbox_environment_name: str, |
151 | 156 | config: Optional[types.CreateAgentEngineSandboxSnapshotConfigOrDict] = None, |
152 | 157 | ) -> types.AgentEngineSandboxSnapshotOperation: |
153 | 158 | """ |
154 | | - Snapshots a sandbox environment. |
| 159 | + Snapshots an existing sandbox environment. |
| 160 | +
|
| 161 | + Args: |
| 162 | + source_sandbox_environment_name (str): |
| 163 | + Required. The name of the sandbox environment to snapshot. |
| 164 | + projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironments/{sandbox_environment_id} |
| 165 | + config (CreateAgentEngineSandboxSnapshotConfig): |
| 166 | + Optional. The configuration for the sandbox snapshot. |
155 | 167 |
|
156 | 168 | """ |
157 | 169 |
|
@@ -219,7 +231,7 @@ def create( |
219 | 231 | self._api_client._verify_response(return_value) |
220 | 232 | return return_value |
221 | 233 |
|
222 | | - def delete( |
| 234 | + def _delete( |
223 | 235 | self, |
224 | 236 | *, |
225 | 237 | name: str, |
@@ -294,7 +306,7 @@ def delete( |
294 | 306 | self._api_client._verify_response(return_value) |
295 | 307 | return return_value |
296 | 308 |
|
297 | | - def get( |
| 309 | + def _get( |
298 | 310 | self, |
299 | 311 | *, |
300 | 312 | name: str, |
@@ -369,7 +381,7 @@ def get( |
369 | 381 | self._api_client._verify_response(return_value) |
370 | 382 | return return_value |
371 | 383 |
|
372 | | - def list( |
| 384 | + def _list( |
373 | 385 | self, |
374 | 386 | *, |
375 | 387 | name: str, |
@@ -444,7 +456,7 @@ def list( |
444 | 456 | self._api_client._verify_response(return_value) |
445 | 457 | return return_value |
446 | 458 |
|
447 | | - def _get_sandbox_snapshot_operation( |
| 459 | + def get_sandbox_snapshot_operation( |
448 | 460 | self, |
449 | 461 | *, |
450 | 462 | operation_name: str, |
@@ -514,18 +526,126 @@ def _get_sandbox_snapshot_operation( |
514 | 526 | self._api_client._verify_response(return_value) |
515 | 527 | return return_value |
516 | 528 |
|
| 529 | + def create( |
| 530 | + self, |
| 531 | + *, |
| 532 | + source_sandbox_environment_name: str, |
| 533 | + config: Optional[types.CreateAgentEngineSandboxSnapshotConfigOrDict] = None, |
| 534 | + poll_interval_seconds: float = 0.1, |
| 535 | + ) -> types.AgentEngineSandboxSnapshotOperation: |
| 536 | + """Snapshots an existing sandbox environment. |
| 537 | +
|
| 538 | + Args: |
| 539 | + source_sandbox_environment_name (str): |
| 540 | + Required. The name of the sandbox environment to snapshot. |
| 541 | + projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironments/{sandbox_environment_id} |
| 542 | + config (CreateAgentEngineSandboxSnapshotConfig): |
| 543 | + Optional. The configuration for the sandbox snapshot. |
| 544 | + poll_interval_seconds (int): |
| 545 | + Optional. Seconds to wait between polling for operation status. Defaults to 0.1. |
| 546 | +
|
| 547 | + Returns: |
| 548 | + AgentEngineSandboxSnapshotOperation: The operation for creating the sandbox snapshot. |
| 549 | + """ |
| 550 | + operation = self._create( |
| 551 | + source_sandbox_environment_name=source_sandbox_environment_name, |
| 552 | + config=config, |
| 553 | + ) |
| 554 | + if config is None: |
| 555 | + config = types.CreateAgentEngineSandboxSnapshotConfig() |
| 556 | + elif isinstance(config, dict): |
| 557 | + config = types.CreateAgentEngineSandboxSnapshotConfig.model_validate(config) |
| 558 | + if config.wait_for_completion: |
| 559 | + if not operation.done: |
| 560 | + operation = _agent_engines_utils._await_operation( |
| 561 | + operation_name=operation.name, |
| 562 | + get_operation_fn=self.get_sandbox_snapshot_operation, |
| 563 | + poll_interval_seconds=poll_interval_seconds, |
| 564 | + ) |
| 565 | + # We need to make a call to get the sandbox snapshot because the operation |
| 566 | + # response might not contain the relevant fields. |
| 567 | + if not operation.response: |
| 568 | + raise ValueError("Error retrieving sandbox snapshot.") |
| 569 | + operation.response = self.get(name=operation.response.name) |
| 570 | + return operation |
| 571 | + |
| 572 | + def list( |
| 573 | + self, |
| 574 | + *, |
| 575 | + name: str, |
| 576 | + config: Optional[types.ListSandboxEnvironmentSnapshotsConfigOrDict] = None, |
| 577 | + ) -> Iterator[types.SandboxEnvironmentSnapshot]: |
| 578 | + """Lists Agent Engine sandbox snapshots. |
| 579 | +
|
| 580 | + Args: |
| 581 | + name (str): |
| 582 | + Required. The name of the agent engine to list sandbox snapshots for. |
| 583 | + projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{sandbox_snapshot_id} |
| 584 | + config (ListSandboxEnvironmentSnapshotsConfig): |
| 585 | + Optional. The configuration for the sandbox snapshots to list. |
| 586 | +
|
| 587 | + Returns: |
| 588 | + Iterable[SandboxEnvironmentSnapshot]: An iterable of agent engine sandbox snapshots. |
| 589 | + """ |
| 590 | + return Pager( |
| 591 | + "sandbox_environment_snapshots", |
| 592 | + functools.partial(self._list, name=name), |
| 593 | + self._list(name=name, config=config), |
| 594 | + config, |
| 595 | + ) |
| 596 | + |
| 597 | + def get( |
| 598 | + self, |
| 599 | + *, |
| 600 | + name: str, |
| 601 | + config: Optional[types.GetSandboxEnvironmentSnapshotConfigOrDict] = None, |
| 602 | + ) -> types.SandboxEnvironmentSnapshot: |
| 603 | + """Gets a sandbox snapshot in the Agent Engine. |
| 604 | + Args: |
| 605 | + name (str): |
| 606 | + Required. A fully-qualified resource name or ID such as |
| 607 | + projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{snapshot_id} |
| 608 | + or a shortened name such as "reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{snapshot_id}". |
| 609 | + config (GetSandboxEnvironmentSnapshotConfigOrDict): |
| 610 | + Optional. The configuration for the sandbox snapshot to get. |
| 611 | + """ |
| 612 | + return self._get(name=name, config=config) |
| 613 | + |
| 614 | + def delete( |
| 615 | + self, |
| 616 | + *, |
| 617 | + name: str, |
| 618 | + config: Optional[types.DeleteSandboxEnvironmentSnapshotConfigOrDict] = None, |
| 619 | + ) -> types.DeleteSandboxEnvironmentSnapshotOperation: |
| 620 | + """Deletes a sandbox snapshot in the Agent Engine. |
| 621 | + Args: |
| 622 | + name (str): |
| 623 | + Required. The name of the sandbox snapshot to delete. |
| 624 | + Format: projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironmentSnapshots/{snapshot_id} |
| 625 | + config (DeleteSandboxEnvironmentSnapshotConfigOrDict): |
| 626 | + Optional. Configuration for the delete operation. |
| 627 | + """ |
| 628 | + return self._delete(name=name, config=config) |
| 629 | + |
517 | 630 |
|
518 | 631 | class AsyncSandboxSnapshots(_api_module.BaseModule): |
519 | 632 | """Sandbox environment snapshot commands.""" |
520 | 633 |
|
521 | | - async def create( |
| 634 | + async def _create( |
522 | 635 | self, |
523 | 636 | *, |
524 | 637 | source_sandbox_environment_name: str, |
525 | 638 | config: Optional[types.CreateAgentEngineSandboxSnapshotConfigOrDict] = None, |
526 | 639 | ) -> types.AgentEngineSandboxSnapshotOperation: |
527 | 640 | """ |
528 | | - Snapshots a sandbox environment. |
| 641 | + Snapshots an existing sandbox environment. |
| 642 | +
|
| 643 | + Args: |
| 644 | + source_sandbox_environment_name (str): |
| 645 | + Required. The name of the sandbox environment to snapshot. |
| 646 | + projects/{project}/locations/{location}/reasoningEngines/{resource_id}/sandboxEnvironments/{sandbox_environment_id} |
| 647 | + config (CreateAgentEngineSandboxSnapshotConfig): |
| 648 | + Optional. The configuration for the sandbox snapshot. |
529 | 649 |
|
530 | 650 | """ |
531 | 651 |
|
@@ -595,7 +715,7 @@ async def create( |
595 | 715 | self._api_client._verify_response(return_value) |
596 | 716 | return return_value |
597 | 717 |
|
598 | | - async def delete( |
| 718 | + async def _delete( |
599 | 719 | self, |
600 | 720 | *, |
601 | 721 | name: str, |
@@ -672,7 +792,7 @@ async def delete( |
672 | 792 | self._api_client._verify_response(return_value) |
673 | 793 | return return_value |
674 | 794 |
|
675 | | - async def get( |
| 795 | + async def _get( |
676 | 796 | self, |
677 | 797 | *, |
678 | 798 | name: str, |
@@ -749,7 +869,7 @@ async def get( |
749 | 869 | self._api_client._verify_response(return_value) |
750 | 870 | return return_value |
751 | 871 |
|
752 | | - async def list( |
| 872 | + async def _list( |
753 | 873 | self, |
754 | 874 | *, |
755 | 875 | name: str, |
@@ -826,7 +946,7 @@ async def list( |
826 | 946 | self._api_client._verify_response(return_value) |
827 | 947 | return return_value |
828 | 948 |
|
829 | | - async def _get_sandbox_snapshot_operation( |
| 949 | + async def get_sandbox_snapshot_operation( |
830 | 950 | self, |
831 | 951 | *, |
832 | 952 | operation_name: str, |
|
0 commit comments