|
| 1 | +from sempy_labs._helper_functions import ( |
| 2 | + resolve_item_id, |
| 3 | + _base_api, |
| 4 | + resolve_workspace_name_and_id, |
| 5 | +) |
| 6 | +from typing import Optional |
| 7 | +from uuid import UUID |
| 8 | +from sempy._utils._log import log |
| 9 | +import sempy_labs._icons as icons |
| 10 | + |
| 11 | + |
| 12 | +@log |
| 13 | +def start_mirroring(sql_database: str | UUID, workspace: Optional[str | UUID] = None): |
| 14 | + """ |
| 15 | + Starts data mirroring for the specified SQL Database. |
| 16 | +
|
| 17 | + This is a wrapper function for the following API: `Mirroring - Start Mirroring <https://learn.microsoft.com/rest/api/fabric/sqldatabase/mirroring/start-mirroring>`_. |
| 18 | +
|
| 19 | + Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples). |
| 20 | +
|
| 21 | + Parameters |
| 22 | + ---------- |
| 23 | + sql_database : str | uuid.UUID |
| 24 | + Name or ID of the SQL Database. |
| 25 | + workspace : str | uuid.UUID, default=None |
| 26 | + The Fabric workspace name or ID. |
| 27 | + Defaults to None which resolves to the workspace of the attached lakehouse |
| 28 | + or if no lakehouse attached, resolves to the workspace of the notebook. |
| 29 | + """ |
| 30 | + |
| 31 | + (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace) |
| 32 | + item_id = resolve_item_id( |
| 33 | + item=sql_database, type="SQLDatabase", workspace=workspace_id |
| 34 | + ) |
| 35 | + |
| 36 | + _base_api( |
| 37 | + request=f"/v1/workspaces/{workspace_id}/sqlDatabases/{item_id}/startMirroring", |
| 38 | + method="post", |
| 39 | + client="fabric_sp", |
| 40 | + ) |
| 41 | + |
| 42 | + print( |
| 43 | + f"{icons.green_dot} The SQL Database '{sql_database}' in the '{workspace_name}' workspace is now being mirrored." |
| 44 | + ) |
| 45 | + |
| 46 | + |
| 47 | +@log |
| 48 | +def stop_mirroring(sql_database: str | UUID, workspace: Optional[str | UUID] = None): |
| 49 | + """ |
| 50 | + Stops data mirroring for the specified SQL Database. |
| 51 | +
|
| 52 | + This is a wrapper function for the following API: `Mirroring - Stop Mirroring <https://learn.microsoft.com/rest/api/fabric/sqldatabase/mirroring/stop-mirroring>`_. |
| 53 | +
|
| 54 | + Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples). |
| 55 | +
|
| 56 | + Parameters |
| 57 | + ---------- |
| 58 | + sql_database : str | uuid.UUID |
| 59 | + Name or ID of the SQL Database. |
| 60 | + workspace : str | uuid.UUID, default=None |
| 61 | + The Fabric workspace name or ID. |
| 62 | + Defaults to None which resolves to the workspace of the attached lakehouse |
| 63 | + or if no lakehouse attached, resolves to the workspace of the notebook. |
| 64 | + """ |
| 65 | + |
| 66 | + (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace) |
| 67 | + item_id = resolve_item_id( |
| 68 | + item=sql_database, type="SQLDatabase", workspace=workspace_id |
| 69 | + ) |
| 70 | + |
| 71 | + _base_api( |
| 72 | + request=f"/v1/workspaces/{workspace_id}/sqlDatabases/{item_id}/stopMirroring", |
| 73 | + method="post", |
| 74 | + client="fabric_sp", |
| 75 | + ) |
| 76 | + |
| 77 | + print( |
| 78 | + f"{icons.green_dot} The SQL Database '{sql_database}' in the '{workspace_name}' workspace is no longer being mirrored." |
| 79 | + ) |
0 commit comments