| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import logging |
| 4 |
import typing as t |
| 5 |
import uuid |
| 6 |
|
| 7 |
from globus_sdk._missing import MISSING, MissingType |
| 8 |
from globus_sdk._payload import GlobusPayload |
| 9 |
|
| 10 |
log = logging.getLogger(__name__) |
| 11 |
|
| 12 |
|
| 13 |
class TunnelCreateDocument(GlobusPayload): |
| 14 |
""" |
| 15 |
Convenience class for constructing a tunnel document to use as the |
| 16 |
``data`` parameter to |
| 17 |
:meth:`create_tunnel <globus_sdk.TransferClientV2.create_tunnel>`. |
| 18 |
""" |
| 19 |
|
| 20 |
def __init__( |
| 21 |
self, |
| 22 |
initiator_stream_access_point: uuid.UUID | str, |
| 23 |
listener_stream_access_point: uuid.UUID | str, |
| 24 |
*, |
| 25 |
label: str | MissingType = MISSING, |
| 26 |
listener_port: int | MissingType = MISSING, |
| 27 |
listener_ip_address: str | MissingType = MISSING, |
| 28 |
submission_id: uuid.UUID | str | MissingType = MISSING, |
| 29 |
lifetime_mins: int | MissingType = MISSING, |
| 30 |
restartable: bool | MissingType = MISSING, |
| 31 |
additional_fields: dict[str, t.Any] | None = None, |
| 32 |
) -> None: |
| 33 |
super().__init__() |
| 34 |
log.debug("Creating a new TunnelCreateDocument object") |
| 35 |
|
| 36 |
# Auto-create submission_id if not given now so that the same |
| 37 |
# submission_id will be used across retries |
| 38 |
if submission_id is MISSING: |
| 39 |
submission_id = uuid.uuid1() |
| 40 |
|
| 41 |
relationships = { |
| 42 |
"listener": { |
| 43 |
"data": { |
| 44 |
"type": "StreamAccessPoint", |
| 45 |
"id": listener_stream_access_point, |
| 46 |
} |
| 47 |
}, |
| 48 |
"initiator": { |
| 49 |
"data": { |
| 50 |
"type": "StreamAccessPoint", |
| 51 |
"id": initiator_stream_access_point, |
| 52 |
} |
| 53 |
}, |
| 54 |
} |
| 55 |
attributes = { |
| 56 |
"label": label, |
| 57 |
"listener_port": listener_port, |
| 58 |
"listener_ip_address": listener_ip_address, |
| 59 |
"submission_id": submission_id, |
| 60 |
"restartable": restartable, |
| 61 |
"lifetime_mins": lifetime_mins, |
| 62 |
} |
| 63 |
if additional_fields is not None: |
| 64 |
attributes.update(additional_fields) |
| 65 |
|
| 66 |
self["data"] = { |
| 67 |
"type": "Tunnel", |
| 68 |
"relationships": relationships, |
| 69 |
"attributes": attributes, |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
class TunnelUpdateDocument(GlobusPayload): |
| 74 |
""" |
| 75 |
Convenience class for constructing a tunnel document to use as the |
| 76 |
``data`` parameter to |
| 77 |
:meth:`update_tunnel <globus_sdk.TransferClientV2.update_tunnel>`. |
| 78 |
""" |
| 79 |
|
| 80 |
def __init__( |
| 81 |
self, |
| 82 |
*, |
| 83 |
label: str | MissingType = MISSING, |
| 84 |
listener_port: int | MissingType = MISSING, |
| 85 |
listener_ip_address: str | MissingType = MISSING, |
| 86 |
state: t.Literal["STOPPING"] | MissingType = MISSING, |
| 87 |
additional_fields: dict[str, t.Any] | None = None, |
| 88 |
) -> None: |
| 89 |
super().__init__() |
| 90 |
log.debug("Creating a new TunnelUpdateDocument object") |
| 91 |
|
| 92 |
attributes = { |
| 93 |
"label": label, |
| 94 |
"listener_port": listener_port, |
| 95 |
"listener_ip_address": listener_ip_address, |
| 96 |
"state": state, |
| 97 |
} |
| 98 |
if additional_fields is not None: |
| 99 |
attributes.update(additional_fields) |
| 100 |
|
| 101 |
self["data"] = { |
| 102 |
"type": "Tunnel", |
| 103 |
"attributes": attributes, |
| 104 |
} |