Skip to content

Commit 05f2849

Browse files
committed
Merge branch 'm-kovalsky/capacityassignmentstatus'
2 parents 91a0ec3 + 62f3151 commit 05f2849

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

src/sempy_labs/admin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
list_capacities_delegated_tenant_settings,
1212
list_access_entities,
1313
list_activity_events,
14+
get_capacity_assignment_status,
1415
)
1516
from sempy_labs.admin._domains import (
1617
list_domains,
@@ -64,4 +65,5 @@
6465
"list_modified_workspaces",
6566
"list_git_connections",
6667
"list_reports",
68+
"get_capacity_assignment_status",
6769
]

src/sempy_labs/admin/_basic_functions.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numpy as np
1212
import pandas as pd
1313
from dateutil.parser import parse as dtparser
14-
import urllib.parse
1514

1615

1716
def list_workspaces(
@@ -901,12 +900,18 @@ def _resolve_workspace_name_and_id(
901900
workspace: str | UUID,
902901
) -> Tuple[str, UUID]:
903902

904-
dfW = list_workspaces(workspace=workspace)
905-
try:
906-
workspace_name = dfW["Name"].iloc[0]
907-
workspace_id = dfW["Id"].iloc[0]
908-
except Exception:
909-
raise ValueError(f"{icons.red_dot} The '{workspace}' workspace was not found.")
903+
if workspace is None:
904+
workspace_id = fabric.get_workspace_id()
905+
workspace_name = fabric.resolve_workspace_name(workspace_id)
906+
else:
907+
dfW = list_workspaces(workspace=workspace)
908+
if not dfW.empty:
909+
workspace_name = dfW["Name"].iloc[0]
910+
workspace_id = dfW["Id"].iloc[0]
911+
else:
912+
raise ValueError(
913+
f"{icons.red_dot} The '{workspace}' workspace was not found."
914+
)
910915

911916
return workspace_name, workspace_id
912917

@@ -988,3 +993,60 @@ def list_reports(
988993
df["Modified Date"] = pd.to_datetime(df["Modified Date"], errors="coerce")
989994

990995
return df
996+
997+
998+
def get_capacity_assignment_status(workspace: Optional[str | UUID] = None):
999+
"""
1000+
Gets the status of the assignment-to-capacity operation for the specified workspace.
1001+
1002+
This is a wrapper function for the following API: `Capacities - Groups CapacityAssignmentStatus <https://learn.microsoft.com/rest/api/power-bi/capacities/groups-capacity-assignment-status>`_.
1003+
1004+
Parameters
1005+
----------
1006+
workspace : str | UUID, default=None
1007+
The Fabric workspace name or id.
1008+
Defaults to None which resolves to the workspace of the attached lakehouse
1009+
or if no lakehouse attached, resolves to the workspace of the notebook.
1010+
1011+
Returns
1012+
-------
1013+
pandas.DataFrame
1014+
A pandas dataframe showing the status of the assignment-to-capacity operation for the specified workspace.
1015+
"""
1016+
1017+
(workspace_name, workspace_id) = _resolve_workspace_name_and_id(workspace)
1018+
1019+
df = pd.DataFrame(
1020+
columns=[
1021+
"Status",
1022+
"Activity Id",
1023+
"Start Time",
1024+
"End Time",
1025+
"Capacity Id",
1026+
"Capacity Name",
1027+
]
1028+
)
1029+
1030+
client = fabric.FabricRestClient()
1031+
response = client.get(f"/v1.0/myorg/groups/{workspace_id}/CapacityAssignmentStatus")
1032+
1033+
if response.status_code != 200:
1034+
raise FabricHTTPException(response)
1035+
1036+
v = response.json()
1037+
capacity_id = v.get("capacityId")
1038+
1039+
(capacity_name, capacity_id) = _resolve_capacity_name_and_id(capacity=capacity_id)
1040+
1041+
new_data = {
1042+
"Status": v.get("status"),
1043+
"Activity Id": v.get("activityId"),
1044+
"Start Time": v.get("startTime"),
1045+
"End Time": v.get("endTime"),
1046+
"Capacity Id": capacity_id,
1047+
"Capacity Name": capacity_name,
1048+
}
1049+
1050+
df = pd.concat([df, pd.DataFrame([new_data])], ignore_index=True)
1051+
1052+
return df

src/sempy_labs/admin/_scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def scan_workspaces(
4040
4141
Returns
4242
-------
43-
dictionary
43+
dict
4444
A json object with the scan result.
4545
"""
4646
scan_result = {

0 commit comments

Comments
 (0)