|
| 1 | +import uuid |
| 2 | + |
| 3 | +import click |
| 4 | +from globus_sdk.services.transfer.data.tunnel_data import CreateTunnelData |
| 5 | + |
| 6 | +from globus_cli.commands.streams import streams_display_flatten_response |
| 7 | +from globus_cli.constants import ExplicitNullType |
| 8 | +from globus_cli.login_manager import LoginManager |
| 9 | +from globus_cli.parsing import command |
| 10 | +from globus_cli.termio import Field, display |
| 11 | + |
| 12 | +STANDARD_FIELDS = [ |
| 13 | + Field("ID", "id"), |
| 14 | + Field("Label", "attributes_label"), |
| 15 | + Field("State", "attributes_state"), |
| 16 | + Field("Status", "attributes_status"), |
| 17 | +] |
| 18 | + |
| 19 | + |
| 20 | +@command("create", short_help="Create a Globus Tunnel.") |
| 21 | +@click.argument( |
| 22 | + "initiator_stream_ap_id", metavar="INITIATOR_STREAM_AP_ID", type=click.UUID |
| 23 | +) |
| 24 | +@click.argument( |
| 25 | + "listener_stream_ap_id", metavar="LISTENER_STREAM_AP_ID", type=click.UUID |
| 26 | +) |
| 27 | +@click.option( |
| 28 | + "--label", |
| 29 | + type=str, |
| 30 | + default=None, |
| 31 | + help="A friendly label to associate with the Tunnel.", |
| 32 | +) |
| 33 | +@click.option( |
| 34 | + "--lifetime-minutes", |
| 35 | + type=int, |
| 36 | + help="The amount of time in minutes that the tunnel will exist.", |
| 37 | +) |
| 38 | +@click.option( |
| 39 | + "--restartable", |
| 40 | + type=bool, |
| 41 | + default=False, |
| 42 | + help=( |
| 43 | + "A boolean to indicate if the tunnel should be restart in the " |
| 44 | + "event of an error." |
| 45 | + ), |
| 46 | +) |
| 47 | +@LoginManager.requires_login("auth", "transfer") |
| 48 | +def create_tunnel_command( |
| 49 | + login_manager: LoginManager, |
| 50 | + *, |
| 51 | + initiator_stream_ap_id: uuid.UUID, |
| 52 | + listener_stream_ap_id: uuid.UUID, |
| 53 | + label: str | None, |
| 54 | + lifetime_minutes: int | None, |
| 55 | + restartable: bool, |
| 56 | +) -> None: |
| 57 | + """ |
| 58 | + Create a Globus Tunnel. |
| 59 | + """ |
| 60 | + data = CreateTunnelData( |
| 61 | + initiator_stream_ap_id, |
| 62 | + listener_stream_ap_id, |
| 63 | + label=label, |
| 64 | + lifetime_mins=lifetime_minutes, |
| 65 | + restartable=restartable, |
| 66 | + ) |
| 67 | + tunnel_client = login_manager.get_transfer_client() |
| 68 | + res = tunnel_client.create_tunnel(data) |
| 69 | + display( |
| 70 | + res, |
| 71 | + text_mode=display.RECORD, |
| 72 | + fields=STANDARD_FIELDS, |
| 73 | + response_key=streams_display_flatten_response, |
| 74 | + ) |
0 commit comments