|
14 | 14 | # limitations under the License. |
15 | 15 | # |
16 | 16 | fromcollectionsimportOrderedDict |
| 17 | +importfunctools |
17 | 18 | fromhttpimportHTTPStatus |
18 | 19 | importjson |
19 | 20 | importloggingasstd_logging |
|
36 | 37 |
|
37 | 38 | fromgoogle.api_coreimportclient_optionsasclient_options_lib |
38 | 39 | fromgoogle.api_coreimportexceptionsascore_exceptions |
39 | | -fromgoogle.api_coreimportgapic_v1 |
| 40 | +fromgoogle.api_coreimportextended_operation,gapic_v1 |
40 | 41 | fromgoogle.api_coreimportretryasretries |
41 | 42 | fromgoogle.authimportcredentialsasga_credentials# type: ignore |
42 | 43 | fromgoogle.auth.exceptionsimportMutualTLSChannelError# type: ignore |
|
61 | 62 |
|
62 | 63 | _LOGGER=std_logging.getLogger(__name__) |
63 | 64 |
|
| 65 | +fromgoogle.api_coreimportextended_operation# type: ignore |
| 66 | + |
64 | 67 | fromgoogle.cloud.compute_v1beta.services.reservation_sub_blocksimportpagers |
65 | 68 | fromgoogle.cloud.compute_v1beta.typesimportcompute |
66 | 69 |
|
@@ -992,6 +995,339 @@ def sample_list(): |
992 | 995 | # Done; return the response. |
993 | 996 | returnresponse |
994 | 997 |
|
| 998 | +defperform_maintenance_unary( |
| 999 | +self, |
| 1000 | +request:Optional[ |
| 1001 | +Union[compute.PerformMaintenanceReservationSubBlockRequest,dict] |
| 1002 | + ]=None, |
| 1003 | +*, |
| 1004 | +project:Optional[str]=None, |
| 1005 | +zone:Optional[str]=None, |
| 1006 | +parent_name:Optional[str]=None, |
| 1007 | +reservation_sub_block:Optional[str]=None, |
| 1008 | +retry:OptionalRetry=gapic_v1.method.DEFAULT, |
| 1009 | +timeout:Union[float,object]=gapic_v1.method.DEFAULT, |
| 1010 | +metadata:Sequence[Tuple[str,Union[str,bytes]]]= (), |
| 1011 | + )->compute.Operation: |
| 1012 | +r"""Allows customers to perform maintenance on a |
| 1013 | + reservation subBlock |
| 1014 | +
|
| 1015 | + .. code-block:: python |
| 1016 | +
|
| 1017 | + # This snippet has been automatically generated and should be regarded as a |
| 1018 | + # code template only. |
| 1019 | + # It will require modifications to work: |
| 1020 | + # - It may require correct/in-range values for request initialization. |
| 1021 | + # - It may require specifying regional endpoints when creating the service |
| 1022 | + # client as shown in: |
| 1023 | + # https://googleapis.dev/python/google-api-core/latest/client_options.html |
| 1024 | + from google.cloud import compute_v1beta |
| 1025 | +
|
| 1026 | + def sample_perform_maintenance(): |
| 1027 | + # Create a client |
| 1028 | + client = compute_v1beta.ReservationSubBlocksClient() |
| 1029 | +
|
| 1030 | + # Initialize request argument(s) |
| 1031 | + request = compute_v1beta.PerformMaintenanceReservationSubBlockRequest( |
| 1032 | + parent_name="parent_name_value", |
| 1033 | + project="project_value", |
| 1034 | + reservation_sub_block="reservation_sub_block_value", |
| 1035 | + zone="zone_value", |
| 1036 | + ) |
| 1037 | +
|
| 1038 | + # Make the request |
| 1039 | + response = client.perform_maintenance(request=request) |
| 1040 | +
|
| 1041 | + # Handle the response |
| 1042 | + print(response) |
| 1043 | +
|
| 1044 | + Args: |
| 1045 | + request (Union[google.cloud.compute_v1beta.types.PerformMaintenanceReservationSubBlockRequest, dict]): |
| 1046 | + The request object. A request message for |
| 1047 | + ReservationSubBlocks.PerformMaintenance. |
| 1048 | + See the method description for details. |
| 1049 | + project (str): |
| 1050 | + Project ID for this request. |
| 1051 | + This corresponds to the ``project`` field |
| 1052 | + on the ``request`` instance; if ``request`` is provided, this |
| 1053 | + should not be set. |
| 1054 | + zone (str): |
| 1055 | + Name of the zone for this request. |
| 1056 | + Zone name should conform to RFC1035. |
| 1057 | +
|
| 1058 | + This corresponds to the ``zone`` field |
| 1059 | + on the ``request`` instance; if ``request`` is provided, this |
| 1060 | + should not be set. |
| 1061 | + parent_name (str): |
| 1062 | + The name of the parent reservation and parent block. In |
| 1063 | + the format of |
| 1064 | + reservations/{reservation_name}/reservationBlocks/{reservation_block_name} |
| 1065 | +
|
| 1066 | + This corresponds to the ``parent_name`` field |
| 1067 | + on the ``request`` instance; if ``request`` is provided, this |
| 1068 | + should not be set. |
| 1069 | + reservation_sub_block (str): |
| 1070 | + The name of the reservation subBlock. |
| 1071 | + Name should conform to RFC1035 or be a |
| 1072 | + resource ID. |
| 1073 | +
|
| 1074 | + This corresponds to the ``reservation_sub_block`` field |
| 1075 | + on the ``request`` instance; if ``request`` is provided, this |
| 1076 | + should not be set. |
| 1077 | + retry (google.api_core.retry.Retry): Designation of what errors, if any, |
| 1078 | + should be retried. |
| 1079 | + timeout (float): The timeout for this request. |
| 1080 | + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be |
| 1081 | + sent along with the request as metadata. Normally, each value must be of type `str`, |
| 1082 | + but for metadata keys ending with the suffix `-bin`, the corresponding values must |
| 1083 | + be of type `bytes`. |
| 1084 | +
|
| 1085 | + Returns: |
| 1086 | + google.api_core.extended_operation.ExtendedOperation: |
| 1087 | + An object representing a extended |
| 1088 | + long-running operation. |
| 1089 | +
|
| 1090 | + """ |
| 1091 | +# Create or coerce a protobuf request object. |
| 1092 | +# - Quick check: If we got a request object, we should *not* have |
| 1093 | +# gotten any keyword arguments that map to the request. |
| 1094 | +flattened_params= [project,zone,parent_name,reservation_sub_block] |
| 1095 | +has_flattened_params= ( |
| 1096 | +len([paramforparaminflattened_paramsifparamisnotNone])>0 |
| 1097 | + ) |
| 1098 | +ifrequestisnotNoneandhas_flattened_params: |
| 1099 | +raiseValueError( |
| 1100 | +"If the `request` argument is set, then none of " |
| 1101 | +"the individual field arguments should be set." |
| 1102 | + ) |
| 1103 | + |
| 1104 | +# - Use the request object if provided (there's no risk of modifying the input as |
| 1105 | +# there are no flattened fields), or create one. |
| 1106 | +ifnotisinstance( |
| 1107 | +request,compute.PerformMaintenanceReservationSubBlockRequest |
| 1108 | + ): |
| 1109 | +request=compute.PerformMaintenanceReservationSubBlockRequest(request) |
| 1110 | +# If we have keyword arguments corresponding to fields on the |
| 1111 | +# request, apply these. |
| 1112 | +ifprojectisnotNone: |
| 1113 | +request.project=project |
| 1114 | +ifzoneisnotNone: |
| 1115 | +request.zone=zone |
| 1116 | +ifparent_nameisnotNone: |
| 1117 | +request.parent_name=parent_name |
| 1118 | +ifreservation_sub_blockisnotNone: |
| 1119 | +request.reservation_sub_block=reservation_sub_block |
| 1120 | + |
| 1121 | +# Wrap the RPC method; this adds retry and timeout information, |
| 1122 | +# and friendly error handling. |
| 1123 | +rpc=self._transport._wrapped_methods[self._transport.perform_maintenance] |
| 1124 | + |
| 1125 | +# Certain fields should be provided within the metadata header; |
| 1126 | +# add these here. |
| 1127 | +metadata=tuple(metadata)+ ( |
| 1128 | +gapic_v1.routing_header.to_grpc_metadata( |
| 1129 | + ( |
| 1130 | + ("project",request.project), |
| 1131 | + ("zone",request.zone), |
| 1132 | + ("parent_name",request.parent_name), |
| 1133 | + ("reservation_sub_block",request.reservation_sub_block), |
| 1134 | + ) |
| 1135 | + ), |
| 1136 | + ) |
| 1137 | + |
| 1138 | +# Validate the universe domain. |
| 1139 | +self._validate_universe_domain() |
| 1140 | + |
| 1141 | +# Send the request. |
| 1142 | +response=rpc( |
| 1143 | +request, |
| 1144 | +retry=retry, |
| 1145 | +timeout=timeout, |
| 1146 | +metadata=metadata, |
| 1147 | + ) |
| 1148 | + |
| 1149 | +# Done; return the response. |
| 1150 | +returnresponse |
| 1151 | + |
| 1152 | +defperform_maintenance( |
| 1153 | +self, |
| 1154 | +request:Optional[ |
| 1155 | +Union[compute.PerformMaintenanceReservationSubBlockRequest,dict] |
| 1156 | + ]=None, |
| 1157 | +*, |
| 1158 | +project:Optional[str]=None, |
| 1159 | +zone:Optional[str]=None, |
| 1160 | +parent_name:Optional[str]=None, |
| 1161 | +reservation_sub_block:Optional[str]=None, |
| 1162 | +retry:OptionalRetry=gapic_v1.method.DEFAULT, |
| 1163 | +timeout:Union[float,object]=gapic_v1.method.DEFAULT, |
| 1164 | +metadata:Sequence[Tuple[str,Union[str,bytes]]]= (), |
| 1165 | + )->extended_operation.ExtendedOperation: |
| 1166 | +r"""Allows customers to perform maintenance on a |
| 1167 | + reservation subBlock |
| 1168 | +
|
| 1169 | + .. code-block:: python |
| 1170 | +
|
| 1171 | + # This snippet has been automatically generated and should be regarded as a |
| 1172 | + # code template only. |
| 1173 | + # It will require modifications to work: |
| 1174 | + # - It may require correct/in-range values for request initialization. |
| 1175 | + # - It may require specifying regional endpoints when creating the service |
| 1176 | + # client as shown in: |
| 1177 | + # https://googleapis.dev/python/google-api-core/latest/client_options.html |
| 1178 | + from google.cloud import compute_v1beta |
| 1179 | +
|
| 1180 | + def sample_perform_maintenance(): |
| 1181 | + # Create a client |
| 1182 | + client = compute_v1beta.ReservationSubBlocksClient() |
| 1183 | +
|
| 1184 | + # Initialize request argument(s) |
| 1185 | + request = compute_v1beta.PerformMaintenanceReservationSubBlockRequest( |
| 1186 | + parent_name="parent_name_value", |
| 1187 | + project="project_value", |
| 1188 | + reservation_sub_block="reservation_sub_block_value", |
| 1189 | + zone="zone_value", |
| 1190 | + ) |
| 1191 | +
|
| 1192 | + # Make the request |
| 1193 | + response = client.perform_maintenance(request=request) |
| 1194 | +
|
| 1195 | + # Handle the response |
| 1196 | + print(response) |
| 1197 | +
|
| 1198 | + Args: |
| 1199 | + request (Union[google.cloud.compute_v1beta.types.PerformMaintenanceReservationSubBlockRequest, dict]): |
| 1200 | + The request object. A request message for |
| 1201 | + ReservationSubBlocks.PerformMaintenance. |
| 1202 | + See the method description for details. |
| 1203 | + project (str): |
| 1204 | + Project ID for this request. |
| 1205 | + This corresponds to the ``project`` field |
| 1206 | + on the ``request`` instance; if ``request`` is provided, this |
| 1207 | + should not be set. |
| 1208 | + zone (str): |
| 1209 | + Name of the zone for this request. |
| 1210 | + Zone name should conform to RFC1035. |
| 1211 | +
|
| 1212 | + This corresponds to the ``zone`` field |
| 1213 | + on the ``request`` instance; if ``request`` is provided, this |
| 1214 | + should not be set. |
| 1215 | + parent_name (str): |
| 1216 | + The name of the parent reservation and parent block. In |
| 1217 | + the format of |
| 1218 | + reservations/{reservation_name}/reservationBlocks/{reservation_block_name} |
| 1219 | +
|
| 1220 | + This corresponds to the ``parent_name`` field |
| 1221 | + on the ``request`` instance; if ``request`` is provided, this |
| 1222 | + should not be set. |
| 1223 | + reservation_sub_block (str): |
| 1224 | + The name of the reservation subBlock. |
| 1225 | + Name should conform to RFC1035 or be a |
| 1226 | + resource ID. |
| 1227 | +
|
| 1228 | + This corresponds to the ``reservation_sub_block`` field |
| 1229 | + on the ``request`` instance; if ``request`` is provided, this |
| 1230 | + should not be set. |
| 1231 | + retry (google.api_core.retry.Retry): Designation of what errors, if any, |
| 1232 | + should be retried. |
| 1233 | + timeout (float): The timeout for this request. |
| 1234 | + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be |
| 1235 | + sent along with the request as metadata. Normally, each value must be of type `str`, |
| 1236 | + but for metadata keys ending with the suffix `-bin`, the corresponding values must |
| 1237 | + be of type `bytes`. |
| 1238 | +
|
| 1239 | + Returns: |
| 1240 | + google.api_core.extended_operation.ExtendedOperation: |
| 1241 | + An object representing a extended |
| 1242 | + long-running operation. |
| 1243 | +
|
| 1244 | + """ |
| 1245 | +# Create or coerce a protobuf request object. |
| 1246 | +# - Quick check: If we got a request object, we should *not* have |
| 1247 | +# gotten any keyword arguments that map to the request. |
| 1248 | +flattened_params= [project,zone,parent_name,reservation_sub_block] |
| 1249 | +has_flattened_params= ( |
| 1250 | +len([paramforparaminflattened_paramsifparamisnotNone])>0 |
| 1251 | + ) |
| 1252 | +ifrequestisnotNoneandhas_flattened_params: |
| 1253 | +raiseValueError( |
| 1254 | +"If the `request` argument is set, then none of " |
| 1255 | +"the individual field arguments should be set." |
| 1256 | + ) |
| 1257 | + |
| 1258 | +# - Use the request object if provided (there's no risk of modifying the input as |
| 1259 | +# there are no flattened fields), or create one. |
| 1260 | +ifnotisinstance( |
| 1261 | +request,compute.PerformMaintenanceReservationSubBlockRequest |
| 1262 | + ): |
| 1263 | +request=compute.PerformMaintenanceReservationSubBlockRequest(request) |
| 1264 | +# If we have keyword arguments corresponding to fields on the |
| 1265 | +# request, apply these. |
| 1266 | +ifprojectisnotNone: |
| 1267 | +request.project=project |
| 1268 | +ifzoneisnotNone: |
| 1269 | +request.zone=zone |
| 1270 | +ifparent_nameisnotNone: |
| 1271 | +request.parent_name=parent_name |
| 1272 | +ifreservation_sub_blockisnotNone: |
| 1273 | +request.reservation_sub_block=reservation_sub_block |
| 1274 | + |
| 1275 | +# Wrap the RPC method; this adds retry and timeout information, |
| 1276 | +# and friendly error handling. |
| 1277 | +rpc=self._transport._wrapped_methods[self._transport.perform_maintenance] |
| 1278 | + |
| 1279 | +# Certain fields should be provided within the metadata header; |
| 1280 | +# add these here. |
| 1281 | +metadata=tuple(metadata)+ ( |
| 1282 | +gapic_v1.routing_header.to_grpc_metadata( |
| 1283 | + ( |
| 1284 | + ("project",request.project), |
| 1285 | + ("zone",request.zone), |
| 1286 | + ("parent_name",request.parent_name), |
| 1287 | + ("reservation_sub_block",request.reservation_sub_block), |
| 1288 | + ) |
| 1289 | + ), |
| 1290 | + ) |
| 1291 | + |
| 1292 | +# Validate the universe domain. |
| 1293 | +self._validate_universe_domain() |
| 1294 | + |
| 1295 | +# Send the request. |
| 1296 | +response=rpc( |
| 1297 | +request, |
| 1298 | +retry=retry, |
| 1299 | +timeout=timeout, |
| 1300 | +metadata=metadata, |
| 1301 | + ) |
| 1302 | + |
| 1303 | +operation_service=self._transport._zone_operations_client |
| 1304 | +operation_request=compute.GetZoneOperationRequest() |
| 1305 | +operation_request.project=request.project |
| 1306 | +operation_request.zone=request.zone |
| 1307 | +operation_request.operation=response.name |
| 1308 | + |
| 1309 | +get_operation=functools.partial(operation_service.get,operation_request) |
| 1310 | +# Cancel is not part of extended operations yet. |
| 1311 | +cancel_operation=lambda:None |
| 1312 | + |
| 1313 | +# Note: this class is an implementation detail to provide a uniform |
| 1314 | +# set of names for certain fields in the extended operation proto message. |
| 1315 | +# See google.api_core.extended_operation.ExtendedOperation for details |
| 1316 | +# on these properties and the expected interface. |
| 1317 | +class_CustomOperation(extended_operation.ExtendedOperation): |
| 1318 | +@property |
| 1319 | +deferror_message(self): |
| 1320 | +returnself._extended_operation.http_error_message |
| 1321 | + |
| 1322 | +@property |
| 1323 | +deferror_code(self): |
| 1324 | +returnself._extended_operation.http_error_status_code |
| 1325 | + |
| 1326 | +response=_CustomOperation.make(get_operation,cancel_operation,response) |
| 1327 | + |
| 1328 | +# Done; return the response. |
| 1329 | +returnresponse |
| 1330 | + |
995 | 1331 | def__enter__(self)->"ReservationSubBlocksClient": |
996 | 1332 | returnself |
997 | 1333 |
|
|