|
13 | 13 | from globus_sdk.scopes import GCSCollectionScopes, Scope, TransferScopes |
14 | 14 | from globus_sdk.transport import RetryConfig |
15 | 15 |
|
16 | | -from .data import DeleteData, TransferData |
| 16 | +from .data import CreateTunnelData, DeleteData, TransferData |
17 | 17 | from .errors import TransferAPIError |
18 | 18 | from .response import IterableTransferResponse |
19 | 19 | from .transport import TRANSFER_DEFAULT_RETRY_CHECKS |
@@ -2699,3 +2699,195 @@ def endpoint_manager_delete_pause_rule( |
2699 | 2699 | f"/v0.10/endpoint_manager/pause_rule/{pause_rule_id}", |
2700 | 2700 | query_params=query_params, |
2701 | 2701 | ) |
| 2702 | + |
| 2703 | + # Tunnel methods |
| 2704 | + |
| 2705 | + def create_tunnel( |
| 2706 | + self, |
| 2707 | + data: dict[str, t.Any] | CreateTunnelData, |
| 2708 | + ) -> response.GlobusHTTPResponse: |
| 2709 | + """ |
| 2710 | + :param data: Parameters for the tunnel creation |
| 2711 | +
|
| 2712 | + .. tab-set:: |
| 2713 | +
|
| 2714 | + .. tab-item:: Example Usage |
| 2715 | +
|
| 2716 | + .. code-block:: python |
| 2717 | +
|
| 2718 | + tc = globus_sdk.TunnelClient(...) |
| 2719 | + result = tc.create_tunnel(data) |
| 2720 | + print(result["data"]["id"]) |
| 2721 | +
|
| 2722 | + .. tab-item:: API Info |
| 2723 | +
|
| 2724 | + ``POST /v2/tunnels`` |
| 2725 | + """ |
| 2726 | + log.debug("TransferClient.create_tunnel(...)") |
| 2727 | + try: |
| 2728 | + data_element = data["data"] |
| 2729 | + except KeyError: |
| 2730 | + raise exc.GlobusSDKUsageError( |
| 2731 | + "create_tunnel() body was malformed (missing the 'data' key). " |
| 2732 | + "Use CreateTunnelData to easily create correct documents." |
| 2733 | + ) |
| 2734 | + |
| 2735 | + try: |
| 2736 | + attributes = data_element["attributes"] |
| 2737 | + except KeyError: |
| 2738 | + data_element["attributes"] = {} |
| 2739 | + attributes = data_element["attributes"] |
| 2740 | + if attributes.get("submission_id", MISSING) is MISSING: |
| 2741 | + log.debug("create_tunnel auto-fetching submission_id") |
| 2742 | + attributes["submission_id"] = self.get_submission_id()["value"] |
| 2743 | + |
| 2744 | + r = self.post("/v2/tunnels", data=data) |
| 2745 | + return r |
| 2746 | + |
| 2747 | + def update_tunnel( |
| 2748 | + self, |
| 2749 | + tunnel_id: str, |
| 2750 | + update_doc: dict[str, t.Any], |
| 2751 | + ) -> response.GlobusHTTPResponse: |
| 2752 | + r""" |
| 2753 | + :param tunnel_id: The ID of the Tunnel. |
| 2754 | + :param update_doc: The document that will be sent to the patch API. |
| 2755 | +
|
| 2756 | + .. tab-set:: |
| 2757 | +
|
| 2758 | + .. tab-item:: Example Usage |
| 2759 | +
|
| 2760 | + .. code-block:: python |
| 2761 | +
|
| 2762 | + tc = globus_sdk.TunnelClient(...) |
| 2763 | + "data" = { |
| 2764 | + "type": "Tunnel", |
| 2765 | + "attributes": { |
| 2766 | + "state": "STOPPING", |
| 2767 | + }, |
| 2768 | + } |
| 2769 | + result = tc.update_tunnel(tunnel_id, data) |
| 2770 | + print(result["data"]) |
| 2771 | +
|
| 2772 | + .. tab-item:: API Info |
| 2773 | +
|
| 2774 | + ``PATCH /v2/tunnels/<tunnel_id>`` |
| 2775 | + """ |
| 2776 | + r = self.patch(f"/v2/tunnels/{tunnel_id}", data=update_doc) |
| 2777 | + return r |
| 2778 | + |
| 2779 | + def get_tunnel( |
| 2780 | + self, |
| 2781 | + tunnel_id: str, |
| 2782 | + *, |
| 2783 | + query_params: dict[str, t.Any] | None = None, |
| 2784 | + ) -> response.GlobusHTTPResponse: |
| 2785 | + """ |
| 2786 | + :param tunnel_id: The ID of the Tunnel which we are fetching details about. |
| 2787 | + :param query_params: Any additional parameters will be passed through |
| 2788 | + as query params. |
| 2789 | +
|
| 2790 | + .. tab-set:: |
| 2791 | +
|
| 2792 | + .. tab-item:: Example Usage |
| 2793 | +
|
| 2794 | + .. code-block:: python |
| 2795 | +
|
| 2796 | + tc = globus_sdk.TunnelClient(...) |
| 2797 | + result = tc.show_tunnel(tunnel_id) |
| 2798 | + print(result["data"]) |
| 2799 | +
|
| 2800 | + .. tab-item:: API Info |
| 2801 | +
|
| 2802 | + ``GET /v2/tunnels/<tunnel_id>`` |
| 2803 | + """ |
| 2804 | + log.debug("TransferClient.get_tunnel(...)") |
| 2805 | + r = self.get(f"/v2/tunnels/{tunnel_id}", query_params=query_params) |
| 2806 | + return r |
| 2807 | + |
| 2808 | + def delete_tunnel( |
| 2809 | + self, |
| 2810 | + tunnel_id: str, |
| 2811 | + ) -> response.GlobusHTTPResponse: |
| 2812 | + """ |
| 2813 | + :param tunnel_id: The ID of the Tunnel to be deleted. |
| 2814 | +
|
| 2815 | + This will clean up all data associated with a Tunnel. |
| 2816 | + Note that Tunnels must be stopped before they can be deleted. |
| 2817 | +
|
| 2818 | + .. tab-set:: |
| 2819 | +
|
| 2820 | + .. tab-item:: Example Usage |
| 2821 | +
|
| 2822 | + .. code-block:: python |
| 2823 | +
|
| 2824 | + tc = globus_sdk.TunnelClient(...) |
| 2825 | + tc.delete_tunnel(tunnel_id) |
| 2826 | +
|
| 2827 | + .. tab-item:: API Info |
| 2828 | +
|
| 2829 | + ``DELETE /v2/tunnels/<tunnel_id>`` |
| 2830 | + """ |
| 2831 | + log.debug("TransferClient.delete_tunnel(...)") |
| 2832 | + r = self.delete(f"/v2/tunnels/{tunnel_id}") |
| 2833 | + return r |
| 2834 | + |
| 2835 | + def list_tunnels( |
| 2836 | + self, |
| 2837 | + *, |
| 2838 | + query_params: dict[str, t.Any] | None = None, |
| 2839 | + ) -> IterableTransferResponse: |
| 2840 | + """ |
| 2841 | + :param query_params: Any additional parameters will be passed through |
| 2842 | + as query params. |
| 2843 | +
|
| 2844 | + This will list all the Tunnels created by the authorized user. |
| 2845 | +
|
| 2846 | + .. tab-set:: |
| 2847 | +
|
| 2848 | + .. tab-item:: Example Usage |
| 2849 | +
|
| 2850 | + .. code-block:: python |
| 2851 | +
|
| 2852 | + tc = globus_sdk.TunnelClient(...) |
| 2853 | + tc.list_tunnels(tunnel_id) |
| 2854 | +
|
| 2855 | + .. tab-item:: API Info |
| 2856 | +
|
| 2857 | + ``GET /v2/tunnels/`` |
| 2858 | + """ |
| 2859 | + log.debug("TransferClient.list_tunnels(...)") |
| 2860 | + r = self.get("/v2/tunnels", query_params=query_params) |
| 2861 | + return IterableTransferResponse(r) |
| 2862 | + |
| 2863 | + def get_stream_access_point( |
| 2864 | + self, |
| 2865 | + stream_ap_id: str, |
| 2866 | + *, |
| 2867 | + query_params: dict[str, t.Any] | None = None, |
| 2868 | + ) -> response.GlobusHTTPResponse: |
| 2869 | + """ |
| 2870 | + :param stream_ap_id: The ID of the steaming access point to lookup. |
| 2871 | + :param query_params: Any additional parameters will be passed through |
| 2872 | + as query params. |
| 2873 | +
|
| 2874 | + This will list all the Tunnels created by the authorized user. |
| 2875 | +
|
| 2876 | + .. tab-set:: |
| 2877 | +
|
| 2878 | + .. tab-item:: Example Usage |
| 2879 | +
|
| 2880 | + .. code-block:: python |
| 2881 | +
|
| 2882 | + tc = globus_sdk.TunnelClient(...) |
| 2883 | + tc.get_stream_ap(stream_ap_id) |
| 2884 | +
|
| 2885 | + .. tab-item:: API Info |
| 2886 | +
|
| 2887 | + ``GET /v2/stream_access_points/<stream_ap_id>`` |
| 2888 | + """ |
| 2889 | + log.debug("TransferClient.get_stream_ap(...)") |
| 2890 | + r = self.get( |
| 2891 | + f"/v2/stream_access_points/{stream_ap_id}", query_params=query_params |
| 2892 | + ) |
| 2893 | + return r |
0 commit comments