@@ -2236,6 +2236,130 @@ def rename_blob(
2236
2236
)
2237
2237
return new_blob
2238
2238
2239
+ @create_trace_span (name = "Storage.Bucket.moveBlob" )
2240
+ def move_blob (
2241
+ self ,
2242
+ blob ,
2243
+ new_name ,
2244
+ client = None ,
2245
+ if_generation_match = None ,
2246
+ if_generation_not_match = None ,
2247
+ if_metageneration_match = None ,
2248
+ if_metageneration_not_match = None ,
2249
+ if_source_generation_match = None ,
2250
+ if_source_generation_not_match = None ,
2251
+ if_source_metageneration_match = None ,
2252
+ if_source_metageneration_not_match = None ,
2253
+ timeout = _DEFAULT_TIMEOUT ,
2254
+ retry = DEFAULT_RETRY_IF_GENERATION_SPECIFIED ,
2255
+ ):
2256
+ """Move a blob to a new name within a single HNS bucket.
2257
+
2258
+ *This feature is currently only supported for HNS (Heirarchical
2259
+ Namespace) buckets.*
2260
+
2261
+ If :attr:`user_project` is set on the bucket, bills the API request to that project.
2262
+
2263
+ :type blob: :class:`google.cloud.storage.blob.Blob`
2264
+ :param blob: The blob to be renamed.
2265
+
2266
+ :type new_name: str
2267
+ :param new_name: The new name for this blob.
2268
+
2269
+ :type client: :class:`~google.cloud.storage.client.Client` or
2270
+ ``NoneType``
2271
+ :param client: (Optional) The client to use. If not passed, falls back
2272
+ to the ``client`` stored on the current bucket.
2273
+
2274
+ :type if_generation_match: int
2275
+ :param if_generation_match:
2276
+ (Optional) See :ref:`using-if-generation-match`
2277
+ Note that the generation to be matched is that of the
2278
+ ``destination`` blob.
2279
+
2280
+ :type if_generation_not_match: int
2281
+ :param if_generation_not_match:
2282
+ (Optional) See :ref:`using-if-generation-not-match`
2283
+ Note that the generation to be matched is that of the
2284
+ ``destination`` blob.
2285
+
2286
+ :type if_metageneration_match: int
2287
+ :param if_metageneration_match:
2288
+ (Optional) See :ref:`using-if-metageneration-match`
2289
+ Note that the metageneration to be matched is that of the
2290
+ ``destination`` blob.
2291
+
2292
+ :type if_metageneration_not_match: int
2293
+ :param if_metageneration_not_match:
2294
+ (Optional) See :ref:`using-if-metageneration-not-match`
2295
+ Note that the metageneration to be matched is that of the
2296
+ ``destination`` blob.
2297
+
2298
+ :type if_source_generation_match: int
2299
+ :param if_source_generation_match:
2300
+ (Optional) Makes the operation conditional on whether the source
2301
+ object's generation matches the given value.
2302
+
2303
+ :type if_source_generation_not_match: int
2304
+ :param if_source_generation_not_match:
2305
+ (Optional) Makes the operation conditional on whether the source
2306
+ object's generation does not match the given value.
2307
+
2308
+ :type if_source_metageneration_match: int
2309
+ :param if_source_metageneration_match:
2310
+ (Optional) Makes the operation conditional on whether the source
2311
+ object's current metageneration matches the given value.
2312
+
2313
+ :type if_source_metageneration_not_match: int
2314
+ :param if_source_metageneration_not_match:
2315
+ (Optional) Makes the operation conditional on whether the source
2316
+ object's current metageneration does not match the given value.
2317
+
2318
+ :type timeout: float or tuple
2319
+ :param timeout:
2320
+ (Optional) The amount of time, in seconds, to wait
2321
+ for the server response. See: :ref:`configuring_timeouts`
2322
+
2323
+ :type retry: google.api_core.retry.Retry
2324
+ :param retry:
2325
+ (Optional) How to retry the RPC.
2326
+ See [Configuring Retries](https://cloud.google.com/python/docs/reference/storage/latest/retry_timeout).
2327
+
2328
+ :rtype: :class:`Blob`
2329
+ :returns: The newly-moved blob.
2330
+ """
2331
+ client = self ._require_client (client )
2332
+ query_params = {}
2333
+
2334
+ if self .user_project is not None :
2335
+ query_params ["userProject" ] = self .user_project
2336
+
2337
+ _add_generation_match_parameters (
2338
+ query_params ,
2339
+ if_generation_match = if_generation_match ,
2340
+ if_generation_not_match = if_generation_not_match ,
2341
+ if_metageneration_match = if_metageneration_match ,
2342
+ if_metageneration_not_match = if_metageneration_not_match ,
2343
+ if_source_generation_match = if_source_generation_match ,
2344
+ if_source_generation_not_match = if_source_generation_not_match ,
2345
+ if_source_metageneration_match = if_source_metageneration_match ,
2346
+ if_source_metageneration_not_match = if_source_metageneration_not_match ,
2347
+ )
2348
+
2349
+ new_blob = Blob (bucket = self , name = new_name )
2350
+ api_path = blob .path + "/moveTo/o/" + new_blob .name
2351
+ move_result = client ._post_resource (
2352
+ api_path ,
2353
+ None ,
2354
+ query_params = query_params ,
2355
+ timeout = timeout ,
2356
+ retry = retry ,
2357
+ _target_object = new_blob ,
2358
+ )
2359
+
2360
+ new_blob ._set_properties (move_result )
2361
+ return new_blob
2362
+
2239
2363
@create_trace_span (name = "Storage.Bucket.restore_blob" )
2240
2364
def restore_blob (
2241
2365
self ,
0 commit comments