|
61 | 61 | from google.iam.v1 import policy_pb2 # type: ignore |
62 | 62 | from google.longrunning import operations_pb2 |
63 | 63 | from google.protobuf import empty_pb2 # type: ignore |
| 64 | +from google.protobuf import field_mask_pb2 # type: ignore |
64 | 65 | from google.protobuf import timestamp_pb2 # type: ignore |
65 | 66 | from google.rpc import status_pb2 # type: ignore |
66 | 67 | from .transports.base import PersistentResourceServiceTransport, DEFAULT_CLIENT_INFO |
@@ -999,6 +1000,149 @@ def sample_delete_persistent_resource(): |
999 | 1000 | # Done; return the response. |
1000 | 1001 | return response |
1001 | 1002 |
|
| 1003 | + def update_persistent_resource( |
| 1004 | + self, |
| 1005 | + request: Optional[ |
| 1006 | + Union[persistent_resource_service.UpdatePersistentResourceRequest, dict] |
| 1007 | + ] = None, |
| 1008 | + *, |
| 1009 | + persistent_resource: Optional[ |
| 1010 | + gca_persistent_resource.PersistentResource |
| 1011 | + ] = None, |
| 1012 | + update_mask: Optional[field_mask_pb2.FieldMask] = None, |
| 1013 | + retry: OptionalRetry = gapic_v1.method.DEFAULT, |
| 1014 | + timeout: Union[float, object] = gapic_v1.method.DEFAULT, |
| 1015 | + metadata: Sequence[Tuple[str, str]] = (), |
| 1016 | + ) -> gac_operation.Operation: |
| 1017 | + r"""Updates a PersistentResource. |
| 1018 | +
|
| 1019 | + .. code-block:: python |
| 1020 | +
|
| 1021 | + # This snippet has been automatically generated and should be regarded as a |
| 1022 | + # code template only. |
| 1023 | + # It will require modifications to work: |
| 1024 | + # - It may require correct/in-range values for request initialization. |
| 1025 | + # - It may require specifying regional endpoints when creating the service |
| 1026 | + # client as shown in: |
| 1027 | + # https://googleapis.dev/python/google-api-core/latest/client_options.html |
| 1028 | + from google.cloud import aiplatform_v1beta1 |
| 1029 | +
|
| 1030 | + def sample_update_persistent_resource(): |
| 1031 | + # Create a client |
| 1032 | + client = aiplatform_v1beta1.PersistentResourceServiceClient() |
| 1033 | +
|
| 1034 | + # Initialize request argument(s) |
| 1035 | + request = aiplatform_v1beta1.UpdatePersistentResourceRequest( |
| 1036 | + ) |
| 1037 | +
|
| 1038 | + # Make the request |
| 1039 | + operation = client.update_persistent_resource(request=request) |
| 1040 | +
|
| 1041 | + print("Waiting for operation to complete...") |
| 1042 | +
|
| 1043 | + response = operation.result() |
| 1044 | +
|
| 1045 | + # Handle the response |
| 1046 | + print(response) |
| 1047 | +
|
| 1048 | + Args: |
| 1049 | + request (Union[google.cloud.aiplatform_v1beta1.types.UpdatePersistentResourceRequest, dict]): |
| 1050 | + The request object. Request message for |
| 1051 | + UpdatePersistentResource method. |
| 1052 | + persistent_resource (google.cloud.aiplatform_v1beta1.types.PersistentResource): |
| 1053 | + Required. The PersistentResource to update. |
| 1054 | +
|
| 1055 | + The PersistentResource's ``name`` field is used to |
| 1056 | + identify the PersistentResource to update. Format: |
| 1057 | + ``projects/{project}/locations/{location}/persistentResources/{persistent_resource}`` |
| 1058 | +
|
| 1059 | + This corresponds to the ``persistent_resource`` field |
| 1060 | + on the ``request`` instance; if ``request`` is provided, this |
| 1061 | + should not be set. |
| 1062 | + update_mask (google.protobuf.field_mask_pb2.FieldMask): |
| 1063 | + Required. Specify the fields to be |
| 1064 | + overwritten in the PersistentResource by |
| 1065 | + the update method. |
| 1066 | +
|
| 1067 | + This corresponds to the ``update_mask`` field |
| 1068 | + on the ``request`` instance; if ``request`` is provided, this |
| 1069 | + should not be set. |
| 1070 | + retry (google.api_core.retry.Retry): Designation of what errors, if any, |
| 1071 | + should be retried. |
| 1072 | + timeout (float): The timeout for this request. |
| 1073 | + metadata (Sequence[Tuple[str, str]]): Strings which should be |
| 1074 | + sent along with the request as metadata. |
| 1075 | +
|
| 1076 | + Returns: |
| 1077 | + google.api_core.operation.Operation: |
| 1078 | + An object representing a long-running operation. |
| 1079 | +
|
| 1080 | + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.PersistentResource` Represents long-lasting resources that are dedicated to users to runs custom |
| 1081 | + workloads. A PersistentResource can have multiple |
| 1082 | + node pools and each node pool can have its own |
| 1083 | + machine spec. |
| 1084 | +
|
| 1085 | + """ |
| 1086 | + # Create or coerce a protobuf request object. |
| 1087 | + # Quick check: If we got a request object, we should *not* have |
| 1088 | + # gotten any keyword arguments that map to the request. |
| 1089 | + has_flattened_params = any([persistent_resource, update_mask]) |
| 1090 | + if request is not None and has_flattened_params: |
| 1091 | + raise ValueError( |
| 1092 | + "If the `request` argument is set, then none of " |
| 1093 | + "the individual field arguments should be set." |
| 1094 | + ) |
| 1095 | + |
| 1096 | + # Minor optimization to avoid making a copy if the user passes |
| 1097 | + # in a persistent_resource_service.UpdatePersistentResourceRequest. |
| 1098 | + # There's no risk of modifying the input as we've already verified |
| 1099 | + # there are no flattened fields. |
| 1100 | + if not isinstance( |
| 1101 | + request, persistent_resource_service.UpdatePersistentResourceRequest |
| 1102 | + ): |
| 1103 | + request = persistent_resource_service.UpdatePersistentResourceRequest( |
| 1104 | + request |
| 1105 | + ) |
| 1106 | + # If we have keyword arguments corresponding to fields on the |
| 1107 | + # request, apply these. |
| 1108 | + if persistent_resource is not None: |
| 1109 | + request.persistent_resource = persistent_resource |
| 1110 | + if update_mask is not None: |
| 1111 | + request.update_mask = update_mask |
| 1112 | + |
| 1113 | + # Wrap the RPC method; this adds retry and timeout information, |
| 1114 | + # and friendly error handling. |
| 1115 | + rpc = self._transport._wrapped_methods[ |
| 1116 | + self._transport.update_persistent_resource |
| 1117 | + ] |
| 1118 | + |
| 1119 | + # Certain fields should be provided within the metadata header; |
| 1120 | + # add these here. |
| 1121 | + metadata = tuple(metadata) + ( |
| 1122 | + gapic_v1.routing_header.to_grpc_metadata( |
| 1123 | + (("persistent_resource.name", request.persistent_resource.name),) |
| 1124 | + ), |
| 1125 | + ) |
| 1126 | + |
| 1127 | + # Send the request. |
| 1128 | + response = rpc( |
| 1129 | + request, |
| 1130 | + retry=retry, |
| 1131 | + timeout=timeout, |
| 1132 | + metadata=metadata, |
| 1133 | + ) |
| 1134 | + |
| 1135 | + # Wrap the response in an operation future. |
| 1136 | + response = gac_operation.from_gapic( |
| 1137 | + response, |
| 1138 | + self._transport.operations_client, |
| 1139 | + gca_persistent_resource.PersistentResource, |
| 1140 | + metadata_type=persistent_resource_service.UpdatePersistentResourceOperationMetadata, |
| 1141 | + ) |
| 1142 | + |
| 1143 | + # Done; return the response. |
| 1144 | + return response |
| 1145 | + |
1002 | 1146 | def __enter__(self) -> "PersistentResourceServiceClient": |
1003 | 1147 | return self |
1004 | 1148 |
|
|
0 commit comments