| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import logging |
| 4 |
import time |
| 5 |
import typing as t |
| 6 |
import uuid |
| 7 |
|
| 8 |
from globus_sdk import client, exc, paging, response |
| 9 |
from globus_sdk._internal import guards |
| 10 |
from globus_sdk._internal.remarshal import commajoin |
| 11 |
from globus_sdk._internal.type_definitions import DateLike, IntLike |
| 12 |
from globus_sdk._missing import MISSING, MissingType |
| 13 |
from globus_sdk.response import IterableJSONAPIResponse |
| 14 |
from globus_sdk.scopes import GCSCollectionScopes, Scope, TransferScopes |
| 15 |
from globus_sdk.transport import RetryConfig |
| 16 |
|
| 17 |
from .data import CreateTunnelData, DeleteData, TransferData |
| 18 |
from .errors import TransferAPIError |
| 19 |
from .response import IterableTransferResponse |
| 20 |
from .transport import TRANSFER_DEFAULT_RETRY_CHECKS |
| 21 |
|
| 22 |
log = logging.getLogger(__name__) |
| 23 |
|
| 24 |
TransferFilterDict = t.Dict[str, t.Union[str, t.List[str]]] |
| 25 |
|
| 26 |
|
| 27 |
def _datelike_to_str(x: DateLike) -> str: |
| 28 |
return x if isinstance(x, str) else x.isoformat(timespec="seconds") |
| 29 |
|
| 30 |
|
| 31 |
def _format_completion_time( |
| 32 |
x: str | tuple[DateLike, DateLike] | MissingType, |
| 33 |
) -> str | MissingType: |
| 34 |
if x is MISSING: |
| 35 |
return MISSING |
| 36 |
elif isinstance(x, str): |
| 37 |
return x |
| 38 |
else: |
| 39 |
start_t, end_t = x |
| 40 |
start_t, end_t = _datelike_to_str(start_t), _datelike_to_str(end_t) |
| 41 |
return f"{start_t},{end_t}" |
| 42 |
|
| 43 |
|
| 44 |
@t.overload |
| 45 |
def _format_filter_item(x: str | TransferFilterDict) -> str: ... |
| 46 |
|
| 47 |
|
| 48 |
@t.overload |
| 49 |
def _format_filter_item(x: MissingType) -> MissingType: ... |
| 50 |
|
| 51 |
|
| 52 |
def _format_filter_item(x: str | TransferFilterDict | MissingType) -> str | MissingType: |
| 53 |
if x is MISSING: |
| 54 |
return MISSING |
| 55 |
elif isinstance(x, str): |
| 56 |
return x |
| 57 |
return "/".join(f"{k}:{commajoin(v)}" for k, v in x.items()) |
| 58 |
|
| 59 |
|
| 60 |
def _format_filter( |
| 61 |
x: str | TransferFilterDict | list[str | TransferFilterDict] | MissingType, |
| 62 |
) -> str | list[str] | MissingType: |
| 63 |
if isinstance(x, list): |
| 64 |
return [_format_filter_item(y) for y in x] |
| 65 |
return _format_filter_item(x) |
| 66 |
|
| 67 |
|
| 68 |
def _get_page_size(paged_result: IterableTransferResponse) -> int: |
| 69 |
return len(paged_result["DATA"]) |
| 70 |
|
| 71 |
|
| 72 |
class TransferClient(client.BaseClient): |
| 73 |
r""" |
| 74 |
Client for the |
| 75 |
`Globus Transfer API <https://docs.globus.org/api/transfer/>`_. |
| 76 |
|
| 77 |
.. sdk-sphinx-copy-params:: BaseClient |
| 78 |
|
| 79 |
This class provides helper methods for most common resources in the |
| 80 |
REST API, and basic ``get``, ``put``, ``post``, and ``delete`` methods |
| 81 |
from the base rest client that can be used to access any REST resource. |
| 82 |
|
| 83 |
Detailed documentation is available in the official REST API |
| 84 |
documentation, which is linked to from the method documentation. Methods |
| 85 |
that allow arbitrary keyword arguments will pass the extra arguments as |
| 86 |
query parameters. |
| 87 |
|
| 88 |
.. _transfer_filter_formatting: |
| 89 |
|
| 90 |
**Filter Formatting** |
| 91 |
|
| 92 |
Several methods of ``TransferClient`` take a ``filter`` parameter which can be a |
| 93 |
string, dict, or list of strings/dicts. When the filter given is a string, it is |
| 94 |
passed as a single unmodified param. When the filter given is a dict, it is |
| 95 |
formatted according to the below rules into a single param. When the filter is a |
| 96 |
list, each item of the list is parsed and passed as separate params. |
| 97 |
|
| 98 |
dict parsing rules: |
| 99 |
|
| 100 |
- each (key, value) pair in the dict is a clause in the resulting filter string |
| 101 |
- clauses are each formatted to ``key:value`` |
| 102 |
- when the value is a list, it is comma-separated, as in ``key:value1,value2`` |
| 103 |
- clauses are separated with slashes, as in ``key1:value1/key2:value2`` |
| 104 |
|
| 105 |
The corresponding external API documentation describes, in detail, the supported |
| 106 |
filter clauses for each method which uses the ``filter`` parameter. |
| 107 |
Generally, speaking, filter clauses documented as ``string list`` can be passed as |
| 108 |
lists to a filter dict, while string, date, and numeric filters should be passed as |
| 109 |
strings. |
| 110 |
|
| 111 |
**Paginated Calls** |
| 112 |
|
| 113 |
Methods which support pagination can be called as paginated or unpaginated methods. |
| 114 |
If the method name is ``TransferClient.foo``, the paginated version is |
| 115 |
``TransferClient.paginated.foo``. |
| 116 |
Using ``TransferClient.endpoint_search`` as an example:: |
| 117 |
|
| 118 |
from globus_sdk import TransferClient |
| 119 |
tc = TransferClient(...) |
| 120 |
|
| 121 |
# this is the unpaginated version |
| 122 |
for x in tc.endpoint_search("tutorial"): |
| 123 |
print("Endpoint ID: {}".format(x["id"])) |
| 124 |
|
| 125 |
# this is the paginated version |
| 126 |
for page in tc.paginated.endpoint_search("testdata"): |
| 127 |
for x in page: |
| 128 |
print("Endpoint ID: {}".format(x["id"])) |
| 129 |
|
| 130 |
.. automethodlist:: globus_sdk.TransferClient |
| 131 |
""" |
| 132 |
|
| 133 |
service_name = "transfer" |
| 134 |
error_class = TransferAPIError |
| 135 |
scopes = TransferScopes |
| 136 |
default_scope_requirements = [TransferScopes.all] |
| 137 |
|
| 138 |
def _register_standard_retry_checks(self, retry_config: RetryConfig) -> None: |
| 139 |
"""Override the default retry checks.""" |
| 140 |
retry_config.checks.register_many_checks(TRANSFER_DEFAULT_RETRY_CHECKS) |
| 141 |
|
| 142 |
def add_app_data_access_scope( |
| 143 |
self, collection_ids: uuid.UUID | str | t.Iterable[uuid.UUID | str] |
| 144 |
) -> TransferClient: |
| 145 |
""" |
| 146 |
Add a dependent ``data_access`` scope for one or more given ``collection_ids`` |
| 147 |
to this client's ``GlobusApp``. Useful for resolving ``ConsentRequired`` errors |
| 148 |
when using standard Globus Connect Server mapped collections. |
| 149 |
|
| 150 |
.. warning:: |
| 151 |
|
| 152 |
This method must only be used on ``collection_ids`` for non-High-Assurance |
| 153 |
GCS Mapped Collections. |
| 154 |
|
| 155 |
Use on other collection types, e.g., on GCP Mapped Collections or any form |
| 156 |
of Guest Collection, will result in "Unknown Scope" errors during the login |
| 157 |
flow. |
| 158 |
|
| 159 |
Returns ``self`` for chaining. |
| 160 |
|
| 161 |
Raises ``GlobusSDKUsageError`` if this client was not initialized with an app. |
| 162 |
|
| 163 |
:param collection_ids: a collection ID or an iterable of IDs. |
| 164 |
|
| 165 |
.. tab-set:: |
| 166 |
|
| 167 |
.. tab-item:: Example Usage |
| 168 |
|
| 169 |
Usage for ``ls`` or a similar operation which points at a single |
| 170 |
collection: |
| 171 |
|
| 172 |
.. code-block:: python |
| 173 |
|
| 174 |
app = UserApp("myapp", client_id=NATIVE_APP_CLIENT_ID) |
| 175 |
client = TransferClient(app=app).add_app_data_access_scope(COLLECTION_ID) |
| 176 |
|
| 177 |
res = client.operation_ls(COLLECTION_ID) |
| 178 |
|
| 179 |
Usage for ``submit_transfer`` or a similar operation which points at |
| 180 |
multiple collections: |
| 181 |
|
| 182 |
.. code-block:: python |
| 183 |
|
| 184 |
app = UserApp("myapp", client_id=NATIVE_APP_CLIENT_ID) |
| 185 |
client = TransferClient(app=app).add_app_data_access_scope( |
| 186 |
(COLLECTION_ID_1, COLLECTION_ID_2) |
| 187 |
) |
| 188 |
|
| 189 |
transfer_data = TransferData( |
| 190 |
source_endpoint=COLLECTION_ID_1, |
| 191 |
destination_endpoint=COLLECTION_ID_2, |
| 192 |
) |
| 193 |
transfer_data.add_item("/foo", "bar/baz") |
| 194 |
... |
| 195 |
res = client.submit_transfer({}) |
| 196 |
""" # noqa: E501 |
| 197 |
if isinstance(collection_ids, (str, uuid.UUID)): |
| 198 |
guards.validators.uuidlike("collection_ids", collection_ids) |
| 199 |
# wrap the collection_ids input in a list for consistent iteration below |
| 200 |
collection_ids_ = [collection_ids] |
| 201 |
else: |
| 202 |
# copy to a list so that ephemeral iterables can be iterated multiple times |
| 203 |
collection_ids_ = list(collection_ids) |
| 204 |
for i, c in enumerate(collection_ids_): |
| 205 |
guards.validators.uuidlike(f"collection_ids[{i}]", c) |
| 206 |
|
| 207 |
scope = TransferScopes.all |
| 208 |
dependencies: list[Scope] = [] |
| 209 |
for coll_id in collection_ids_: |
| 210 |
data_access_scope = GCSCollectionScopes( |
| 211 |
str(coll_id) |
| 212 |
).data_access.with_optional(True) |
| 213 |
dependencies.append(data_access_scope) |
| 214 |
scope = scope.with_dependencies(dependencies) |
| 215 |
self.add_app_scope(scope) |
| 216 |
return self |
| 217 |
|
| 218 |
# Convenience methods, providing more pythonic access to common REST |
| 219 |
# resources |
| 220 |
|
| 221 |
# |
| 222 |
# Endpoint Management |
| 223 |
# |
| 224 |
|
| 225 |
def get_endpoint( |
| 226 |
self, |
| 227 |
endpoint_id: uuid.UUID | str, |
| 228 |
*, |
| 229 |
query_params: dict[str, t.Any] | None = None, |
| 230 |
) -> response.GlobusHTTPResponse: |
| 231 |
""" |
| 232 |
:param endpoint_id: ID of endpoint to lookup |
| 233 |
:param query_params: Any additional parameters will be passed through |
| 234 |
as query params. |
| 235 |
|
| 236 |
.. tab-set:: |
| 237 |
|
| 238 |
.. tab-item:: Example Usage |
| 239 |
|
| 240 |
.. code-block:: python |
| 241 |
|
| 242 |
tc = globus_sdk.TransferClient(...) |
| 243 |
endpoint = tc.get_endpoint(endpoint_id) |
| 244 |
print("Endpoint name:", endpoint["display_name"] or endpoint["canonical_name"]) |
| 245 |
|
| 246 |
.. tab-item:: API Info |
| 247 |
|
| 248 |
``GET /endpoint/<endpoint_id>`` |
| 249 |
|
| 250 |
.. extdoclink:: Get Endpoint or Collection by ID |
| 251 |
:ref: transfer/endpoints_and_collections/#get_endpoint_or_collection_by_id |
| 252 |
""" # noqa: E501 |
| 253 |
log.debug(f"TransferClient.get_endpoint({endpoint_id})") |
| 254 |
return self.get(f"/v0.10/endpoint/{endpoint_id}", query_params=query_params) |
| 255 |
|
| 256 |
def update_endpoint( |
| 257 |
self, |
| 258 |
endpoint_id: uuid.UUID | str, |
| 259 |
data: dict[str, t.Any], |
| 260 |
*, |
| 261 |
query_params: dict[str, t.Any] | None = None, |
| 262 |
) -> response.GlobusHTTPResponse: |
| 263 |
""" |
| 264 |
:param endpoint_id: ID of endpoint to lookup |
| 265 |
:param data: A partial endpoint document with fields to update |
| 266 |
:param query_params: Any additional parameters will be passed through |
| 267 |
as query params. |
| 268 |
|
| 269 |
.. tab-set:: |
| 270 |
|
| 271 |
.. tab-item:: Example Usage |
| 272 |
|
| 273 |
.. code-block:: python |
| 274 |
|
| 275 |
tc = globus_sdk.TransferClient(...) |
| 276 |
epup = { |
| 277 |
"display_name": "My New Endpoint Name", |
| 278 |
"description": "Better Description", |
| 279 |
} |
| 280 |
update_result = tc.update_endpoint(endpoint_id, epup) |
| 281 |
|
| 282 |
.. tab-item:: API Info |
| 283 |
|
| 284 |
``PUT /endpoint/<endpoint_id>`` |
| 285 |
|
| 286 |
.. extdoclink:: Update Globus Connect Personal collection by id |
| 287 |
:ref: transfer/gcp_management/#update_collection_by_id |
| 288 |
""" # noqa: E501 |
| 289 |
log.debug(f"TransferClient.update_endpoint({endpoint_id}, ...)") |
| 290 |
return self.put( |
| 291 |
f"/v0.10/endpoint/{endpoint_id}", data=data, query_params=query_params |
| 292 |
) |
| 293 |
|
| 294 |
def set_subscription_id( |
| 295 |
self, |
| 296 |
collection_id: uuid.UUID | str, |
| 297 |
subscription_id: uuid.UUID | str | t.Literal["DEFAULT"] | None, |
| 298 |
) -> response.GlobusHTTPResponse: |
| 299 |
""" |
| 300 |
Set the ``subscription_id`` on a mapped collection. |
| 301 |
This is primarily used for subscription management on Globus Connect Personal. |
| 302 |
|
| 303 |
This operation requires membership in a Globus subscription group and |
| 304 |
has authorization requirements which depend upon the caller's roles on |
| 305 |
the subscription group and the endpoint or collection. |
| 306 |
|
| 307 |
Guest Collections inherit the subscriptions of their Mapped Collections and |
| 308 |
cannot have a ``subscription_id`` directly set in this way. |
| 309 |
|
| 310 |
:param collection_id: The collection ID which is having its subscription set. |
| 311 |
:param subscription_id: The ID of the subscription to assign, the special |
| 312 |
string ``"DEFAULT"``, or ``None``. |
| 313 |
|
| 314 |
.. note:: |
| 315 |
|
| 316 |
Setting ``subscription_id="DEFAULT"`` results in the service choosing your |
| 317 |
subscription ID, but requires that you only have one subscription. |
| 318 |
If you have multiple subscriptions, using ``"DEFAULT"`` will result in an |
| 319 |
error. |
| 320 |
|
| 321 |
Setting ``subscription_id=None`` clears any existing subscription from the |
| 322 |
collection. |
| 323 |
|
| 324 |
.. tab-set:: |
| 325 |
|
| 326 |
.. tab-item:: Example Usage |
| 327 |
|
| 328 |
.. code-block:: python |
| 329 |
|
| 330 |
import globus_sdk |
| 331 |
|
| 332 |
MY_SUBSCRIPTION_ID = "..." |
| 333 |
LOCAL_GCP = globus_sdk.LocalGlobusConnectPersonal() |
| 334 |
|
| 335 |
tc = globus_sdk.TransferClient(...) |
| 336 |
tc.endpoint_set_subscription_id( |
| 337 |
LOCAL_GCP.endpoint_id, |
| 338 |
MY_SUBSCRIPTION_ID, |
| 339 |
) |
| 340 |
|
| 341 |
.. tab-item:: API Info |
| 342 |
|
| 343 |
``PUT /endpoint/<collection_id>/subscription`` |
| 344 |
|
| 345 |
.. extdoclink:: Associate a Globus Connect Personal Mapped Collection with a Subscription |
| 346 |
:ref: transfer/gcp_management/#associate_collection_subscription |
| 347 |
""" # noqa: E501 |
| 348 |
return self.put( |
| 349 |
f"/v0.10/endpoint/{collection_id}/subscription", |
| 350 |
data={"subscription_id": subscription_id}, |
| 351 |
) |
| 352 |
|
| 353 |
def set_subscription_admin_verified( |
| 354 |
self, |
| 355 |
collection_id: uuid.UUID | str, |
| 356 |
subscription_admin_verified: bool, |
| 357 |
) -> response.GlobusHTTPResponse: |
| 358 |
""" |
| 359 |
Sets the value of ``subscription_admin_verified`` on a Globus Connect Personal |
| 360 |
mapped collection. A value of ``True`` grants verified status, and a |
| 361 |
value of ``False`` revokes verified status. |
| 362 |
|
| 363 |
This operation requires membership in a Globus subscription group and |
| 364 |
has authorization requirements which depend upon the caller's roles on |
| 365 |
the subscription group and the collection. |
| 366 |
|
| 367 |
Subscription administrators can grant or revoke verification on a collection |
| 368 |
that is associated with their subscription without needing an administrator |
| 369 |
role on the collection itself. |
| 370 |
|
| 371 |
Users with the administrator effective role on the collection can revoke |
| 372 |
verification on a collection, but must still be a subscription administrator |
| 373 |
to grant verification. |
| 374 |
|
| 375 |
:param collection_id: The collection ID which is having its subscription set. |
| 376 |
:param subscription_admin_verified: The verification status of the collection |
| 377 |
expressed as a Boolean type. |
| 378 |
|
| 379 |
.. tab-set:: |
| 380 |
|
| 381 |
.. tab-item:: Example Usage |
| 382 |
|
| 383 |
.. code-block:: python |
| 384 |
|
| 385 |
import globus_sdk |
| 386 |
|
| 387 |
LOCAL_GCP = globus_sdk.LocalGlobusConnectPersonal() |
| 388 |
|
| 389 |
tc = globus_sdk.TransferClient(...) |
| 390 |
tc.endpoint_set_subscription_id( |
| 391 |
LOCAL_GCP.endpoint_id, |
| 392 |
True, |
| 393 |
) |
| 394 |
|
| 395 |
.. tab-item:: API Info |
| 396 |
|
| 397 |
``PUT /endpoint/<collection_id>/subscription_admin_verified`` |
| 398 |
|
| 399 |
.. extdoclink:: Set Subscription Admin Verified |
| 400 |
:ref: transfer/gcp_management/#set_subscription_admin_verified |
| 401 |
""" # noqa: E501 |
| 402 |
return self.put( |
| 403 |
f"/v0.10/endpoint/{collection_id}/subscription_admin_verified", |
| 404 |
data={"subscription_admin_verified": subscription_admin_verified}, |
| 405 |
) |
| 406 |
|
| 407 |
def delete_endpoint( |
| 408 |
self, endpoint_id: uuid.UUID | str |
| 409 |
) -> response.GlobusHTTPResponse: |
| 410 |
""" |
| 411 |
:param endpoint_id: ID of endpoint to delete |
| 412 |
|
| 413 |
.. tab-set:: |
| 414 |
|
| 415 |
.. tab-item:: Example Usage |
| 416 |
|
| 417 |
.. code-block:: python |
| 418 |
|
| 419 |
tc = globus_sdk.TransferClient(...) |
| 420 |
delete_result = tc.delete_endpoint(endpoint_id) |
| 421 |
|
| 422 |
.. tab-item:: API Info |
| 423 |
|
| 424 |
``DELETE /endpoint/<endpoint_id>`` |
| 425 |
|
| 426 |
.. extdoclink:: Delete Globus Connect Personal collection by id |
| 427 |
:ref: transfer/gcp_management/#delete_collection_by_id |
| 428 |
""" |
| 429 |
log.debug(f"TransferClient.delete_endpoint({endpoint_id})") |
| 430 |
return self.delete(f"/v0.10/endpoint/{endpoint_id}") |
| 431 |
|
| 432 |
@paging.has_paginator( |
| 433 |
paging.HasNextPaginator, |
| 434 |
items_key="DATA", |
| 435 |
get_page_size=_get_page_size, |
| 436 |
max_total_results=1000, |
| 437 |
page_size=100, |
| 438 |
) |
| 439 |
def endpoint_search( |
| 440 |
self, |
| 441 |
filter_fulltext: str | MissingType = MISSING, |
| 442 |
*, |
| 443 |
filter_scope: str | MissingType = MISSING, |
| 444 |
filter_owner_id: str | MissingType = MISSING, |
| 445 |
filter_host_endpoint: uuid.UUID | str | MissingType = MISSING, |
| 446 |
filter_non_functional: bool | MissingType = MISSING, |
| 447 |
filter_entity_type: ( |
| 448 |
t.Literal[ |
| 449 |
"GCP_mapped_collection", |
| 450 |
"GCP_guest_collection", |
| 451 |
"GCSv5_endpoint", |
| 452 |
"GCSv5_mapped_collection", |
| 453 |
"GCSv5_guest_collection", |
| 454 |
] |
| 455 |
| MissingType |
| 456 |
) = MISSING, |
| 457 |
limit: int | MissingType = MISSING, |
| 458 |
offset: int | MissingType = MISSING, |
| 459 |
query_params: dict[str, t.Any] | None = None, |
| 460 |
) -> IterableTransferResponse: |
| 461 |
r""" |
| 462 |
:param filter_fulltext: The string to use in a full text search on endpoints. |
| 463 |
Effectively, the "search query" which is being requested. May be omitted |
| 464 |
with specific ``filter_scope`` values. |
| 465 |
:param filter_scope: A "scope" within which to search for endpoints. This must |
| 466 |
be one of the limited and known names known to the service, which can be |
| 467 |
found documented in the **External Documentation** below. Defaults to |
| 468 |
searching all endpoints (in which case ``filter_fulltext`` is required) |
| 469 |
:param filter_owner_id: Limit search to endpoints owned by the specified Globus |
| 470 |
Auth identity. Conflicts with scopes 'my-endpoints', 'my-gcp-endpoints', and |
| 471 |
'shared-by-me'. |
| 472 |
:param filter_host_endpoint: Limit search to endpoints hosted by the specified |
| 473 |
endpoint. May cause BadRequest or PermissionDenied errors if the endpoint ID |
| 474 |
given is not valid for this operation. |
| 475 |
:param filter_non_functional: Limit search to endpoints which have the |
| 476 |
'non_functional' flag set to True or False. Mutually exclusive with |
| 477 |
``filter_entity_type``. |
| 478 |
:param filter_entity_type: Limit search to endpoints or collections of a |
| 479 |
specified entity type. Mutually exclusive with ``filter_non_functional``. |
| 480 |
:param limit: limit the number of results |
| 481 |
:param offset: offset used in paging |
| 482 |
:param query_params: Any additional parameters will be passed through |
| 483 |
as query params. |
| 484 |
|
| 485 |
It is important to be aware that the Endpoint Search API limits |
| 486 |
you to 1000 results for any search query. |
| 487 |
|
| 488 |
.. tab-set:: |
| 489 |
|
| 490 |
.. tab-item:: Example Usage |
| 491 |
|
| 492 |
Search for a given string as a fulltext search: |
| 493 |
|
| 494 |
.. code-block:: python |
| 495 |
|
| 496 |
tc = globus_sdk.TransferClient(...) |
| 497 |
for ep in tc.endpoint_search("String to search for!"): |
| 498 |
print(ep["display_name"]) |
| 499 |
|
| 500 |
Search for a given string, but only on endpoints that you own: |
| 501 |
|
| 502 |
.. code-block:: python |
| 503 |
|
| 504 |
for ep in tc.endpoint_search("foo", filter_scope="my-endpoints"): |
| 505 |
print(f"{ep['display_name']} has ID {ep['id']}") |
| 506 |
|
| 507 |
.. tab-item:: Paginated Usage |
| 508 |
|
| 509 |
.. paginatedusage:: endpoint_search |
| 510 |
|
| 511 |
.. tab-item:: API Info |
| 512 |
|
| 513 |
.. parsed-literal:: |
| 514 |
|
| 515 |
GET /endpoint_search\ |
| 516 |
?filter_fulltext=<filter_fulltext>&filter_scope=<filter_scope> |
| 517 |
|
| 518 |
.. extdoclink:: Endpoint and Collection Search |
| 519 |
:ref: transfer/endpoint_and_collection_search |
| 520 |
""" # noqa: E501 |
| 521 |
query_params = { |
| 522 |
"filter_scope": filter_scope, |
| 523 |
"filter_fulltext": filter_fulltext, |
| 524 |
"filter_owner_id": filter_owner_id, |
| 525 |
"filter_host_endpoint": filter_host_endpoint, |
| 526 |
"filter_non_functional": ( |
| 527 |
1 |
| 528 |
if filter_non_functional |
| 529 |
else ( |
| 530 |
0 |
| 531 |
if isinstance(filter_non_functional, bool) |
| 532 |
else filter_non_functional |
| 533 |
) |
| 534 |
), |
| 535 |
"filter_entity_type": filter_entity_type, |
| 536 |
"limit": limit, |
| 537 |
"offset": offset, |
| 538 |
**(query_params or {}), |
| 539 |
} |
| 540 |
log.debug(f"TransferClient.endpoint_search({query_params})") |
| 541 |
return IterableTransferResponse( |
| 542 |
self.get("/v0.10/endpoint_search", query_params=query_params) |
| 543 |
) |
| 544 |
|
| 545 |
def my_effective_pause_rule_list( |
| 546 |
self, |
| 547 |
endpoint_id: uuid.UUID | str, |
| 548 |
*, |
| 549 |
query_params: dict[str, t.Any] | None = None, |
| 550 |
) -> IterableTransferResponse: |
| 551 |
""" |
| 552 |
:param endpoint_id: the endpoint on which the current user's effective pause |
| 553 |
rules are fetched |
| 554 |
:param query_params: Additional passthrough query parameters |
| 555 |
|
| 556 |
.. tab-set:: |
| 557 |
|
| 558 |
.. tab-item:: API Info |
| 559 |
|
| 560 |
``GET /endpoint/<endpoint_id>/my_effective_pause_rule_list`` |
| 561 |
|
| 562 |
.. extdoclink:: Get my effective collection pause rules |
| 563 |
:ref: transfer/endpoints_and_collections/#get_collection_pause_rules |
| 564 |
""" |
| 565 |
log.debug(f"TransferClient.my_effective_pause_rule_list({endpoint_id}, ...)") |
| 566 |
return IterableTransferResponse( |
| 567 |
self.get( |
| 568 |
f"/v0.10/endpoint/{endpoint_id}/my_effective_pause_rule_list", |
| 569 |
query_params=query_params, |
| 570 |
) |
| 571 |
) |
| 572 |
|
| 573 |
# Shared Endpoints |
| 574 |
|
| 575 |
def my_shared_endpoint_list( |
| 576 |
self, |
| 577 |
endpoint_id: uuid.UUID | str, |
| 578 |
*, |
| 579 |
query_params: dict[str, t.Any] | None = None, |
| 580 |
) -> IterableTransferResponse: |
| 581 |
""" |
| 582 |
:param endpoint_id: the host endpoint whose shares are listed |
| 583 |
:param query_params: Additional passthrough query parameters |
| 584 |
|
| 585 |
Get a list of shared endpoints for which the user has ``administrator`` or |
| 586 |
``access_manager`` on a given host endpoint. |
| 587 |
|
| 588 |
.. tab-set:: |
| 589 |
|
| 590 |
.. tab-item:: API Info |
| 591 |
|
| 592 |
``GET /endpoint/<endpoint_id>/my_shared_endpoint_list`` |
| 593 |
|
| 594 |
.. extdoclink:: Get my guest collection list |
| 595 |
:ref: transfer/endpoints_and_collections/#get_my_guest_collection_list |
| 596 |
""" # noqa: E501 |
| 597 |
log.debug(f"TransferClient.my_shared_endpoint_list({endpoint_id}, ...)") |
| 598 |
return IterableTransferResponse( |
| 599 |
self.get( |
| 600 |
f"/v0.10/endpoint/{endpoint_id}/my_shared_endpoint_list", |
| 601 |
query_params=query_params, |
| 602 |
) |
| 603 |
) |
| 604 |
|
| 605 |
@paging.has_paginator(paging.NextTokenPaginator, items_key="shared_endpoints") |
| 606 |
def get_shared_endpoint_list( |
| 607 |
self, |
| 608 |
endpoint_id: uuid.UUID | str, |
| 609 |
*, |
| 610 |
max_results: int | MissingType = MISSING, |
| 611 |
next_token: str | MissingType = MISSING, |
| 612 |
query_params: dict[str, t.Any] | None = None, |
| 613 |
) -> IterableTransferResponse: |
| 614 |
""" |
| 615 |
:param endpoint_id: the host endpoint whose shares are listed |
| 616 |
:param max_results: cap to the number of results |
| 617 |
:param next_token: token used for paging |
| 618 |
:param query_params: Any additional parameters to be passed through |
| 619 |
as query params. |
| 620 |
|
| 621 |
Get a list of all shared endpoints on a given host endpoint. |
| 622 |
|
| 623 |
.. tab-set:: |
| 624 |
|
| 625 |
.. tab-item:: Paginated Usage |
| 626 |
|
| 627 |
.. paginatedusage:: get_shared_endpoint_list |
| 628 |
|
| 629 |
.. tab-item:: API Info |
| 630 |
|
| 631 |
``GET /endpoint/<endpoint_id>/shared_endpoint_list`` |
| 632 |
|
| 633 |
.. extdoclink:: Get guest collection list |
| 634 |
:ref: transfer/endpoints_and_collections/get_guest_collection_list |
| 635 |
""" |
| 636 |
log.debug(f"TransferClient.get_shared_endpoint_list({endpoint_id}, ...)") |
| 637 |
query_params = { |
| 638 |
"max_results": ( |
| 639 |
str(max_results) if isinstance(max_results, int) else max_results |
| 640 |
), |
| 641 |
"next_token": next_token, |
| 642 |
**(query_params or {}), |
| 643 |
} |
| 644 |
return IterableTransferResponse( |
| 645 |
self.get( |
| 646 |
f"/v0.10/endpoint/{endpoint_id}/shared_endpoint_list", |
| 647 |
query_params=query_params, |
| 648 |
), |
| 649 |
iter_key="shared_endpoints", |
| 650 |
) |
| 651 |
|
| 652 |
def create_shared_endpoint( |
| 653 |
self, data: dict[str, t.Any] |
| 654 |
) -> response.GlobusHTTPResponse: |
| 655 |
""" |
| 656 |
:param data: A python dict representation of a ``shared_endpoint`` document |
| 657 |
|
| 658 |
.. tab-set:: |
| 659 |
|
| 660 |
.. tab-item:: Example Usage |
| 661 |
|
| 662 |
.. code-block:: python |
| 663 |
|
| 664 |
tc = globus_sdk.TransferClient(...) |
| 665 |
shared_ep_data = { |
| 666 |
"DATA_TYPE": "shared_endpoint", |
| 667 |
"host_endpoint": host_endpoint_id, |
| 668 |
"host_path": host_path, |
| 669 |
"display_name": display_name, |
| 670 |
# optionally specify additional endpoint fields |
| 671 |
"description": "my test share", |
| 672 |
} |
| 673 |
create_result = tc.create_shared_endpoint(shared_ep_data) |
| 674 |
endpoint_id = create_result["id"] |
| 675 |
|
| 676 |
.. tab-item:: API Info |
| 677 |
|
| 678 |
``POST /shared_endpoint`` |
| 679 |
|
| 680 |
.. extdoclink:: Create guest collection |
| 681 |
:ref: transfer/gcp_management/#create_guest_collection |
| 682 |
""" |
| 683 |
log.debug("TransferClient.create_shared_endpoint(...)") |
| 684 |
return self.post("/v0.10/shared_endpoint", data=data) |
| 685 |
|
| 686 |
# Endpoint servers |
| 687 |
|
| 688 |
def endpoint_server_list( |
| 689 |
self, |
| 690 |
endpoint_id: uuid.UUID | str, |
| 691 |
*, |
| 692 |
query_params: dict[str, t.Any] | None = None, |
| 693 |
) -> IterableTransferResponse: |
| 694 |
""" |
| 695 |
:param endpoint_id: The endpoint whose servers are being listed |
| 696 |
:param query_params: Any additional parameters to be passed through |
| 697 |
as query params. |
| 698 |
|
| 699 |
.. tab-set:: |
| 700 |
|
| 701 |
.. tab-item:: API Info |
| 702 |
|
| 703 |
``GET /endpoint/<endpoint_id>/server_list`` |
| 704 |
|
| 705 |
.. extdoclink:: Get endpoint or collection server list |
| 706 |
:ref: transfer/endpoints_and_collections/#get_endpoint_or_collection_server_list |
| 707 |
""" # noqa: E501 |
| 708 |
log.debug(f"TransferClient.endpoint_server_list({endpoint_id}, ...)") |
| 709 |
return IterableTransferResponse( |
| 710 |
self.get( |
| 711 |
f"/v0.10/endpoint/{endpoint_id}/server_list", query_params=query_params |
| 712 |
) |
| 713 |
) |
| 714 |
|
| 715 |
def get_endpoint_server( |
| 716 |
self, |
| 717 |
endpoint_id: uuid.UUID | str, |
| 718 |
server_id: IntLike, |
| 719 |
*, |
| 720 |
query_params: dict[str, t.Any] | None = None, |
| 721 |
) -> response.GlobusHTTPResponse: |
| 722 |
""" |
| 723 |
:param endpoint_id: The endpoint under which the server is registered |
| 724 |
:param server_id: The ID of the server |
| 725 |
:param query_params: Additional passthrough query parameters |
| 726 |
|
| 727 |
.. tab-set:: |
| 728 |
|
| 729 |
.. tab-item:: API Info |
| 730 |
|
| 731 |
``GET /endpoint/<endpoint_id>/server/<server_id>`` |
| 732 |
|
| 733 |
.. extdoclink:: Get server by id |
| 734 |
:ref: transfer/endpoints_and_collections/#get_server_by_id |
| 735 |
""" |
| 736 |
log.debug( |
| 737 |
"TransferClient.get_endpoint_server(%s, %s, ...)", endpoint_id, server_id |
| 738 |
) |
| 739 |
return self.get( |
| 740 |
f"/v0.10/endpoint/{endpoint_id}/server/{server_id}", |
| 741 |
query_params=query_params, |
| 742 |
) |
| 743 |
|
| 744 |
# |
| 745 |
# Roles |
| 746 |
# |
| 747 |
|
| 748 |
def endpoint_role_list( |
| 749 |
self, |
| 750 |
endpoint_id: uuid.UUID | str, |
| 751 |
*, |
| 752 |
query_params: dict[str, t.Any] | None = None, |
| 753 |
) -> IterableTransferResponse: |
| 754 |
""" |
| 755 |
:param endpoint_id: The endpoint whose roles are being listed |
| 756 |
:param query_params: Any additional parameters to be passed through |
| 757 |
as query params. |
| 758 |
|
| 759 |
.. tab-set:: |
| 760 |
|
| 761 |
.. tab-item:: API Info |
| 762 |
|
| 763 |
``GET /endpoint/<endpoint_id>/role_list`` |
| 764 |
|
| 765 |
.. extdoclink:: Get list of roles |
| 766 |
:ref: transfer/roles/#role_list |
| 767 |
""" |
| 768 |
log.debug(f"TransferClient.endpoint_role_list({endpoint_id}, ...)") |
| 769 |
return IterableTransferResponse( |
| 770 |
self.get( |
| 771 |
f"/v0.10/endpoint/{endpoint_id}/role_list", query_params=query_params |
| 772 |
) |
| 773 |
) |
| 774 |
|
| 775 |
def add_endpoint_role( |
| 776 |
self, endpoint_id: uuid.UUID | str, role_data: dict[str, t.Any] |
| 777 |
) -> response.GlobusHTTPResponse: |
| 778 |
""" |
| 779 |
:param endpoint_id: The endpoint on which the role is being added |
| 780 |
:param role_data: A role document for the new role |
| 781 |
|
| 782 |
.. tab-set:: |
| 783 |
|
| 784 |
.. tab-item:: API Info |
| 785 |
|
| 786 |
``POST /endpoint/<endpoint_id>/role`` |
| 787 |
|
| 788 |
.. extdoclink:: Create Globus Connect Personal collection role |
| 789 |
:ref: transfer/roles/#create_role |
| 790 |
""" |
| 791 |
log.debug(f"TransferClient.add_endpoint_role({endpoint_id}, ...)") |
| 792 |
return self.post(f"/v0.10/endpoint/{endpoint_id}/role", data=role_data) |
| 793 |
|
| 794 |
def get_endpoint_role( |
| 795 |
self, |
| 796 |
endpoint_id: uuid.UUID | str, |
| 797 |
role_id: str, |
| 798 |
*, |
| 799 |
query_params: dict[str, t.Any] | None = None, |
| 800 |
) -> response.GlobusHTTPResponse: |
| 801 |
""" |
| 802 |
:param endpoint_id: The endpoint on which the role applies |
| 803 |
:param role_id: The ID of the role |
| 804 |
:param query_params: Additional passthrough query parameters |
| 805 |
|
| 806 |
.. tab-set:: |
| 807 |
|
| 808 |
.. tab-item:: API Info |
| 809 |
|
| 810 |
``GET /endpoint/<endpoint_id>/role/<role_id>`` |
| 811 |
|
| 812 |
.. extdoclink:: Get role by id |
| 813 |
:ref: transfer/roles/#get_role_by_id |
| 814 |
""" |
| 815 |
log.debug(f"TransferClient.get_endpoint_role({endpoint_id}, {role_id}, ...)") |
| 816 |
return self.get( |
| 817 |
f"/v0.10/endpoint/{endpoint_id}/role/{role_id}", query_params=query_params |
| 818 |
) |
| 819 |
|
| 820 |
def delete_endpoint_role( |
| 821 |
self, endpoint_id: uuid.UUID | str, role_id: str |
| 822 |
) -> response.GlobusHTTPResponse: |
| 823 |
""" |
| 824 |
:param endpoint_id: The endpoint on which the role applies |
| 825 |
:param role_id: The ID of the role to delete |
| 826 |
|
| 827 |
.. tab-set:: |
| 828 |
|
| 829 |
.. tab-item:: API Info |
| 830 |
|
| 831 |
``DELETE /endpoint/<endpoint_id>/role/<role_id>`` |
| 832 |
|
| 833 |
.. extdoclink:: Delete Globus Connect Personal collection role by id |
| 834 |
:ref: transfer/roles/#delete_role_by_id |
| 835 |
""" |
| 836 |
log.debug(f"TransferClient.delete_endpoint_role({endpoint_id}, {role_id})") |
| 837 |
return self.delete(f"/v0.10/endpoint/{endpoint_id}/role/{role_id}") |
| 838 |
|
| 839 |
# |
| 840 |
# ACLs |
| 841 |
# |
| 842 |
|
| 843 |
def endpoint_acl_list( |
| 844 |
self, |
| 845 |
endpoint_id: uuid.UUID | str, |
| 846 |
*, |
| 847 |
query_params: dict[str, t.Any] | None = None, |
| 848 |
) -> IterableTransferResponse: |
| 849 |
""" |
| 850 |
:param endpoint_id: The endpoint whose ACLs are being listed |
| 851 |
:param query_params: Additional passthrough query parameters |
| 852 |
|
| 853 |
.. tab-set:: |
| 854 |
|
| 855 |
.. tab-item:: API Info |
| 856 |
|
| 857 |
``GET /endpoint/<endpoint_id>/access_list`` |
| 858 |
|
| 859 |
.. extdoclink:: Get list of access rules |
| 860 |
:ref: transfer/acl/#rest_access_get_list |
| 861 |
""" |
| 862 |
log.debug(f"TransferClient.endpoint_acl_list({endpoint_id}, ...)") |
| 863 |
return IterableTransferResponse( |
| 864 |
self.get( |
| 865 |
f"/v0.10/endpoint/{endpoint_id}/access_list", query_params=query_params |
| 866 |
) |
| 867 |
) |
| 868 |
|
| 869 |
def get_endpoint_acl_rule( |
| 870 |
self, |
| 871 |
endpoint_id: uuid.UUID | str, |
| 872 |
rule_id: str, |
| 873 |
*, |
| 874 |
query_params: dict[str, t.Any] | None = None, |
| 875 |
) -> response.GlobusHTTPResponse: |
| 876 |
""" |
| 877 |
:param endpoint_id: The endpoint on which the access rule applies |
| 878 |
:param rule_id: The ID of the rule to fetch |
| 879 |
:param query_params: Additional passthrough query parameters |
| 880 |
|
| 881 |
.. tab-set:: |
| 882 |
|
| 883 |
.. tab-item:: API Info |
| 884 |
|
| 885 |
``GET /endpoint/<endpoint_id>/access/<rule_id>`` |
| 886 |
|
| 887 |
.. extdoclink:: Get access rule by ID |
| 888 |
:ref: transfer/acl/#get_access_rule_by_id |
| 889 |
""" |
| 890 |
log.debug( |
| 891 |
"TransferClient.get_endpoint_acl_rule(%s, %s, ...)", endpoint_id, rule_id |
| 892 |
) |
| 893 |
return self.get( |
| 894 |
f"/v0.10/endpoint/{endpoint_id}/access/{rule_id}", query_params=query_params |
| 895 |
) |
| 896 |
|
| 897 |
def add_endpoint_acl_rule( |
| 898 |
self, endpoint_id: uuid.UUID | str, rule_data: dict[str, t.Any] |
| 899 |
) -> response.GlobusHTTPResponse: |
| 900 |
""" |
| 901 |
:param endpoint_id: ID of endpoint to which to add the acl |
| 902 |
:param rule_data: A python dict representation of an ``access`` document |
| 903 |
|
| 904 |
.. tab-set:: |
| 905 |
|
| 906 |
.. tab-item:: Example Usage |
| 907 |
|
| 908 |
.. code-block:: python |
| 909 |
|
| 910 |
tc = globus_sdk.TransferClient(...) |
| 911 |
rule_data = { |
| 912 |
"DATA_TYPE": "access", |
| 913 |
"principal_type": "identity", |
| 914 |
"principal": identity_id, |
| 915 |
"path": "/dataset1/", |
| 916 |
"permissions": "rw", |
| 917 |
} |
| 918 |
result = tc.add_endpoint_acl_rule(endpoint_id, rule_data) |
| 919 |
rule_id = result["access_id"] |
| 920 |
|
| 921 |
Note that if this rule is being created on a shared endpoint |
| 922 |
the "path" field is relative to the "host_path" of the shared endpoint. |
| 923 |
|
| 924 |
.. tab-item:: API Info |
| 925 |
|
| 926 |
``POST /endpoint/<endpoint_id>/access`` |
| 927 |
|
| 928 |
.. extdoclink:: Create access rule |
| 929 |
:ref: transfer/acl/#rest_access_create |
| 930 |
""" |
| 931 |
log.debug(f"TransferClient.add_endpoint_acl_rule({endpoint_id}, ...)") |
| 932 |
return self.post(f"/v0.10/endpoint/{endpoint_id}/access", data=rule_data) |
| 933 |
|
| 934 |
def update_endpoint_acl_rule( |
| 935 |
self, |
| 936 |
endpoint_id: uuid.UUID | str, |
| 937 |
rule_id: str, |
| 938 |
rule_data: dict[str, t.Any], |
| 939 |
) -> response.GlobusHTTPResponse: |
| 940 |
""" |
| 941 |
:param endpoint_id: The endpoint on which the access rule applies |
| 942 |
:param rule_id: The ID of the access rule to modify |
| 943 |
:param rule_data: A partial ``access`` document containing fields to update |
| 944 |
|
| 945 |
.. tab-set:: |
| 946 |
|
| 947 |
.. tab-item:: API Info |
| 948 |
|
| 949 |
``PUT /endpoint/<endpoint_id>/access/<rule_id>`` |
| 950 |
|
| 951 |
.. extdoclink:: Update access rule |
| 952 |
:ref: transfer/acl/#update_access_rule |
| 953 |
""" |
| 954 |
log.debug( |
| 955 |
"TransferClient.update_endpoint_acl_rule(%s, %s, ...)", |
| 956 |
endpoint_id, |
| 957 |
rule_id, |
| 958 |
) |
| 959 |
return self.put( |
| 960 |
f"/v0.10/endpoint/{endpoint_id}/access/{rule_id}", data=rule_data |
| 961 |
) |
| 962 |
|
| 963 |
def delete_endpoint_acl_rule( |
| 964 |
self, endpoint_id: uuid.UUID | str, rule_id: str |
| 965 |
) -> response.GlobusHTTPResponse: |
| 966 |
""" |
| 967 |
:param endpoint_id: The endpoint on which the access rule applies |
| 968 |
:param rule_id: The ID of the access rule to remove |
| 969 |
|
| 970 |
.. tab-set:: |
| 971 |
|
| 972 |
.. tab-item:: API Info |
| 973 |
|
| 974 |
``DELETE /endpoint/<endpoint_id>/access/<rule_id>`` |
| 975 |
|
| 976 |
.. extdoclink:: Delete access rule |
| 977 |
:ref: transfer/acl/#delete_access_rule |
| 978 |
""" |
| 979 |
log.debug( |
| 980 |
"TransferClient.delete_endpoint_acl_rule(%s, %s)", endpoint_id, rule_id |
| 981 |
) |
| 982 |
return self.delete(f"/v0.10/endpoint/{endpoint_id}/access/{rule_id}") |
| 983 |
|
| 984 |
# |
| 985 |
# Bookmarks |
| 986 |
# |
| 987 |
|
| 988 |
def bookmark_list( |
| 989 |
self, *, query_params: dict[str, t.Any] | None = None |
| 990 |
) -> IterableTransferResponse: |
| 991 |
""" |
| 992 |
:param query_params: Additional passthrough query parameters |
| 993 |
|
| 994 |
.. tab-set:: |
| 995 |
|
| 996 |
.. tab-item:: API Info |
| 997 |
|
| 998 |
``GET /bookmark_list`` |
| 999 |
|
| 1000 |
.. extdoclink:: Get list of bookmarks |
| 1001 |
:ref: transfer/collection_bookmarks/#get_list_of_bookmarks |
| 1002 |
""" |
| 1003 |
log.debug(f"TransferClient.bookmark_list({query_params})") |
| 1004 |
return IterableTransferResponse( |
| 1005 |
self.get("/v0.10/bookmark_list", query_params=query_params) |
| 1006 |
) |
| 1007 |
|
| 1008 |
def create_bookmark( |
| 1009 |
self, bookmark_data: dict[str, t.Any] |
| 1010 |
) -> response.GlobusHTTPResponse: |
| 1011 |
""" |
| 1012 |
:param bookmark_data: A bookmark document for the bookmark to create |
| 1013 |
|
| 1014 |
.. tab-set:: |
| 1015 |
|
| 1016 |
.. tab-item:: API Info |
| 1017 |
|
| 1018 |
``POST /bookmark`` |
| 1019 |
|
| 1020 |
.. extdoclink:: Create bookmark |
| 1021 |
:ref: transfer/collection_bookmarks/#create_bookmark |
| 1022 |
""" |
| 1023 |
log.debug(f"TransferClient.create_bookmark({bookmark_data})") |
| 1024 |
return self.post("/v0.10/bookmark", data=bookmark_data) |
| 1025 |
|
| 1026 |
def get_bookmark( |
| 1027 |
self, |
| 1028 |
bookmark_id: uuid.UUID | str, |
| 1029 |
*, |
| 1030 |
query_params: dict[str, t.Any] | None = None, |
| 1031 |
) -> response.GlobusHTTPResponse: |
| 1032 |
""" |
| 1033 |
:param bookmark_id: The ID of the bookmark to lookup |
| 1034 |
:param query_params: Additional passthrough query parameters |
| 1035 |
|
| 1036 |
.. tab-set:: |
| 1037 |
|
| 1038 |
.. tab-item:: API Info |
| 1039 |
|
| 1040 |
``GET /bookmark/<bookmark_id>`` |
| 1041 |
|
| 1042 |
.. extdoclink:: Get bookmark by ID |
| 1043 |
:ref: transfer/collection_bookmarks/#get_bookmark_by_id |
| 1044 |
""" |
| 1045 |
log.debug(f"TransferClient.get_bookmark({bookmark_id})") |
| 1046 |
return self.get(f"/v0.10/bookmark/{bookmark_id}", query_params=query_params) |
| 1047 |
|
| 1048 |
def update_bookmark( |
| 1049 |
self, bookmark_id: uuid.UUID | str, bookmark_data: dict[str, t.Any] |
| 1050 |
) -> response.GlobusHTTPResponse: |
| 1051 |
""" |
| 1052 |
:param bookmark_id: The ID of the bookmark to modify |
| 1053 |
:param bookmark_data: A partial bookmark document with fields to update |
| 1054 |
|
| 1055 |
.. tab-set:: |
| 1056 |
|
| 1057 |
.. tab-item:: API Info |
| 1058 |
|
| 1059 |
``PUT /bookmark/<bookmark_id>`` |
| 1060 |
|
| 1061 |
.. extdoclink:: Update bookmark |
| 1062 |
:ref: transfer/collection_bookmarks/#update_bookmark |
| 1063 |
""" |
| 1064 |
log.debug(f"TransferClient.update_bookmark({bookmark_id})") |
| 1065 |
return self.put(f"/v0.10/bookmark/{bookmark_id}", data=bookmark_data) |
| 1066 |
|
| 1067 |
def delete_bookmark( |
| 1068 |
self, bookmark_id: uuid.UUID | str |
| 1069 |
) -> response.GlobusHTTPResponse: |
| 1070 |
""" |
| 1071 |
:param bookmark_id: The ID of the bookmark to delete |
| 1072 |
|
| 1073 |
.. tab-set:: |
| 1074 |
|
| 1075 |
.. tab-item:: API Info |
| 1076 |
|
| 1077 |
``DELETE /bookmark/<bookmark_id>`` |
| 1078 |
|
| 1079 |
.. extdoclink:: Delete bookmark by ID |
| 1080 |
:ref: transfer/collection_bookmarks/#delete_bookmark_by_id |
| 1081 |
""" |
| 1082 |
log.debug(f"TransferClient.delete_bookmark({bookmark_id})") |
| 1083 |
return self.delete(f"/v0.10/bookmark/{bookmark_id}") |
| 1084 |
|
| 1085 |
# |
| 1086 |
# Synchronous Filesys Operations |
| 1087 |
# |
| 1088 |
|
| 1089 |
def operation_ls( |
| 1090 |
self, |
| 1091 |
endpoint_id: uuid.UUID | str, |
| 1092 |
path: str | MissingType = MISSING, |
| 1093 |
*, |
| 1094 |
show_hidden: bool | MissingType = MISSING, |
| 1095 |
orderby: str | list[str] | MissingType = MISSING, |
| 1096 |
limit: int | MissingType = MISSING, |
| 1097 |
offset: int | MissingType = MISSING, |
| 1098 |
# note: filter is a soft keyword in python, so using this name is okay |
| 1099 |
# pylint: disable=redefined-builtin |
| 1100 |
filter: ( |
| 1101 |
str | TransferFilterDict | list[str | TransferFilterDict] | MissingType |
| 1102 |
) = MISSING, |
| 1103 |
local_user: str | MissingType = MISSING, |
| 1104 |
query_params: dict[str, t.Any] | None = None, |
| 1105 |
) -> IterableTransferResponse: |
| 1106 |
""" |
| 1107 |
:param endpoint_id: The ID of the endpoint on which to do a dir listing |
| 1108 |
:param path: Path to a directory on the endpoint to list |
| 1109 |
:param show_hidden: Show hidden files (names beginning in dot). |
| 1110 |
Defaults to true. |
| 1111 |
:param limit: Limit the number of results returned. Defaults to 100,000 , |
| 1112 |
which is also the maximum. |
| 1113 |
:param offset: Offset into the result list, which can be used to page results. |
| 1114 |
:param orderby: One or more order-by options. Each option is |
| 1115 |
either a field name or a field name followed by a space and 'ASC' or 'DESC' |
| 1116 |
for ascending or descending. |
| 1117 |
:param filter: Only return file documents which match these filter clauses. For |
| 1118 |
the filter syntax, see the **External Documentation** linked below. If a |
| 1119 |
dict is supplied as the filter, it is formatted as a set of filter clauses. |
| 1120 |
If a list is supplied, it is passed as multiple params. |
| 1121 |
See :ref:`filter formatting <transfer_filter_formatting>` for details. |
| 1122 |
:param local_user: Optional value passed to identity mapping specifying which |
| 1123 |
local user account to map to. Only usable with Globus Connect Server v5 |
| 1124 |
mapped collections. |
| 1125 |
:param query_params: Additional passthrough query parameters |
| 1126 |
|
| 1127 |
.. note:: |
| 1128 |
|
| 1129 |
Pagination is not supported by the GridFTP protocol, and therefore |
| 1130 |
limit+offset pagination will result in the Transfer service repeatedly |
| 1131 |
fetching an entire directory listing from the server and filtering it before |
| 1132 |
returning it to the client. |
| 1133 |
|
| 1134 |
For latency-sensitive applications, such usage may still be more efficient |
| 1135 |
than asking for a very large directory listing as it reduces the size of the |
| 1136 |
payload passed between the Transfer service and the client. |
| 1137 |
|
| 1138 |
.. tab-set:: |
| 1139 |
|
| 1140 |
.. tab-item:: Example Usage |
| 1141 |
|
| 1142 |
List with a path: |
| 1143 |
|
| 1144 |
.. code-block:: python |
| 1145 |
|
| 1146 |
tc = globus_sdk.TransferClient(...) |
| 1147 |
for entry in tc.operation_ls(ep_id, path="/~/project1/"): |
| 1148 |
print(entry["name"], entry["type"]) |
| 1149 |
|
| 1150 |
List with explicit ordering: |
| 1151 |
|
| 1152 |
.. code-block:: python |
| 1153 |
|
| 1154 |
tc = globus_sdk.TransferClient(...) |
| 1155 |
for entry in tc.operation_ls(ep_id, path="/~/project1/", orderby=["type", "name"]): |
| 1156 |
print(entry["name DESC"], entry["type"]) |
| 1157 |
|
| 1158 |
List filtering to files modified before January 1, 2021. Note the use |
| 1159 |
of an empty "start date" for the filter: |
| 1160 |
|
| 1161 |
.. code-block:: python |
| 1162 |
|
| 1163 |
tc = globus_sdk.TransferClient(...) |
| 1164 |
for entry in tc.operation_ls( |
| 1165 |
ep_id, |
| 1166 |
path="/~/project1/", |
| 1167 |
filter={"last_modified": ["", "2021-01-01"]}, |
| 1168 |
): |
| 1169 |
print(entry["name"], entry["type"]) |
| 1170 |
|
| 1171 |
.. tab-item:: API Info |
| 1172 |
|
| 1173 |
``GET /operation/endpoint/<endpoint_id>/ls`` |
| 1174 |
|
| 1175 |
.. extdoclink:: List Directory Contents |
| 1176 |
:ref: transfer/file_operations/#list_directory_contents |
| 1177 |
""" # noqa: E501 |
| 1178 |
query_params = { |
| 1179 |
"path": path, |
| 1180 |
"limit": limit, |
| 1181 |
"offset": offset, |
| 1182 |
"show_hidden": ( |
| 1183 |
1 |
| 1184 |
if show_hidden |
| 1185 |
else 0 if isinstance(show_hidden, bool) else show_hidden |
| 1186 |
), |
| 1187 |
"orderby": commajoin(orderby), |
| 1188 |
"filter": _format_filter(filter), |
| 1189 |
"local_user": local_user, |
| 1190 |
**(query_params or {}), |
| 1191 |
} |
| 1192 |
log.debug(f"TransferClient.operation_ls({endpoint_id}, {query_params})") |
| 1193 |
return IterableTransferResponse( |
| 1194 |
self.get( |
| 1195 |
f"/v0.10/operation/endpoint/{endpoint_id}/ls", query_params=query_params |
| 1196 |
) |
| 1197 |
) |
| 1198 |
|
| 1199 |
def operation_mkdir( |
| 1200 |
self, |
| 1201 |
endpoint_id: uuid.UUID | str, |
| 1202 |
path: str, |
| 1203 |
*, |
| 1204 |
local_user: str | MissingType = MISSING, |
| 1205 |
query_params: dict[str, t.Any] | None = None, |
| 1206 |
) -> response.GlobusHTTPResponse: |
| 1207 |
""" |
| 1208 |
:param endpoint_id: The ID of the endpoint on which to create a directory |
| 1209 |
:param path: Path to the new directory to create |
| 1210 |
:param local_user: Optional value passed to identity mapping specifying which |
| 1211 |
local user account to map to. Only usable with Globus Connect Server v5 |
| 1212 |
mapped collections. |
| 1213 |
:param query_params: Additional passthrough query parameters |
| 1214 |
|
| 1215 |
.. tab-set:: |
| 1216 |
|
| 1217 |
.. tab-item:: Example Usage |
| 1218 |
|
| 1219 |
.. code-block:: python |
| 1220 |
|
| 1221 |
tc = globus_sdk.TransferClient(...) |
| 1222 |
tc.operation_mkdir(ep_id, path="/~/newdir/") |
| 1223 |
|
| 1224 |
.. tab-item:: API Info |
| 1225 |
|
| 1226 |
``POST /operation/endpoint/<endpoint_id>/mkdir`` |
| 1227 |
|
| 1228 |
.. extdoclink:: Make Directory |
| 1229 |
:ref: transfer/file_operations/#make_directory |
| 1230 |
""" |
| 1231 |
log.debug( |
| 1232 |
"TransferClient.operation_mkdir({}, {}, {})".format( |
| 1233 |
endpoint_id, path, query_params |
| 1234 |
) |
| 1235 |
) |
| 1236 |
json_body = { |
| 1237 |
"DATA_TYPE": "mkdir", |
| 1238 |
"path": path, |
| 1239 |
"local_user": local_user, |
| 1240 |
} |
| 1241 |
return self.post( |
| 1242 |
f"/v0.10/operation/endpoint/{endpoint_id}/mkdir", |
| 1243 |
data=json_body, |
| 1244 |
query_params=query_params, |
| 1245 |
) |
| 1246 |
|
| 1247 |
def operation_rename( |
| 1248 |
self, |
| 1249 |
endpoint_id: uuid.UUID | str, |
| 1250 |
oldpath: str, |
| 1251 |
newpath: str, |
| 1252 |
*, |
| 1253 |
local_user: str | MissingType = MISSING, |
| 1254 |
query_params: dict[str, t.Any] | None = None, |
| 1255 |
) -> response.GlobusHTTPResponse: |
| 1256 |
""" |
| 1257 |
:param endpoint_id: The ID of the endpoint on which to rename a file |
| 1258 |
:param oldpath: Path to the old filename |
| 1259 |
:param newpath: Path to the new filename |
| 1260 |
:param local_user: Optional value passed to identity mapping specifying which |
| 1261 |
local user account to map to. Only usable with Globus Connect Server v5 |
| 1262 |
mapped collections. |
| 1263 |
:param query_params: Additional passthrough query parameters |
| 1264 |
|
| 1265 |
.. tab-set:: |
| 1266 |
|
| 1267 |
.. tab-item:: Example Usage |
| 1268 |
|
| 1269 |
.. code-block:: python |
| 1270 |
|
| 1271 |
tc = globus_sdk.TransferClient(...) |
| 1272 |
tc.operation_rename(ep_id, oldpath="/~/file1.txt", newpath="/~/project1data.txt") |
| 1273 |
|
| 1274 |
.. tab-item:: API Info |
| 1275 |
|
| 1276 |
``POST /operation/endpoint/<endpoint_id>/rename`` |
| 1277 |
|
| 1278 |
.. extdoclink:: Rename |
| 1279 |
:ref: transfer/file_operations/#rename |
| 1280 |
""" # noqa: E501 |
| 1281 |
log.debug( |
| 1282 |
"TransferClient.operation_rename({}, {}, {}, {})".format( |
| 1283 |
endpoint_id, oldpath, newpath, query_params |
| 1284 |
) |
| 1285 |
) |
| 1286 |
json_body = { |
| 1287 |
"DATA_TYPE": "rename", |
| 1288 |
"old_path": oldpath, |
| 1289 |
"new_path": newpath, |
| 1290 |
"local_user": local_user, |
| 1291 |
} |
| 1292 |
return self.post( |
| 1293 |
f"/v0.10/operation/endpoint/{endpoint_id}/rename", |
| 1294 |
data=json_body, |
| 1295 |
query_params=query_params, |
| 1296 |
) |
| 1297 |
|
| 1298 |
def operation_stat( |
| 1299 |
self, |
| 1300 |
endpoint_id: uuid.UUID | str, |
| 1301 |
path: str | MissingType = MISSING, |
| 1302 |
*, |
| 1303 |
local_user: str | MissingType = MISSING, |
| 1304 |
query_params: dict[str, t.Any] | None = None, |
| 1305 |
) -> response.GlobusHTTPResponse: |
| 1306 |
""" |
| 1307 |
:param endpoint_id: The ID of the collection on which to do the stat operation |
| 1308 |
:param path: Path on the collection to do the stat operation on |
| 1309 |
:param local_user: Optional value passed to identity mapping specifying which |
| 1310 |
local user account to map to. Only usable with Globus Connect Server v5 |
| 1311 |
mapped collections. |
| 1312 |
:param query_params: Additional passthrough query parameters |
| 1313 |
|
| 1314 |
.. tab-set:: |
| 1315 |
|
| 1316 |
.. tab-item:: Example Usage |
| 1317 |
|
| 1318 |
.. code-block:: python |
| 1319 |
|
| 1320 |
tc = globus_sdk.TransferClient(...) |
| 1321 |
tc.operation_stat(ep_id, "/path/to/item") |
| 1322 |
|
| 1323 |
.. tab-item:: Example Response Data |
| 1324 |
|
| 1325 |
.. expandtestfixture:: transfer.operation_stat |
| 1326 |
|
| 1327 |
.. tab-item:: API Info |
| 1328 |
|
| 1329 |
``GET /operation/endpoint/<endpoint_id>/stat`` |
| 1330 |
|
| 1331 |
.. extdoclink:: Get File or Directory Status |
| 1332 |
:ref: transfer/file_operations/#stat |
| 1333 |
""" |
| 1334 |
query_params = { |
| 1335 |
"path": path, |
| 1336 |
"local_user": local_user, |
| 1337 |
**(query_params or {}), |
| 1338 |
} |
| 1339 |
log.debug(f"TransferClient.operation_stat({endpoint_id}, {query_params})") |
| 1340 |
return self.get( |
| 1341 |
f"/v0.10/operation/endpoint/{endpoint_id}/stat", query_params=query_params |
| 1342 |
) |
| 1343 |
|
| 1344 |
# |
| 1345 |
# Task Submission |
| 1346 |
# |
| 1347 |
|
| 1348 |
def get_submission_id( |
| 1349 |
self, *, query_params: dict[str, t.Any] | None = None |
| 1350 |
) -> response.GlobusHTTPResponse: |
| 1351 |
""" |
| 1352 |
:param query_params: Additional passthrough query parameters |
| 1353 |
|
| 1354 |
Submission IDs are required to submit tasks to the Transfer service |
| 1355 |
via the :meth:`submit_transfer <.submit_transfer>` and |
| 1356 |
:meth:`submit_delete <.submit_delete>` methods. |
| 1357 |
|
| 1358 |
Most users will not need to call this method directly, as the |
| 1359 |
methods :meth:`~submit_transfer` and :meth:`~submit_delete` will call it |
| 1360 |
automatically if the data does not contain a ``submission_id``. |
| 1361 |
|
| 1362 |
.. tab-set:: |
| 1363 |
|
| 1364 |
.. tab-item:: API Info |
| 1365 |
|
| 1366 |
``GET /submission_id`` |
| 1367 |
|
| 1368 |
.. extdoclink:: Get a submission ID |
| 1369 |
:ref: transfer/task_submit/#get_submission_id |
| 1370 |
|
| 1371 |
.. tab-item:: Example Response Data |
| 1372 |
|
| 1373 |
.. expandtestfixture:: transfer.get_submission_id |
| 1374 |
""" |
| 1375 |
log.debug(f"TransferClient.get_submission_id({query_params})") |
| 1376 |
return self.get("/v0.10/submission_id", query_params=query_params) |
| 1377 |
|
| 1378 |
def submit_transfer( |
| 1379 |
self, data: dict[str, t.Any] | TransferData |
| 1380 |
) -> response.GlobusHTTPResponse: |
| 1381 |
""" |
| 1382 |
:param data: A transfer task document listing files and directories, and setting |
| 1383 |
various options. See :class:`TransferData <globus_sdk.TransferData>` for |
| 1384 |
details |
| 1385 |
|
| 1386 |
Submit a Transfer Task. |
| 1387 |
|
| 1388 |
If no ``submission_id`` is included in the payload, one will be requested and |
| 1389 |
used automatically. The data passed to this method will be modified to include |
| 1390 |
the ``submission_id``. |
| 1391 |
|
| 1392 |
.. tab-set:: |
| 1393 |
|
| 1394 |
.. tab-item:: Example Usage |
| 1395 |
|
| 1396 |
.. code-block:: python |
| 1397 |
|
| 1398 |
tdata = globus_sdk.TransferData( |
| 1399 |
source_endpoint_id, |
| 1400 |
destination_endpoint_id, |
| 1401 |
label="SDK example", |
| 1402 |
sync_level="checksum", |
| 1403 |
) |
| 1404 |
tdata.add_item("/source/path/dir/", "/dest/path/dir/") |
| 1405 |
tdata.add_item("/source/path/file.txt", "/dest/path/file.txt") |
| 1406 |
|
| 1407 |
tc = globus_sdk.TransferClient(...) |
| 1408 |
transfer_result = tc.submit_transfer(tdata) |
| 1409 |
print("task_id =", transfer_result["task_id"]) |
| 1410 |
|
| 1411 |
The `data` parameter can be a normal Python dictionary, or |
| 1412 |
a :class:`TransferData <globus_sdk.TransferData>` object. |
| 1413 |
|
| 1414 |
.. tab-item:: API Info |
| 1415 |
|
| 1416 |
``POST /transfer`` |
| 1417 |
|
| 1418 |
.. extdoclink:: Submit a transfer task |
| 1419 |
:ref: transfer/task_submit/#submit_transfer_task |
| 1420 |
""" # noqa: E501 |
| 1421 |
log.debug("TransferClient.submit_transfer(...)") |
| 1422 |
if "submission_id" not in data or data["submission_id"] is MISSING: |
| 1423 |
log.debug("submit_transfer autofetching submission_id") |
| 1424 |
data["submission_id"] = self.get_submission_id()["value"] |
| 1425 |
return self.post("/v0.10/transfer", data=data) |
| 1426 |
|
| 1427 |
def submit_delete( |
| 1428 |
self, data: dict[str, t.Any] | DeleteData |
| 1429 |
) -> response.GlobusHTTPResponse: |
| 1430 |
""" |
| 1431 |
:param data: A delete task document listing files and directories, and setting |
| 1432 |
various options. See :class:`DeleteData <globus_sdk.DeleteData>` for |
| 1433 |
details |
| 1434 |
|
| 1435 |
Submit a Delete Task. |
| 1436 |
|
| 1437 |
If no ``submission_id`` is included in the payload, one will be requested and |
| 1438 |
used automatically. The data passed to this method will be modified to include |
| 1439 |
the ``submission_id``. |
| 1440 |
|
| 1441 |
.. tab-set:: |
| 1442 |
|
| 1443 |
.. tab-item:: Example Usage |
| 1444 |
|
| 1445 |
.. code-block:: python |
| 1446 |
|
| 1447 |
ddata = globus_sdk.DeleteData(endpoint_id, recursive=True) |
| 1448 |
ddata.add_item("/dir/to/delete/") |
| 1449 |
ddata.add_item("/file/to/delete/file.txt") |
| 1450 |
|
| 1451 |
tc = globus_sdk.TransferClient(...) |
| 1452 |
delete_result = tc.submit_delete(ddata) |
| 1453 |
print("task_id =", delete_result["task_id"]) |
| 1454 |
|
| 1455 |
The `data` parameter can be a normal Python dictionary, or |
| 1456 |
a :class:`DeleteData <globus_sdk.DeleteData>` object. |
| 1457 |
|
| 1458 |
.. tab-item:: API Info |
| 1459 |
|
| 1460 |
``POST /delete`` |
| 1461 |
|
| 1462 |
.. extdoclink:: Submit a delete task |
| 1463 |
:ref: transfer/task_submit/#submit_delete_task |
| 1464 |
""" |
| 1465 |
log.debug("TransferClient.submit_delete(...)") |
| 1466 |
if "submission_id" not in data or data["submission_id"] is MISSING: |
| 1467 |
log.debug("submit_delete autofetching submission_id") |
| 1468 |
data["submission_id"] = self.get_submission_id()["value"] |
| 1469 |
return self.post("/v0.10/delete", data=data) |
| 1470 |
|
| 1471 |
# |
| 1472 |
# Task inspection and management |
| 1473 |
# |
| 1474 |
|
| 1475 |
@paging.has_paginator( |
| 1476 |
paging.LimitOffsetTotalPaginator, |
| 1477 |
items_key="DATA", |
| 1478 |
get_page_size=_get_page_size, |
| 1479 |
max_total_results=1000, |
| 1480 |
page_size=1000, |
| 1481 |
) |
| 1482 |
def task_list( |
| 1483 |
self, |
| 1484 |
*, |
| 1485 |
limit: int | MissingType = MISSING, |
| 1486 |
offset: int | MissingType = MISSING, |
| 1487 |
orderby: str | list[str] | MissingType = MISSING, |
| 1488 |
# pylint: disable=redefined-builtin |
| 1489 |
filter: str | TransferFilterDict | MissingType = MISSING, |
| 1490 |
query_params: dict[str, t.Any] | None = None, |
| 1491 |
) -> IterableTransferResponse: |
| 1492 |
""" |
| 1493 |
Get an iterable of task documents owned by the current user. |
| 1494 |
|
| 1495 |
:param limit: limit the number of results |
| 1496 |
:param offset: offset used in paging |
| 1497 |
:param orderby: One or more order-by options. Each option is |
| 1498 |
either a field name or a field name followed by a space and 'ASC' or 'DESC' |
| 1499 |
for ascending or descending. See example usage for details. |
| 1500 |
:param filter: Only return task documents which match these filter clauses. For |
| 1501 |
the filter syntax, see the **External Documentation** linked below. If a |
| 1502 |
dict is supplied as the filter, it is formatted as a set of filter clauses. |
| 1503 |
See :ref:`filter formatting <transfer_filter_formatting>` for details. |
| 1504 |
:param query_params: Additional passthrough query parameters |
| 1505 |
|
| 1506 |
.. tab-set:: |
| 1507 |
|
| 1508 |
.. tab-item:: Example Usage |
| 1509 |
|
| 1510 |
Fetch 10 tasks and print some basic info: |
| 1511 |
|
| 1512 |
.. code-block:: python |
| 1513 |
|
| 1514 |
tc = TransferClient(...) |
| 1515 |
for task in tc.task_list(limit=10): |
| 1516 |
print( |
| 1517 |
f"Task({task['task_id']}): " |
| 1518 |
f"{task['source_endpoint']} -> {task['destination_endpoint']}" |
| 1519 |
) |
| 1520 |
|
| 1521 |
Fetch 3 *specific* tasks using a ``task_id`` filter: |
| 1522 |
|
| 1523 |
.. code-block:: python |
| 1524 |
|
| 1525 |
tc = TransferClient(...) |
| 1526 |
task_ids = [ |
| 1527 |
"acb4b581-b3f3-403a-a42a-9da97aaa9961", |
| 1528 |
"39447a3c-e002-401a-b95c-f48b69b4c60a", |
| 1529 |
"02330d3a-987b-4abb-97ed-6a22f8fa365e", |
| 1530 |
] |
| 1531 |
for task in tc.task_list(filter={"task_id": task_ids}): |
| 1532 |
print( |
| 1533 |
f"Task({task['task_id']}): " |
| 1534 |
f"{task['source_endpoint']} -> {task['destination_endpoint']}" |
| 1535 |
) |
| 1536 |
|
| 1537 |
Fetch the last 5 failed tasks by submission time: |
| 1538 |
|
| 1539 |
.. code-block:: python |
| 1540 |
|
| 1541 |
tc = TransferClient(...) |
| 1542 |
for task in tc.task_list( |
| 1543 |
limit=5, |
| 1544 |
orderby="request_time DESC", |
| 1545 |
filter={"status": "FAILED"} |
| 1546 |
): |
| 1547 |
print( |
| 1548 |
f"Task({task['task_id']}) failed: " |
| 1549 |
f"{task['source_endpoint']} -> {task['destination_endpoint']}" |
| 1550 |
) |
| 1551 |
|
| 1552 |
|
| 1553 |
.. tab-item:: Paginated Usage |
| 1554 |
|
| 1555 |
.. paginatedusage:: task_list |
| 1556 |
|
| 1557 |
.. tab-item:: API Info |
| 1558 |
|
| 1559 |
``GET /task_list`` |
| 1560 |
|
| 1561 |
.. extdoclink:: Task List |
| 1562 |
:ref: transfer/task/#get_task_list |
| 1563 |
""" # noqa: E501 |
| 1564 |
log.debug("TransferClient.task_list(...)") |
| 1565 |
query_params = { |
| 1566 |
"limit": limit, |
| 1567 |
"offset": offset, |
| 1568 |
"orderby": commajoin(orderby), |
| 1569 |
"filter": _format_filter_item(filter), |
| 1570 |
**(query_params or {}), |
| 1571 |
} |
| 1572 |
return IterableTransferResponse( |
| 1573 |
self.get("/v0.10/task_list", query_params=query_params) |
| 1574 |
) |
| 1575 |
|
| 1576 |
@paging.has_paginator( |
| 1577 |
paging.LimitOffsetTotalPaginator, |
| 1578 |
items_key="DATA", |
| 1579 |
get_page_size=_get_page_size, |
| 1580 |
max_total_results=1000, |
| 1581 |
page_size=1000, |
| 1582 |
) |
| 1583 |
def task_event_list( |
| 1584 |
self, |
| 1585 |
task_id: uuid.UUID | str, |
| 1586 |
*, |
| 1587 |
limit: int | MissingType = MISSING, |
| 1588 |
offset: int | MissingType = MISSING, |
| 1589 |
query_params: dict[str, t.Any] | None = None, |
| 1590 |
) -> IterableTransferResponse: |
| 1591 |
r""" |
| 1592 |
List events (for example, faults and errors) for a given Task. |
| 1593 |
|
| 1594 |
:param task_id: The ID of the task to inspect |
| 1595 |
:param limit: limit the number of results |
| 1596 |
:param offset: offset used in paging |
| 1597 |
:param query_params: Additional passthrough query parameters |
| 1598 |
|
| 1599 |
.. tab-set:: |
| 1600 |
|
| 1601 |
.. tab-item:: Example Usage |
| 1602 |
|
| 1603 |
Fetch 10 events and print some basic info: |
| 1604 |
|
| 1605 |
.. code-block:: python |
| 1606 |
|
| 1607 |
tc = TransferClient(...) |
| 1608 |
task_id = ... |
| 1609 |
for event in tc.task_event_list(task_id, limit=10): |
| 1610 |
print(f"Event on Task({task_id}) at {event['time']}:\n{event['description']}") |
| 1611 |
|
| 1612 |
.. tab-item:: Paginated Usage |
| 1613 |
|
| 1614 |
.. paginatedusage:: task_event_list |
| 1615 |
|
| 1616 |
.. tab-item:: API Info |
| 1617 |
|
| 1618 |
``GET /task/<task_id>/event_list`` |
| 1619 |
|
| 1620 |
.. extdoclink:: Get Event List |
| 1621 |
:ref: transfer/task/#get_event_list |
| 1622 |
""" # noqa: E501 |
| 1623 |
log.debug(f"TransferClient.task_event_list({task_id}, ...)") |
| 1624 |
query_params = { |
| 1625 |
"limit": limit, |
| 1626 |
"offset": offset, |
| 1627 |
**(query_params or {}), |
| 1628 |
} |
| 1629 |
return IterableTransferResponse( |
| 1630 |
self.get(f"/v0.10/task/{task_id}/event_list", query_params=query_params) |
| 1631 |
) |
| 1632 |
|
| 1633 |
def get_task( |
| 1634 |
self, |
| 1635 |
task_id: uuid.UUID | str, |
| 1636 |
*, |
| 1637 |
query_params: dict[str, t.Any] | None = None, |
| 1638 |
) -> response.GlobusHTTPResponse: |
| 1639 |
""" |
| 1640 |
:param task_id: The ID of the task to inspect |
| 1641 |
:param query_params: Additional passthrough query parameters |
| 1642 |
|
| 1643 |
.. tab-set:: |
| 1644 |
|
| 1645 |
.. tab-item:: API Info |
| 1646 |
|
| 1647 |
``GET /task/<task_id>`` |
| 1648 |
|
| 1649 |
.. extdoclink:: Get task by ID |
| 1650 |
:ref: transfer/task/#get_task_by_id |
| 1651 |
""" |
| 1652 |
log.debug(f"TransferClient.get_task({task_id}, ...)") |
| 1653 |
return self.get(f"/v0.10/task/{task_id}", query_params=query_params) |
| 1654 |
|
| 1655 |
def update_task( |
| 1656 |
self, |
| 1657 |
task_id: uuid.UUID | str, |
| 1658 |
data: dict[str, t.Any], |
| 1659 |
*, |
| 1660 |
query_params: dict[str, t.Any] | None = None, |
| 1661 |
) -> response.GlobusHTTPResponse: |
| 1662 |
""" |
| 1663 |
Modify a task. Only tasks which are still running can be modified, and only the |
| 1664 |
``label`` and ``deadline`` fields can be updated. |
| 1665 |
|
| 1666 |
:param task_id: The ID of the task to modify |
| 1667 |
:param data: A partial task document with fields to update |
| 1668 |
:param query_params: Additional passthrough query parameters |
| 1669 |
|
| 1670 |
.. tab-set:: |
| 1671 |
|
| 1672 |
.. tab-item:: API Info |
| 1673 |
|
| 1674 |
``PUT /task/<task_id>`` |
| 1675 |
|
| 1676 |
.. extdoclink:: Update task by ID |
| 1677 |
:ref: transfer/task/#update_task_by_id |
| 1678 |
""" |
| 1679 |
log.debug(f"TransferClient.update_task({task_id}, ...)") |
| 1680 |
return self.put(f"/v0.10/task/{task_id}", data=data, query_params=query_params) |
| 1681 |
|
| 1682 |
def cancel_task(self, task_id: uuid.UUID | str) -> response.GlobusHTTPResponse: |
| 1683 |
""" |
| 1684 |
Cancel a task which is still running. |
| 1685 |
|
| 1686 |
:param task_id: The ID of the task to cancel |
| 1687 |
|
| 1688 |
.. tab-set:: |
| 1689 |
|
| 1690 |
.. tab-item:: API Info |
| 1691 |
|
| 1692 |
``POST /task/<task_id>/cancel`` |
| 1693 |
|
| 1694 |
.. extdoclink:: Cancel task by ID |
| 1695 |
:ref: transfer/task/#cancel_task_by_id |
| 1696 |
""" |
| 1697 |
log.debug(f"TransferClient.cancel_task({task_id})") |
| 1698 |
return self.post(f"/v0.10/task/{task_id}/cancel") |
| 1699 |
|
| 1700 |
def task_wait( |
| 1701 |
self, task_id: uuid.UUID | str, *, timeout: int = 10, polling_interval: int = 10 |
| 1702 |
) -> bool: |
| 1703 |
r""" |
| 1704 |
Wait until a Task is complete or fails, with a time limit. If the task |
| 1705 |
is "ACTIVE" after time runs out, returns ``False``. Otherwise returns |
| 1706 |
``True``. |
| 1707 |
|
| 1708 |
:param task_id: ID of the Task to wait on for completion |
| 1709 |
:param timeout: Number of seconds to wait in total. Minimum 1. [Default: ``10``] |
| 1710 |
:param polling_interval: Number of seconds between queries to Globus about the |
| 1711 |
Task status. Minimum 1. [Default: ``10``] |
| 1712 |
|
| 1713 |
.. tab-set:: |
| 1714 |
|
| 1715 |
.. tab-item:: Example Usage |
| 1716 |
|
| 1717 |
If you want to wait for a task to terminate, but want to warn every |
| 1718 |
minute that it doesn't terminate, you could: |
| 1719 |
|
| 1720 |
.. code-block:: python |
| 1721 |
|
| 1722 |
tc = TransferClient(...) |
| 1723 |
while not tc.task_wait(task_id, timeout=60): |
| 1724 |
print(f"Another minute went by without {task_id} terminating") |
| 1725 |
|
| 1726 |
Or perhaps you want to check on a task every minute for 10 minutes, and |
| 1727 |
give up if it doesn't complete in that time: |
| 1728 |
|
| 1729 |
.. code-block:: python |
| 1730 |
|
| 1731 |
tc = TransferClient(...) |
| 1732 |
done = tc.task_wait(task_id, timeout=600, polling_interval=60) |
| 1733 |
if not done: |
| 1734 |
print(f"{task_id} didn't successfully terminate!") |
| 1735 |
else: |
| 1736 |
print(f"{task_id} completed") |
| 1737 |
|
| 1738 |
You could print dots while you wait for a task by only waiting one |
| 1739 |
second at a time: |
| 1740 |
|
| 1741 |
.. code-block:: python |
| 1742 |
|
| 1743 |
tc = TransferClient(...) |
| 1744 |
while not tc.task_wait(task_id, timeout=1, polling_interval=1): |
| 1745 |
print(".", end="") |
| 1746 |
print(f"\n{task_id} completed!") |
| 1747 |
""" # noqa: E501 |
| 1748 |
log.debug( |
| 1749 |
"TransferClient.task_wait(%s, %s, %s)", task_id, timeout, polling_interval |
| 1750 |
) |
| 1751 |
|
| 1752 |
# check valid args |
| 1753 |
if timeout < 1: |
| 1754 |
log.error(f"task_wait() timeout={timeout} is less than minimum of 1s") |
| 1755 |
raise exc.GlobusSDKUsageError( |
| 1756 |
"TransferClient.task_wait timeout has a minimum of 1" |
| 1757 |
) |
| 1758 |
if polling_interval < 1: |
| 1759 |
log.error( |
| 1760 |
"task_wait() polling_interval={} is less than minimum of 1s".format( |
| 1761 |
polling_interval |
| 1762 |
) |
| 1763 |
) |
| 1764 |
raise exc.GlobusSDKUsageError( |
| 1765 |
"TransferClient.task_wait polling_interval has a minimum of 1" |
| 1766 |
) |
| 1767 |
|
| 1768 |
# ensure that we always wait at least one interval, even if the timeout |
| 1769 |
# is shorter than the polling interval, by reducing the interval to the |
| 1770 |
# timeout if it is larger |
| 1771 |
polling_interval = min(timeout, polling_interval) |
| 1772 |
|
| 1773 |
# helper for readability |
| 1774 |
def timed_out(waited_time: int) -> bool: |
| 1775 |
return waited_time > timeout |
| 1776 |
|
| 1777 |
waited_time = 0 |
| 1778 |
# doing this as a while-True loop actually makes it simpler than doing |
| 1779 |
# while not timed_out(waited_time) because of the end condition |
| 1780 |
while True: |
| 1781 |
# get task, check if status != ACTIVE |
| 1782 |
task = self.get_task(task_id) |
| 1783 |
status = task["status"] |
| 1784 |
if status != "ACTIVE": |
| 1785 |
log.debug( |
| 1786 |
"task_wait(task_id={}) terminated with status={}".format( |
| 1787 |
task_id, status |
| 1788 |
) |
| 1789 |
) |
| 1790 |
return True |
| 1791 |
|
| 1792 |
# make sure to check if we timed out before sleeping again, so we |
| 1793 |
# don't sleep an extra polling_interval |
| 1794 |
waited_time += polling_interval |
| 1795 |
if timed_out(waited_time): |
| 1796 |
log.debug(f"task_wait(task_id={task_id}) timed out") |
| 1797 |
return False |
| 1798 |
|
| 1799 |
log.debug(f"task_wait(task_id={task_id}) waiting {polling_interval}s") |
| 1800 |
time.sleep(polling_interval) |
| 1801 |
# unreachable -- end of task_wait |
| 1802 |
|
| 1803 |
def task_pause_info( |
| 1804 |
self, |
| 1805 |
task_id: uuid.UUID | str, |
| 1806 |
*, |
| 1807 |
query_params: dict[str, t.Any] | None = None, |
| 1808 |
) -> response.GlobusHTTPResponse: |
| 1809 |
""" |
| 1810 |
Get info about why a task is paused or about to be paused. |
| 1811 |
|
| 1812 |
:param task_id: The ID of the task to inspect |
| 1813 |
:param query_params: Additional passthrough query parameters |
| 1814 |
|
| 1815 |
.. tab-set:: |
| 1816 |
|
| 1817 |
.. tab-item:: API Info |
| 1818 |
|
| 1819 |
``GET /task/<task_id>/pause_info`` |
| 1820 |
|
| 1821 |
.. extdoclink:: Get task pause info |
| 1822 |
:ref: transfer/task/#get_task_pause_info |
| 1823 |
""" |
| 1824 |
log.debug(f"TransferClient.task_pause_info({task_id}, ...)") |
| 1825 |
return self.get(f"/v0.10/task/{task_id}/pause_info", query_params=query_params) |
| 1826 |
|
| 1827 |
@paging.has_paginator( |
| 1828 |
paging.NullableMarkerPaginator, items_key="DATA", marker_key="next_marker" |
| 1829 |
) |
| 1830 |
def task_successful_transfers( |
| 1831 |
self, |
| 1832 |
task_id: uuid.UUID | str, |
| 1833 |
*, |
| 1834 |
marker: str | MissingType = MISSING, |
| 1835 |
query_params: dict[str, t.Any] | None = None, |
| 1836 |
) -> IterableTransferResponse: |
| 1837 |
""" |
| 1838 |
Get the successful file transfers for a completed Task. |
| 1839 |
|
| 1840 |
.. note:: |
| 1841 |
|
| 1842 |
Only files that were actually transferred are included. This does |
| 1843 |
not include directories, files that were checked but skipped as |
| 1844 |
part of a sync transfer, or files which were skipped due to |
| 1845 |
skip_source_errors being set on the task. |
| 1846 |
|
| 1847 |
:param task_id: The ID of the task to inspect |
| 1848 |
:param marker: A marker for pagination |
| 1849 |
:param query_params: Additional passthrough query parameters |
| 1850 |
|
| 1851 |
.. tab-set:: |
| 1852 |
|
| 1853 |
.. tab-item:: Example Usage |
| 1854 |
|
| 1855 |
Fetch all transferred files for a task and print some basic info: |
| 1856 |
|
| 1857 |
.. code-block:: python |
| 1858 |
|
| 1859 |
tc = TransferClient(...) |
| 1860 |
task_id = ... |
| 1861 |
for info in tc.task_successful_transfers(task_id): |
| 1862 |
print(f"{info['source_path']} -> {info['destination_path']}") |
| 1863 |
|
| 1864 |
.. tab-item:: Paginated Usage |
| 1865 |
|
| 1866 |
.. paginatedusage:: task_successful_transfers |
| 1867 |
|
| 1868 |
.. tab-item:: API Info |
| 1869 |
|
| 1870 |
``GET /task/<task_id>/successful_transfers`` |
| 1871 |
|
| 1872 |
.. extdoclink:: Get Task Successful Transfers |
| 1873 |
:ref: transfer/task/#get_task_successful_transfers |
| 1874 |
""" # noqa: E501 |
| 1875 |
log.debug(f"TransferClient.task_successful_transfers({task_id}, ...)") |
| 1876 |
query_params = { |
| 1877 |
"marker": marker, |
| 1878 |
**(query_params or {}), |
| 1879 |
} |
| 1880 |
return IterableTransferResponse( |
| 1881 |
self.get( |
| 1882 |
f"/v0.10/task/{task_id}/successful_transfers", query_params=query_params |
| 1883 |
) |
| 1884 |
) |
| 1885 |
|
| 1886 |
@paging.has_paginator( |
| 1887 |
paging.NullableMarkerPaginator, items_key="DATA", marker_key="next_marker" |
| 1888 |
) |
| 1889 |
def task_skipped_errors( |
| 1890 |
self, |
| 1891 |
task_id: uuid.UUID | str, |
| 1892 |
*, |
| 1893 |
marker: str | MissingType = MISSING, |
| 1894 |
query_params: dict[str, t.Any] | None = None, |
| 1895 |
) -> IterableTransferResponse: |
| 1896 |
""" |
| 1897 |
Get path and error information for all paths that were skipped due |
| 1898 |
to skip_source_errors being set on a completed transfer Task. |
| 1899 |
|
| 1900 |
:param task_id: The ID of the task to inspect |
| 1901 |
:param marker: A marker for pagination |
| 1902 |
:param query_params: Additional passthrough query parameters |
| 1903 |
|
| 1904 |
.. tab-set:: |
| 1905 |
|
| 1906 |
.. tab-item:: Example Usage |
| 1907 |
|
| 1908 |
Fetch all skipped errors for a task and print some basic info: |
| 1909 |
|
| 1910 |
.. code-block:: python |
| 1911 |
|
| 1912 |
tc = TransferClient(...) |
| 1913 |
task_id = ... |
| 1914 |
for info in tc.task_skipped_errors(task_id): |
| 1915 |
print(f"{info['error_code']} -> {info['source_path']}") |
| 1916 |
|
| 1917 |
.. tab-item:: Paginated Usage |
| 1918 |
|
| 1919 |
.. paginatedusage:: task_skipped_errors |
| 1920 |
|
| 1921 |
.. tab-item:: API Info |
| 1922 |
|
| 1923 |
``GET /task/<task_id>/skipped_errors`` |
| 1924 |
|
| 1925 |
.. extdoclink:: Get Task Skipped Errors |
| 1926 |
:ref: transfer/task/#get_task_skipped_errors |
| 1927 |
""" # noqa: E501 |
| 1928 |
log.debug("TransferClient.task_skipped_errors(%s, ...)", task_id) |
| 1929 |
query_params = { |
| 1930 |
"marker": marker, |
| 1931 |
**(query_params or {}), |
| 1932 |
} |
| 1933 |
return IterableTransferResponse( |
| 1934 |
self.get(f"/v0.10/task/{task_id}/skipped_errors", query_params=query_params) |
| 1935 |
) |
| 1936 |
|
| 1937 |
# |
| 1938 |
# advanced endpoint management (requires endpoint manager role) |
| 1939 |
# |
| 1940 |
|
| 1941 |
def endpoint_manager_monitored_endpoints( |
| 1942 |
self, *, query_params: dict[str, t.Any] | None = None |
| 1943 |
) -> IterableTransferResponse: |
| 1944 |
""" |
| 1945 |
Get endpoints the current user is a monitor or manager on. |
| 1946 |
|
| 1947 |
:param query_params: Additional passthrough query parameters |
| 1948 |
|
| 1949 |
.. tab-set:: |
| 1950 |
|
| 1951 |
.. tab-item:: API Info |
| 1952 |
|
| 1953 |
``GET endpoint_manager/monitored_endpoints`` |
| 1954 |
|
| 1955 |
.. extdoclink:: Get monitored endpoints and collections |
| 1956 |
:ref: transfer/advanced_collection_management/#get_monitored_endpoints_and_collections |
| 1957 |
""" # noqa: E501 |
| 1958 |
log.debug( |
| 1959 |
f"TransferClient.endpoint_manager_monitored_endpoints({query_params})" |
| 1960 |
) |
| 1961 |
return IterableTransferResponse( |
| 1962 |
self.get( |
| 1963 |
"/v0.10/endpoint_manager/monitored_endpoints", query_params=query_params |
| 1964 |
) |
| 1965 |
) |
| 1966 |
|
| 1967 |
def endpoint_manager_hosted_endpoint_list( |
| 1968 |
self, |
| 1969 |
endpoint_id: uuid.UUID | str, |
| 1970 |
*, |
| 1971 |
query_params: dict[str, t.Any] | None = None, |
| 1972 |
) -> IterableTransferResponse: |
| 1973 |
""" |
| 1974 |
Get shared endpoints hosted on the given endpoint. |
| 1975 |
|
| 1976 |
:param endpoint_id: The ID of the host endpoint |
| 1977 |
:param query_params: Additional passthrough query parameters |
| 1978 |
|
| 1979 |
.. tab-set:: |
| 1980 |
|
| 1981 |
.. tab-item:: API Info |
| 1982 |
|
| 1983 |
``GET /endpoint_manager/endpoint/<endpoint_id>/hosted_endpoint_list`` |
| 1984 |
|
| 1985 |
.. extdoclink:: Get hosted endpoint list |
| 1986 |
:ref: transfer/advanced_collection_management/#get_hosted_collection_list |
| 1987 |
""" # noqa: E501 |
| 1988 |
log.debug( |
| 1989 |
f"TransferClient.endpoint_manager_hosted_endpoint_list({endpoint_id})" |
| 1990 |
) |
| 1991 |
return IterableTransferResponse( |
| 1992 |
self.get( |
| 1993 |
f"/v0.10/endpoint_manager/endpoint/{endpoint_id}/hosted_endpoint_list", |
| 1994 |
query_params=query_params, |
| 1995 |
) |
| 1996 |
) |
| 1997 |
|
| 1998 |
def endpoint_manager_get_endpoint( |
| 1999 |
self, |
| 2000 |
endpoint_id: uuid.UUID | str, |
| 2001 |
*, |
| 2002 |
query_params: dict[str, t.Any] | None = None, |
| 2003 |
) -> response.GlobusHTTPResponse: |
| 2004 |
""" |
| 2005 |
Get endpoint details as an admin. |
| 2006 |
|
| 2007 |
:param endpoint_id: The ID of the endpoint |
| 2008 |
:param query_params: Additional passthrough query parameters |
| 2009 |
|
| 2010 |
.. tab-set:: |
| 2011 |
|
| 2012 |
.. tab-item:: API Info |
| 2013 |
|
| 2014 |
``GET /endpoint_manager/endpoint/<endpoint_id>`` |
| 2015 |
|
| 2016 |
.. extdoclink:: Get endpoint as admin |
| 2017 |
:ref: transfer/advanced_collection_management/#mc_get_endpoint_or_collection |
| 2018 |
""" # noqa: E501 |
| 2019 |
log.debug(f"TransferClient.endpoint_manager_get_endpoint({endpoint_id})") |
| 2020 |
return self.get( |
| 2021 |
f"/v0.10/endpoint_manager/endpoint/{endpoint_id}", query_params=query_params |
| 2022 |
) |
| 2023 |
|
| 2024 |
def endpoint_manager_acl_list( |
| 2025 |
self, |
| 2026 |
endpoint_id: uuid.UUID | str, |
| 2027 |
*, |
| 2028 |
query_params: dict[str, t.Any] | None = None, |
| 2029 |
) -> IterableTransferResponse: |
| 2030 |
""" |
| 2031 |
Get a list of access control rules on specified endpoint as an admin. |
| 2032 |
|
| 2033 |
:param endpoint_id: The ID of the endpoint |
| 2034 |
:param query_params: Additional passthrough query parameters |
| 2035 |
|
| 2036 |
.. tab-set:: |
| 2037 |
|
| 2038 |
.. tab-item:: API Info |
| 2039 |
|
| 2040 |
``GET endpoint_manager/endpoint/<endpoint_id>/access_list`` |
| 2041 |
|
| 2042 |
.. extdoclink:: Get guest collection access list as admin |
| 2043 |
:ref: transfer/advanced_collection_management/#get_guest_collection_access_list_as_admin |
| 2044 |
""" # noqa: E501 |
| 2045 |
log.debug( |
| 2046 |
f"TransferClient.endpoint_manager_endpoint_acl_list({endpoint_id}, ...)" |
| 2047 |
) |
| 2048 |
return IterableTransferResponse( |
| 2049 |
self.get( |
| 2050 |
f"/v0.10/endpoint_manager/endpoint/{endpoint_id}/access_list", |
| 2051 |
query_params=query_params, |
| 2052 |
) |
| 2053 |
) |
| 2054 |
|
| 2055 |
# |
| 2056 |
# endpoint manager task methods |
| 2057 |
# |
| 2058 |
|
| 2059 |
@paging.has_paginator(paging.LastKeyPaginator, items_key="DATA") |
| 2060 |
def endpoint_manager_task_list( |
| 2061 |
self, |
| 2062 |
*, |
| 2063 |
filter_status: str | t.Iterable[str] | MissingType = MISSING, |
| 2064 |
filter_task_id: ( |
| 2065 |
uuid.UUID | str | t.Iterable[uuid.UUID | str] | MissingType |
| 2066 |
) = MISSING, |
| 2067 |
filter_owner_id: uuid.UUID | str | MissingType = MISSING, |
| 2068 |
filter_endpoint: uuid.UUID | str | MissingType = MISSING, |
| 2069 |
filter_endpoint_use: t.Literal["source", "destination"] | MissingType = MISSING, |
| 2070 |
filter_is_paused: bool | MissingType = MISSING, |
| 2071 |
filter_completion_time: str | tuple[DateLike, DateLike] | MissingType = MISSING, |
| 2072 |
filter_min_faults: int | MissingType = MISSING, |
| 2073 |
filter_local_user: str | MissingType = MISSING, |
| 2074 |
last_key: str | MissingType = MISSING, |
| 2075 |
query_params: dict[str, t.Any] | None = None, |
| 2076 |
) -> IterableTransferResponse: |
| 2077 |
r""" |
| 2078 |
Get a list of tasks visible via ``activity_monitor`` role, as opposed |
| 2079 |
to tasks owned by the current user. |
| 2080 |
|
| 2081 |
For any query that doesn't specify a ``filter_status`` that is a subset of |
| 2082 |
``("ACTIVE", "INACTIVE")``, at least one of ``filter_task_id`` or |
| 2083 |
``filter_endpoint`` is required. |
| 2084 |
|
| 2085 |
:param filter_status: Return only tasks with any of the specified statuses |
| 2086 |
Note that in-progress tasks will have status ``"ACTIVE"`` or ``"INACTIVE"``, |
| 2087 |
and completed tasks will have status ``"SUCCEEDED"`` or ``"FAILED"``. |
| 2088 |
:param filter_task_id: Return only tasks with any of the specified ids. If any |
| 2089 |
of the specified tasks do not involve an endpoint the user has an |
| 2090 |
appropriate role for, a ``PermissionDenied`` error will be returned. This |
| 2091 |
filter can't be combined with any other filter. If another filter is |
| 2092 |
passed, a ``BadRequest`` will be returned. (limit: 50 task IDs) |
| 2093 |
:param filter_owner_id: A Globus Auth identity id. Limit results to tasks |
| 2094 |
submitted by the specified identity, or linked to the specified identity, |
| 2095 |
at submit time. Returns ``UserNotFound`` if the identity does not exist or |
| 2096 |
has never used the Globus Transfer service. If no tasks were submitted by |
| 2097 |
this user to an endpoint the current user has an appropriate role on, an |
| 2098 |
empty result set will be returned. Unless filtering for running tasks (i.e. |
| 2099 |
``filter_status`` is a subset of ``("ACTIVE", "INACTIVE")``, |
| 2100 |
``filter_endpoint`` is required when using ``filter_owner_id``. |
| 2101 |
:param filter_endpoint: Single endpoint id. Return only tasks with a matching |
| 2102 |
source or destination endpoint or matching source or destination host |
| 2103 |
endpoint. |
| 2104 |
:param filter_endpoint_use: In combination with ``filter_endpoint``, filter to |
| 2105 |
tasks where the endpoint or collection was used specifically as the source or |
| 2106 |
destination of the transfer. |
| 2107 |
:param filter_is_paused: Return only tasks with the specified ``is_paused`` |
| 2108 |
value. Requires that ``filter_status`` is also passed and contains a subset |
| 2109 |
of ``"ACTIVE"`` and ``"INACTIVE"``. Completed tasks always have |
| 2110 |
``is_paused`` equal to ``False`` and filtering on their paused state is not |
| 2111 |
useful and not supported. Note that pausing is an async operation, and |
| 2112 |
after a pause rule is inserted it will take time before the ``is_paused`` |
| 2113 |
flag is set on all affected tasks. Tasks paused by id will have the |
| 2114 |
``is_paused`` flag set immediately. |
| 2115 |
:param filter_completion_time: Start and end date-times separated by a comma, or |
| 2116 |
provided as a tuple of strings or datetime objects. Returns only completed |
| 2117 |
tasks with ``completion_time`` in the specified range. Date strings should |
| 2118 |
be specified in one of the following ISO 8601 formats: |
| 2119 |
``YYYY-MM-DDTHH:MM:SS``, ``YYYY-MM-DDTHH:MM:SS+/-HH:MM``, or |
| 2120 |
``YYYY-MM-DDTHH:MM:SSZ``. If no timezone is specified, UTC is assumed. A |
| 2121 |
space can be used between the date and time instead of ``T``. A blank string |
| 2122 |
may be used for either the start or end (but not both) to indicate no limit |
| 2123 |
on that side. If the end date is blank, the filter will also include all |
| 2124 |
active tasks, since they will complete some time in the future. |
| 2125 |
:param filter_min_faults: Minimum number of cumulative faults, inclusive. |
| 2126 |
Return only tasks with ``faults >= N``, where ``N`` is the filter value. |
| 2127 |
Use ``filter_min_faults=1`` to find all tasks with at least one fault. |
| 2128 |
Note that many errors are not fatal and the task may still be successful |
| 2129 |
even if ``faults >= 1``. |
| 2130 |
:param filter_local_user: A valid username for the target system running the |
| 2131 |
endpoint, as a utf8 encoded string. Requires that ``filter_endpoint`` is |
| 2132 |
also set. Return only tasks that have successfully fetched the local user |
| 2133 |
from the endpoint, and match the values of ``filter_endpoint`` and |
| 2134 |
``filter_local_user`` on the source or on the destination. |
| 2135 |
:param last_key: the last key, for paging |
| 2136 |
:param query_params: Additional passthrough query parameters |
| 2137 |
|
| 2138 |
.. tab-set:: |
| 2139 |
|
| 2140 |
.. tab-item:: Example Usage |
| 2141 |
|
| 2142 |
Fetch some tasks and print some basic info: |
| 2143 |
|
| 2144 |
.. code-block:: python |
| 2145 |
|
| 2146 |
tc = TransferClient(...) |
| 2147 |
for task in tc.endpoint_manager_task_list(filter_status="ACTIVE"): |
| 2148 |
print( |
| 2149 |
f"Task({task['task_id']}): " |
| 2150 |
f"{task['source_endpoint']} -> {task['destination_endpoint']}\n" |
| 2151 |
" was submitted by\n" |
| 2152 |
f" {task['owner_string']}" |
| 2153 |
) |
| 2154 |
|
| 2155 |
.. tab-item:: Paginated Usage |
| 2156 |
|
| 2157 |
.. paginatedusage:: endpoint_manager_task_list |
| 2158 |
|
| 2159 |
For example, fetch and print all active tasks visible via |
| 2160 |
``activity_monitor`` permissions: |
| 2161 |
|
| 2162 |
.. code-block:: python |
| 2163 |
|
| 2164 |
tc = TransferClient(...) |
| 2165 |
for page in tc.paginated.endpoint_manager_task_list(filter_status="ACTIVE"): |
| 2166 |
for task in page: |
| 2167 |
print( |
| 2168 |
f"Task({task['task_id']}): " |
| 2169 |
f"{task['source_endpoint']} -> {task['destination_endpoint']}\n" |
| 2170 |
" was submitted by\n" |
| 2171 |
f" {task['owner_string']}" |
| 2172 |
) |
| 2173 |
|
| 2174 |
.. tab-item:: API Info |
| 2175 |
|
| 2176 |
``GET endpoint_manager/task_list`` |
| 2177 |
|
| 2178 |
.. extdoclink:: Advanced Collection Management: Get tasks |
| 2179 |
:ref: transfer/advanced_collection_management/#get_tasks |
| 2180 |
""" # noqa: E501 |
| 2181 |
log.debug("TransferClient.endpoint_manager_task_list(...)") |
| 2182 |
if filter_endpoint is MISSING and filter_endpoint_use is not MISSING: |
| 2183 |
raise exc.GlobusSDKUsageError( |
| 2184 |
"`filter_endpoint_use` is only valid when `filter_endpoint` is " |
| 2185 |
"also supplied." |
| 2186 |
) |
| 2187 |
query_params = { |
| 2188 |
"filter_status": commajoin(filter_status), |
| 2189 |
"filter_task_id": commajoin(filter_task_id), |
| 2190 |
"filter_owner_id": filter_owner_id, |
| 2191 |
"filter_endpoint": filter_endpoint, |
| 2192 |
"filter_endpoint_use": filter_endpoint_use, |
| 2193 |
"filter_is_paused": filter_is_paused, |
| 2194 |
"filter_completion_time": _format_completion_time(filter_completion_time), |
| 2195 |
"filter_min_faults": filter_min_faults, |
| 2196 |
"filter_local_user": filter_local_user, |
| 2197 |
"last_key": last_key, |
| 2198 |
**(query_params or {}), |
| 2199 |
} |
| 2200 |
return IterableTransferResponse( |
| 2201 |
self.get("/v0.10/endpoint_manager/task_list", query_params=query_params) |
| 2202 |
) |
| 2203 |
|
| 2204 |
def endpoint_manager_get_task( |
| 2205 |
self, |
| 2206 |
task_id: uuid.UUID | str, |
| 2207 |
*, |
| 2208 |
query_params: dict[str, t.Any] | None = None, |
| 2209 |
) -> response.GlobusHTTPResponse: |
| 2210 |
""" |
| 2211 |
Get task info as an admin. Requires activity monitor effective role on |
| 2212 |
the destination endpoint of the task. |
| 2213 |
|
| 2214 |
:param task_id: The ID of the task to inspect |
| 2215 |
:param query_params: Additional passthrough query parameters |
| 2216 |
|
| 2217 |
.. tab-set:: |
| 2218 |
|
| 2219 |
.. tab-item:: API Info |
| 2220 |
|
| 2221 |
``GET /endpoint_manager/task/<task_id>`` |
| 2222 |
|
| 2223 |
.. extdoclink:: Advanced Collection Management: Get task |
| 2224 |
:ref: transfer/advanced_collection_management/#get_task |
| 2225 |
""" |
| 2226 |
log.debug(f"TransferClient.endpoint_manager_get_task({task_id}, ...)") |
| 2227 |
return self.get( |
| 2228 |
f"/v0.10/endpoint_manager/task/{task_id}", query_params=query_params |
| 2229 |
) |
| 2230 |
|
| 2231 |
@paging.has_paginator( |
| 2232 |
paging.LimitOffsetTotalPaginator, |
| 2233 |
items_key="DATA", |
| 2234 |
get_page_size=_get_page_size, |
| 2235 |
max_total_results=1000, |
| 2236 |
page_size=1000, |
| 2237 |
) |
| 2238 |
def endpoint_manager_task_event_list( |
| 2239 |
self, |
| 2240 |
task_id: uuid.UUID | str, |
| 2241 |
*, |
| 2242 |
limit: int | MissingType = MISSING, |
| 2243 |
offset: int | MissingType = MISSING, |
| 2244 |
filter_is_error: bool | MissingType = MISSING, |
| 2245 |
query_params: dict[str, t.Any] | None = None, |
| 2246 |
) -> IterableTransferResponse: |
| 2247 |
""" |
| 2248 |
List events (for example, faults and errors) for a given task as an |
| 2249 |
admin. Requires activity monitor effective role on the destination |
| 2250 |
endpoint of the task. |
| 2251 |
|
| 2252 |
:param task_id: The ID of the task to inspect |
| 2253 |
:param limit: limit the number of results |
| 2254 |
:param offset: offset used in paging |
| 2255 |
:param filter_is_error: Return only events that are errors. A value of ``False`` |
| 2256 |
(returning only non-errors) is not supported. By default all events are |
| 2257 |
returned. |
| 2258 |
:param query_params: Additional passthrough query parameters |
| 2259 |
|
| 2260 |
.. tab-set:: |
| 2261 |
|
| 2262 |
.. tab-item:: Paginated Usage |
| 2263 |
|
| 2264 |
.. paginatedusage:: endpoint_manager_task_event_list |
| 2265 |
|
| 2266 |
.. tab-item:: API Info |
| 2267 |
|
| 2268 |
``GET /task/<task_id>/event_list`` |
| 2269 |
|
| 2270 |
.. extdoclink:: Advanced Collection Management: Get task events |
| 2271 |
:ref: transfer/advanced_collection_management/#get_task_events |
| 2272 |
""" |
| 2273 |
log.debug(f"TransferClient.endpoint_manager_task_event_list({task_id}, ...)") |
| 2274 |
query_params = { |
| 2275 |
"limit": limit, |
| 2276 |
"offset": offset, |
| 2277 |
"filter_is_error": ( |
| 2278 |
1 |
| 2279 |
if filter_is_error |
| 2280 |
else 0 if isinstance(filter_is_error, bool) else filter_is_error |
| 2281 |
), |
| 2282 |
**(query_params or {}), |
| 2283 |
} |
| 2284 |
return IterableTransferResponse( |
| 2285 |
self.get( |
| 2286 |
f"/v0.10/endpoint_manager/task/{task_id}/event_list", |
| 2287 |
query_params=query_params, |
| 2288 |
) |
| 2289 |
) |
| 2290 |
|
| 2291 |
def endpoint_manager_task_pause_info( |
| 2292 |
self, |
| 2293 |
task_id: uuid.UUID | str, |
| 2294 |
*, |
| 2295 |
query_params: dict[str, t.Any] | None = None, |
| 2296 |
) -> response.GlobusHTTPResponse: |
| 2297 |
""" |
| 2298 |
Get details about why a task is paused as an admin. Requires activity |
| 2299 |
monitor effective role on the destination endpoint of the task. |
| 2300 |
|
| 2301 |
:param task_id: The ID of the task to inspect |
| 2302 |
:param query_params: Additional passthrough query parameters |
| 2303 |
|
| 2304 |
.. tab-set:: |
| 2305 |
|
| 2306 |
.. tab-item:: API Info |
| 2307 |
|
| 2308 |
``GET /endpoint_manager/task/<task_id>/pause_info`` |
| 2309 |
|
| 2310 |
.. extdoclink:: Get task pause info as admin |
| 2311 |
:ref: transfer/advanced_collection_management/#get_task_pause_info_as_admin |
| 2312 |
""" # noqa: E501 |
| 2313 |
log.debug(f"TransferClient.endpoint_manager_task_pause_info({task_id}, ...)") |
| 2314 |
return self.get( |
| 2315 |
f"/v0.10/endpoint_manager/task/{task_id}/pause_info", |
| 2316 |
query_params=query_params, |
| 2317 |
) |
| 2318 |
|
| 2319 |
@paging.has_paginator( |
| 2320 |
paging.NullableMarkerPaginator, items_key="DATA", marker_key="next_marker" |
| 2321 |
) |
| 2322 |
def endpoint_manager_task_successful_transfers( |
| 2323 |
self, |
| 2324 |
task_id: uuid.UUID | str, |
| 2325 |
*, |
| 2326 |
marker: str | MissingType = MISSING, |
| 2327 |
query_params: dict[str, t.Any] | None = None, |
| 2328 |
) -> IterableTransferResponse: |
| 2329 |
r""" |
| 2330 |
Get the successful file transfers for a completed Task as an admin. |
| 2331 |
|
| 2332 |
:param task_id: The ID of the task to inspect |
| 2333 |
:param marker: A marker for pagination |
| 2334 |
:param query_params: Additional passthrough query parameters |
| 2335 |
|
| 2336 |
.. tab-set:: |
| 2337 |
|
| 2338 |
.. tab-item:: Paginated Usage |
| 2339 |
|
| 2340 |
.. paginatedusage:: endpoint_manager_task_successful_transfers |
| 2341 |
|
| 2342 |
.. tab-item:: API Info |
| 2343 |
|
| 2344 |
``GET /endpoint_manager/task/<task_id>/successful_transfers`` |
| 2345 |
|
| 2346 |
.. extdoclink:: Get task successful transfers as admin |
| 2347 |
:ref: transfer/advanced_collection_management/\ |
| 2348 |
#get_task_successful_transfers_as_admin |
| 2349 |
""" |
| 2350 |
log.debug( |
| 2351 |
"TransferClient.endpoint_manager_task_successful_transfers(%s, ...)", |
| 2352 |
task_id, |
| 2353 |
) |
| 2354 |
query_params = { |
| 2355 |
"marker": marker, |
| 2356 |
**(query_params or {}), |
| 2357 |
} |
| 2358 |
return IterableTransferResponse( |
| 2359 |
self.get( |
| 2360 |
f"/v0.10/endpoint_manager/task/{task_id}/successful_transfers", |
| 2361 |
query_params=query_params, |
| 2362 |
) |
| 2363 |
) |
| 2364 |
|
| 2365 |
@paging.has_paginator( |
| 2366 |
paging.NullableMarkerPaginator, items_key="DATA", marker_key="next_marker" |
| 2367 |
) |
| 2368 |
def endpoint_manager_task_skipped_errors( |
| 2369 |
self, |
| 2370 |
task_id: uuid.UUID | str, |
| 2371 |
*, |
| 2372 |
marker: str | MissingType = MISSING, |
| 2373 |
query_params: dict[str, t.Any] | None = None, |
| 2374 |
) -> IterableTransferResponse: |
| 2375 |
r""" |
| 2376 |
Get skipped errors for a completed Task as an admin. |
| 2377 |
|
| 2378 |
:param task_id: The ID of the task to inspect |
| 2379 |
:param marker: A marker for pagination |
| 2380 |
:param query_params: Additional passthrough query parameters |
| 2381 |
|
| 2382 |
.. tab-set:: |
| 2383 |
|
| 2384 |
.. tab-item:: Paginated Usage |
| 2385 |
|
| 2386 |
.. paginatedusage:: endpoint_manager_task_skipped_errors |
| 2387 |
|
| 2388 |
.. tab-item:: API Info |
| 2389 |
|
| 2390 |
``GET /endpoint_manager/task/<task_id>/skipped_errors`` |
| 2391 |
|
| 2392 |
.. extdoclink:: Get task skipped errors as admin |
| 2393 |
:ref: transfer/advanced_collection_management/\ |
| 2394 |
#get_task_skipped_errors_as_admin |
| 2395 |
""" |
| 2396 |
log.debug( |
| 2397 |
f"TransferClient.endpoint_manager_task_skipped_errors({task_id}, ...)" |
| 2398 |
) |
| 2399 |
query_params = { |
| 2400 |
"marker": marker, |
| 2401 |
**(query_params or {}), |
| 2402 |
} |
| 2403 |
return IterableTransferResponse( |
| 2404 |
self.get( |
| 2405 |
f"/v0.10/endpoint_manager/task/{task_id}/skipped_errors", |
| 2406 |
query_params=query_params, |
| 2407 |
) |
| 2408 |
) |
| 2409 |
|
| 2410 |
def endpoint_manager_cancel_tasks( |
| 2411 |
self, |
| 2412 |
task_ids: t.Iterable[uuid.UUID | str], |
| 2413 |
message: str, |
| 2414 |
*, |
| 2415 |
query_params: dict[str, t.Any] | None = None, |
| 2416 |
) -> response.GlobusHTTPResponse: |
| 2417 |
""" |
| 2418 |
Cancel a list of tasks as an admin. Requires activity manager effective |
| 2419 |
role on the task(s) source or destination endpoint(s). |
| 2420 |
|
| 2421 |
:param task_ids: List of task ids to cancel |
| 2422 |
:param message: Message given to all users whose tasks have been canceled |
| 2423 |
:param query_params: Additional passthrough query parameters |
| 2424 |
|
| 2425 |
.. tab-set:: |
| 2426 |
|
| 2427 |
.. tab-item:: API Info |
| 2428 |
|
| 2429 |
``POST /endpoint_manager/admin_cancel`` |
| 2430 |
|
| 2431 |
.. extdoclink:: Cancel tasks as admin |
| 2432 |
:ref: transfer/advanced_collection_management/#admin_cancel |
| 2433 |
""" |
| 2434 |
str_task_ids = [str(i) for i in task_ids] |
| 2435 |
log.debug( |
| 2436 |
f"TransferClient.endpoint_manager_cancel_tasks({str_task_ids}, {message})" |
| 2437 |
) |
| 2438 |
data = {"message": message, "task_id_list": str_task_ids} |
| 2439 |
return self.post( |
| 2440 |
"/v0.10/endpoint_manager/admin_cancel", data=data, query_params=query_params |
| 2441 |
) |
| 2442 |
|
| 2443 |
def endpoint_manager_cancel_status( |
| 2444 |
self, |
| 2445 |
admin_cancel_id: uuid.UUID | str, |
| 2446 |
*, |
| 2447 |
query_params: dict[str, t.Any] | None = None, |
| 2448 |
) -> response.GlobusHTTPResponse: |
| 2449 |
""" |
| 2450 |
Get the status of an an admin cancel (result of |
| 2451 |
endpoint_manager_cancel_tasks). |
| 2452 |
|
| 2453 |
:param admin_cancel_id: The ID of the the cancel job to inspect |
| 2454 |
:param query_params: Additional passthrough query parameters |
| 2455 |
|
| 2456 |
.. tab-set:: |
| 2457 |
|
| 2458 |
.. tab-item:: API Info |
| 2459 |
|
| 2460 |
``GET /endpoint_manager/admin_cancel/<admin_cancel_id>`` |
| 2461 |
|
| 2462 |
.. extdoclink:: Get cancel status by ID |
| 2463 |
:ref: transfer/advanced_collection_management/#get_cancel_status_by_id |
| 2464 |
""" # noqa: E501 |
| 2465 |
log.debug(f"TransferClient.endpoint_manager_cancel_status({admin_cancel_id})") |
| 2466 |
return self.get( |
| 2467 |
f"/v0.10/endpoint_manager/admin_cancel/{admin_cancel_id}", |
| 2468 |
query_params=query_params, |
| 2469 |
) |
| 2470 |
|
| 2471 |
def endpoint_manager_pause_tasks( |
| 2472 |
self, |
| 2473 |
task_ids: t.Iterable[uuid.UUID | str], |
| 2474 |
message: str, |
| 2475 |
*, |
| 2476 |
query_params: dict[str, t.Any] | None = None, |
| 2477 |
) -> response.GlobusHTTPResponse: |
| 2478 |
""" |
| 2479 |
Pause a list of tasks as an admin. Requires activity manager effective |
| 2480 |
role on the task(s) source or destination endpoint(s). |
| 2481 |
|
| 2482 |
:param task_ids: List of task ids to pause |
| 2483 |
:param message: Message given to all users whose tasks have been paused |
| 2484 |
:param query_params: Additional passthrough query parameters |
| 2485 |
|
| 2486 |
.. tab-set:: |
| 2487 |
|
| 2488 |
.. tab-item:: API Info |
| 2489 |
|
| 2490 |
``POST /endpoint_manager/admin_pause`` |
| 2491 |
|
| 2492 |
.. extdoclink:: Pause tasks as admin |
| 2493 |
:ref: transfer/advanced_collection_management/#pause_tasks_as_admin |
| 2494 |
""" |
| 2495 |
str_task_ids = [str(i) for i in task_ids] |
| 2496 |
log.debug( |
| 2497 |
f"TransferClient.endpoint_manager_pause_tasks({str_task_ids}, {message})" |
| 2498 |
) |
| 2499 |
data = {"message": message, "task_id_list": str_task_ids} |
| 2500 |
return self.post( |
| 2501 |
"/v0.10/endpoint_manager/admin_pause", data=data, query_params=query_params |
| 2502 |
) |
| 2503 |
|
| 2504 |
def endpoint_manager_resume_tasks( |
| 2505 |
self, |
| 2506 |
task_ids: t.Iterable[uuid.UUID | str], |
| 2507 |
*, |
| 2508 |
query_params: dict[str, t.Any] | None = None, |
| 2509 |
) -> response.GlobusHTTPResponse: |
| 2510 |
""" |
| 2511 |
Resume a list of tasks as an admin. Requires activity manager effective |
| 2512 |
role on the task(s) source or destination endpoint(s). |
| 2513 |
|
| 2514 |
:param task_ids: List of task ids to resume |
| 2515 |
:param query_params: Additional passthrough query parameters |
| 2516 |
|
| 2517 |
.. tab-set:: |
| 2518 |
|
| 2519 |
.. tab-item:: API Info |
| 2520 |
|
| 2521 |
``POST /endpoint_manager/admin_resume`` |
| 2522 |
|
| 2523 |
.. extdoclink:: Resume tasks as admin |
| 2524 |
:ref: transfer/advanced_collection_management/#resume_tasks_as_admin |
| 2525 |
""" |
| 2526 |
str_task_ids = [str(i) for i in task_ids] |
| 2527 |
log.debug(f"TransferClient.endpoint_manager_resume_tasks({str_task_ids})") |
| 2528 |
data = {"task_id_list": str_task_ids} |
| 2529 |
return self.post( |
| 2530 |
"/v0.10/endpoint_manager/admin_resume", data=data, query_params=query_params |
| 2531 |
) |
| 2532 |
|
| 2533 |
# |
| 2534 |
# endpoint manager pause rule methods |
| 2535 |
# |
| 2536 |
|
| 2537 |
def endpoint_manager_pause_rule_list( |
| 2538 |
self, |
| 2539 |
*, |
| 2540 |
filter_endpoint: uuid.UUID | str | MissingType = MISSING, |
| 2541 |
query_params: dict[str, t.Any] | None = None, |
| 2542 |
) -> IterableTransferResponse: |
| 2543 |
""" |
| 2544 |
Get a list of pause rules on endpoints that the current user has the |
| 2545 |
activity monitor effective role on. |
| 2546 |
|
| 2547 |
:param filter_endpoint: An endpoint ID. Limit results to rules on endpoints |
| 2548 |
hosted by this endpoint. Must be activity monitor on this endpoint, not just |
| 2549 |
the hosted endpoints. |
| 2550 |
:param query_params: Additional passthrough query parameters |
| 2551 |
|
| 2552 |
.. tab-set:: |
| 2553 |
|
| 2554 |
.. tab-item:: API Info |
| 2555 |
|
| 2556 |
``GET /endpoint_manager/pause_rule_list`` |
| 2557 |
|
| 2558 |
.. extdoclink:: Get pause rules |
| 2559 |
:ref: transfer/advanced_collection_management/#get_pause_rules |
| 2560 |
""" |
| 2561 |
log.debug("TransferClient.endpoint_manager_pause_rule_list(...)") |
| 2562 |
query_params = { |
| 2563 |
"filter_endpoint": filter_endpoint, |
| 2564 |
**(query_params or {}), |
| 2565 |
} |
| 2566 |
return IterableTransferResponse( |
| 2567 |
self.get( |
| 2568 |
"/v0.10/endpoint_manager/pause_rule_list", query_params=query_params |
| 2569 |
) |
| 2570 |
) |
| 2571 |
|
| 2572 |
def endpoint_manager_create_pause_rule( |
| 2573 |
self, data: dict[str, t.Any] | None |
| 2574 |
) -> response.GlobusHTTPResponse: |
| 2575 |
""" |
| 2576 |
Create a new pause rule. Requires the activity manager effective role |
| 2577 |
on the endpoint defined in the rule. |
| 2578 |
|
| 2579 |
:param data: A pause rule document describing the rule to create |
| 2580 |
|
| 2581 |
.. tab-set:: |
| 2582 |
|
| 2583 |
.. tab-item:: Example Usage |
| 2584 |
|
| 2585 |
.. code-block:: python |
| 2586 |
|
| 2587 |
tc = globus_sdk.TransferClient(...) |
| 2588 |
rule_data = { |
| 2589 |
"DATA_TYPE": "pause_rule", |
| 2590 |
"message": "Message to users explaining why tasks are paused", |
| 2591 |
"endpoint_id": "339abc22-aab3-4b45-bb56-8d40535bfd80", |
| 2592 |
"identity_id": None, # affect all users on endpoint |
| 2593 |
"start_time": None, # start now |
| 2594 |
} |
| 2595 |
create_result = tc.endpoint_manager_create_pause_rule(ep_data) |
| 2596 |
rule_id = create_result["id"] |
| 2597 |
|
| 2598 |
.. tab-item:: API Info |
| 2599 |
|
| 2600 |
``POST /endpoint_manager/pause_rule`` |
| 2601 |
|
| 2602 |
.. extdoclink:: Create pause rule |
| 2603 |
:ref: transfer/advanced_collection_management/#create_pause_rule |
| 2604 |
""" |
| 2605 |
log.debug("TransferClient.endpoint_manager_create_pause_rule(...)") |
| 2606 |
return self.post("/v0.10/endpoint_manager/pause_rule", data=data) |
| 2607 |
|
| 2608 |
def endpoint_manager_get_pause_rule( |
| 2609 |
self, |
| 2610 |
pause_rule_id: uuid.UUID | str, |
| 2611 |
*, |
| 2612 |
query_params: dict[str, t.Any] | None = None, |
| 2613 |
) -> response.GlobusHTTPResponse: |
| 2614 |
""" |
| 2615 |
Get an existing pause rule by ID. Requires the activity manager |
| 2616 |
effective role on the endpoint defined in the rule. |
| 2617 |
|
| 2618 |
:param pause_rule_id: ID of pause rule to get |
| 2619 |
:param query_params: Additional passthrough query parameters |
| 2620 |
|
| 2621 |
.. tab-set:: |
| 2622 |
|
| 2623 |
.. tab-item:: API Info |
| 2624 |
|
| 2625 |
``GET /endpoint_manager/pause_rule/<pause_rule_id>`` |
| 2626 |
|
| 2627 |
.. extdoclink:: Get pause rule |
| 2628 |
:ref: transfer/advanced_collection_management/#get_pause_rule |
| 2629 |
""" |
| 2630 |
log.debug(f"TransferClient.endpoint_manager_get_pause_rule({pause_rule_id})") |
| 2631 |
return self.get( |
| 2632 |
f"/v0.10/endpoint_manager/pause_rule/{pause_rule_id}", |
| 2633 |
query_params=query_params, |
| 2634 |
) |
| 2635 |
|
| 2636 |
def endpoint_manager_update_pause_rule( |
| 2637 |
self, |
| 2638 |
pause_rule_id: uuid.UUID | str, |
| 2639 |
data: dict[str, t.Any] | None, |
| 2640 |
) -> response.GlobusHTTPResponse: |
| 2641 |
""" |
| 2642 |
Update an existing pause rule by ID. Requires the activity manager |
| 2643 |
effective role on the endpoint defined in the rule. |
| 2644 |
Note that non update-able fields in data will be ignored. |
| 2645 |
|
| 2646 |
:param pause_rule_id: The ID of the pause rule to update |
| 2647 |
:param data: A partial pause rule document with fields to update |
| 2648 |
|
| 2649 |
.. tab-set:: |
| 2650 |
|
| 2651 |
.. tab-item:: Example Usage |
| 2652 |
|
| 2653 |
.. code-block:: python |
| 2654 |
|
| 2655 |
tc = globus_sdk.TransferClient(...) |
| 2656 |
rule_data = { |
| 2657 |
"message": "Update to pause, reads are now allowed.", |
| 2658 |
"pause_ls": False, |
| 2659 |
"pause_task_transfer_read": False, |
| 2660 |
} |
| 2661 |
update_result = tc.endpoint_manager_update_pause_rule(ep_data) |
| 2662 |
|
| 2663 |
.. tab-item:: API Info |
| 2664 |
|
| 2665 |
``PUT /endpoint_manager/pause_rule/<pause_rule_id>`` |
| 2666 |
|
| 2667 |
.. extdoclink:: Update pause rule |
| 2668 |
:ref: transfer/advanced_collection_management/#update_pause_rule |
| 2669 |
""" |
| 2670 |
log.debug(f"TransferClient.endpoint_manager_update_pause_rule({pause_rule_id})") |
| 2671 |
return self.put( |
| 2672 |
f"/v0.10/endpoint_manager/pause_rule/{pause_rule_id}", data=data |
| 2673 |
) |
| 2674 |
|
| 2675 |
def endpoint_manager_delete_pause_rule( |
| 2676 |
self, |
| 2677 |
pause_rule_id: uuid.UUID | str, |
| 2678 |
*, |
| 2679 |
query_params: dict[str, t.Any] | None = None, |
| 2680 |
) -> response.GlobusHTTPResponse: |
| 2681 |
""" |
| 2682 |
Delete an existing pause rule by ID. Requires the user to see the |
| 2683 |
"editable" field of the rule as True. Any tasks affected by this rule |
| 2684 |
will no longer be once it is deleted. |
| 2685 |
|
| 2686 |
:param pause_rule_id: The ID of the pause rule to delete |
| 2687 |
:param query_params: Additional passthrough query parameters |
| 2688 |
|
| 2689 |
.. tab-set:: |
| 2690 |
|
| 2691 |
.. tab-item:: API Info |
| 2692 |
|
| 2693 |
``DELETE /endpoint_manager/pause_rule/<pause_rule_id>`` |
| 2694 |
|
| 2695 |
.. extdoclink:: Delete pause rule |
| 2696 |
:ref: transfer/advanced_collection_management/#delete_pause_rule |
| 2697 |
""" |
| 2698 |
log.debug(f"TransferClient.endpoint_manager_delete_pause_rule({pause_rule_id})") |
| 2699 |
return self.delete( |
| 2700 |
f"/v0.10/endpoint_manager/pause_rule/{pause_rule_id}", |
| 2701 |
query_params=query_params, |
| 2702 |
) |
| 2703 |
|
| 2704 |
# Tunnel methods |
| 2705 |
|
| 2706 |
def create_tunnel( |
| 2707 |
self, |
| 2708 |
data: dict[str, t.Any] | CreateTunnelData, |
| 2709 |
) -> response.GlobusHTTPResponse: |
| 2710 |
""" |
| 2711 |
.. note:: |
| 2712 |
|
| 2713 |
Tunnels functionality is currently in Beta and may experience |
| 2714 |
changes that will break this interface |
| 2715 |
|
| 2716 |
:param data: Parameters for the tunnel creation |
| 2717 |
|
| 2718 |
.. tab-set:: |
| 2719 |
|
| 2720 |
.. tab-item:: Example Usage |
| 2721 |
|
| 2722 |
.. code-block:: python |
| 2723 |
|
| 2724 |
tc = globus_sdk.TransferClient(...) |
| 2725 |
result = tc.create_tunnel(data) |
| 2726 |
print(result["data"]["id"]) |
| 2727 |
|
| 2728 |
.. tab-item:: API Info |
| 2729 |
|
| 2730 |
``POST /v2/tunnels`` |
| 2731 |
""" |
| 2732 |
log.debug("TransferClient.create_tunnel(...)") |
| 2733 |
try: |
| 2734 |
data_element = data["data"] |
| 2735 |
except KeyError as e: |
| 2736 |
raise exc.GlobusSDKUsageError( |
| 2737 |
"create_tunnel() body was malformed (missing the 'data' key). " |
| 2738 |
"Use CreateTunnelData to easily create correct documents." |
| 2739 |
) from e |
| 2740 |
|
| 2741 |
try: |
| 2742 |
attributes = data_element["attributes"] |
| 2743 |
except KeyError: |
| 2744 |
data_element["attributes"] = {} |
| 2745 |
attributes = data_element["attributes"] |
| 2746 |
if attributes.get("submission_id", MISSING) is MISSING: |
| 2747 |
log.debug("create_tunnel auto-creating submission_id") |
| 2748 |
attributes["submission_id"] = str(uuid.uuid1()) |
| 2749 |
|
| 2750 |
r = self.post("/v2/tunnels", data=data) |
| 2751 |
return r |
| 2752 |
|
| 2753 |
def update_tunnel( |
| 2754 |
self, |
| 2755 |
tunnel_id: str | uuid.UUID, |
| 2756 |
update_doc: dict[str, t.Any], |
| 2757 |
) -> response.GlobusHTTPResponse: |
| 2758 |
r""" |
| 2759 |
.. note:: |
| 2760 |
|
| 2761 |
Tunnels functionality is currently in Beta and may experience |
| 2762 |
changes that will break this interface |
| 2763 |
|
| 2764 |
:param tunnel_id: The ID of the Tunnel. |
| 2765 |
:param update_doc: The document that will be sent to the patch API. |
| 2766 |
|
| 2767 |
.. tab-set:: |
| 2768 |
|
| 2769 |
.. tab-item:: Example Usage |
| 2770 |
|
| 2771 |
.. code-block:: python |
| 2772 |
|
| 2773 |
tc = globus_sdk.TransferClient(...) |
| 2774 |
"data" = { |
| 2775 |
"type": "Tunnel", |
| 2776 |
"attributes": { |
| 2777 |
"state": "STOPPING", |
| 2778 |
}, |
| 2779 |
} |
| 2780 |
result = tc.update_tunnel(tunnel_id, data) |
| 2781 |
print(result["data"]) |
| 2782 |
|
| 2783 |
.. tab-item:: API Info |
| 2784 |
|
| 2785 |
``PATCH /v2/tunnels/<tunnel_id>`` |
| 2786 |
""" |
| 2787 |
log.debug(f"TransferClient.update_tunnel({tunnel_id}, {update_doc})") |
| 2788 |
r = self.patch(f"/v2/tunnels/{tunnel_id}", data=update_doc) |
| 2789 |
return r |
| 2790 |
|
| 2791 |
def get_tunnel( |
| 2792 |
self, |
| 2793 |
tunnel_id: str | uuid.UUID, |
| 2794 |
*, |
| 2795 |
query_params: dict[str, t.Any] | None = None, |
| 2796 |
) -> response.GlobusHTTPResponse: |
| 2797 |
""" |
| 2798 |
.. note:: |
| 2799 |
|
| 2800 |
Tunnels functionality is currently in Beta and may experience |
| 2801 |
changes that will break this interface |
| 2802 |
|
| 2803 |
:param tunnel_id: The ID of the Tunnel which we are fetching details about. |
| 2804 |
:param query_params: Any additional parameters will be passed through |
| 2805 |
as query params. |
| 2806 |
|
| 2807 |
.. tab-set:: |
| 2808 |
|
| 2809 |
.. tab-item:: Example Usage |
| 2810 |
|
| 2811 |
.. code-block:: python |
| 2812 |
|
| 2813 |
tc = globus_sdk.TransferClient(...) |
| 2814 |
result = tc.show_tunnel(tunnel_id) |
| 2815 |
print(result["data"]) |
| 2816 |
|
| 2817 |
.. tab-item:: API Info |
| 2818 |
|
| 2819 |
``GET /v2/tunnels/<tunnel_id>`` |
| 2820 |
""" |
| 2821 |
log.debug("TransferClient.get_tunnel({tunnel_id}, {query_params})") |
| 2822 |
r = self.get(f"/v2/tunnels/{tunnel_id}", query_params=query_params) |
| 2823 |
return r |
| 2824 |
|
| 2825 |
def delete_tunnel( |
| 2826 |
self, |
| 2827 |
tunnel_id: str | uuid.UUID, |
| 2828 |
) -> response.GlobusHTTPResponse: |
| 2829 |
""" |
| 2830 |
.. note:: |
| 2831 |
|
| 2832 |
Tunnels functionality is currently in Beta and may experience |
| 2833 |
changes that will break this interface |
| 2834 |
|
| 2835 |
:param tunnel_id: The ID of the Tunnel to be deleted. |
| 2836 |
|
| 2837 |
This will clean up all data associated with a Tunnel. |
| 2838 |
Note that Tunnels must be stopped before they can be deleted. |
| 2839 |
|
| 2840 |
.. tab-set:: |
| 2841 |
|
| 2842 |
.. tab-item:: Example Usage |
| 2843 |
|
| 2844 |
.. code-block:: python |
| 2845 |
|
| 2846 |
tc = globus_sdk.TransferClient(...) |
| 2847 |
tc.delete_tunnel(tunnel_id) |
| 2848 |
|
| 2849 |
.. tab-item:: API Info |
| 2850 |
|
| 2851 |
``DELETE /v2/tunnels/<tunnel_id>`` |
| 2852 |
""" |
| 2853 |
log.debug(f"TransferClient.delete_tunnel({tunnel_id})") |
| 2854 |
r = self.delete(f"/v2/tunnels/{tunnel_id}") |
| 2855 |
return r |
| 2856 |
|
| 2857 |
def list_tunnels( |
| 2858 |
self, |
| 2859 |
*, |
| 2860 |
query_params: dict[str, t.Any] | None = None, |
| 2861 |
) -> IterableJSONAPIResponse: |
| 2862 |
""" |
| 2863 |
.. note:: |
| 2864 |
|
| 2865 |
Tunnels functionality is currently in Beta and may experience |
| 2866 |
changes that will break this interface |
| 2867 |
|
| 2868 |
:param query_params: Any additional parameters will be passed through |
| 2869 |
as query params. |
| 2870 |
|
| 2871 |
This will list all the Tunnels created by the authorized user. |
| 2872 |
|
| 2873 |
.. tab-set:: |
| 2874 |
|
| 2875 |
.. tab-item:: Example Usage |
| 2876 |
|
| 2877 |
.. code-block:: python |
| 2878 |
|
| 2879 |
tc = globus_sdk.TransferClient(...) |
| 2880 |
tc.list_tunnels(tunnel_id) |
| 2881 |
|
| 2882 |
.. tab-item:: API Info |
| 2883 |
|
| 2884 |
``GET /v2/tunnels/`` |
| 2885 |
""" |
| 2886 |
log.debug(f"TransferClient.list_tunnels({query_params})") |
| 2887 |
r = self.get("/v2/tunnels", query_params=query_params) |
| 2888 |
return IterableJSONAPIResponse(r) |
| 2889 |
|
| 2890 |
def get_stream_access_point( |
| 2891 |
self, |
| 2892 |
stream_ap_id: str | uuid.UUID, |
| 2893 |
*, |
| 2894 |
query_params: dict[str, t.Any] | None = None, |
| 2895 |
) -> response.GlobusHTTPResponse: |
| 2896 |
""" |
| 2897 |
.. note:: |
| 2898 |
|
| 2899 |
Tunnels functionality is currently in Beta and may experience |
| 2900 |
changes that will break this interface |
| 2901 |
|
| 2902 |
:param stream_ap_id: The ID of the steaming access point to lookup. |
| 2903 |
:param query_params: Any additional parameters will be passed through |
| 2904 |
as query params. |
| 2905 |
|
| 2906 |
Get a stream access point by id. |
| 2907 |
|
| 2908 |
.. tab-set:: |
| 2909 |
|
| 2910 |
.. tab-item:: Example Usage |
| 2911 |
|
| 2912 |
.. code-block:: python |
| 2913 |
|
| 2914 |
tc = globus_sdk.TransferClient(...) |
| 2915 |
tc.get_stream_ap(stream_ap_id) |
| 2916 |
|
| 2917 |
.. tab-item:: API Info |
| 2918 |
|
| 2919 |
``GET /v2/stream_access_points/<stream_ap_id>`` |
| 2920 |
""" |
| 2921 |
log.debug( |
| 2922 |
f"TransferClient.get_stream_access_point({stream_ap_id}, {query_params})" |
| 2923 |
) |
| 2924 |
r = self.get( |
| 2925 |
f"/v2/stream_access_points/{stream_ap_id}", query_params=query_params |
| 2926 |
) |
| 2927 |
return r |
| 2928 |
|
| 2929 |
def get_tunnel_events( |
| 2930 |
self, |
| 2931 |
tunnel_id: str | uuid.UUID, |
| 2932 |
*, |
| 2933 |
query_params: dict[str, t.Any] | None = None, |
| 2934 |
) -> response.GlobusHTTPResponse: |
| 2935 |
""" |
| 2936 |
.. note:: |
| 2937 |
|
| 2938 |
Tunnels functionality is currently in Beta and may experience |
| 2939 |
changes that will break this interface |
| 2940 |
|
| 2941 |
:param tunnel_id: The ID of the Tunnel which we are fetching events about. |
| 2942 |
:param query_params: Any additional parameters will be passed through |
| 2943 |
as query params. |
| 2944 |
|
| 2945 |
List all events for a specific tunnel. |
| 2946 |
|
| 2947 |
.. tab-set:: |
| 2948 |
|
| 2949 |
.. tab-item:: Example Usage |
| 2950 |
|
| 2951 |
.. code-block:: python |
| 2952 |
|
| 2953 |
tc = globus_sdk.TransferClient(...) |
| 2954 |
result = tc.get_tunnel_events(tunnel_id) |
| 2955 |
print(result["data"]) |
| 2956 |
|
| 2957 |
.. tab-item:: API Info |
| 2958 |
|
| 2959 |
``GET /v2/tunnels/<tunnel_id>/events`` |
| 2960 |
""" |
| 2961 |
log.debug(f"TransferClient.get_tunnel_events({tunnel_id}, {query_params})") |
| 2962 |
r = self.get(f"/v2/tunnels/{tunnel_id}/events", query_params=query_params) |
| 2963 |
return r |