Skip to content

Commit

Permalink
Merge branch 'm-kovalsky/capacityassignmentstatus'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Dec 4, 2024
2 parents 91a0ec3 + 62f3151 commit 05f2849
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/sempy_labs/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
list_capacities_delegated_tenant_settings,
list_access_entities,
list_activity_events,
get_capacity_assignment_status,
)
from sempy_labs.admin._domains import (
list_domains,
Expand Down Expand Up @@ -64,4 +65,5 @@
"list_modified_workspaces",
"list_git_connections",
"list_reports",
"get_capacity_assignment_status",
]
76 changes: 69 additions & 7 deletions src/sempy_labs/admin/_basic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import numpy as np
import pandas as pd
from dateutil.parser import parse as dtparser
import urllib.parse


def list_workspaces(
Expand Down Expand Up @@ -901,12 +900,18 @@ def _resolve_workspace_name_and_id(
workspace: str | UUID,
) -> Tuple[str, UUID]:

dfW = list_workspaces(workspace=workspace)
try:
workspace_name = dfW["Name"].iloc[0]
workspace_id = dfW["Id"].iloc[0]
except Exception:
raise ValueError(f"{icons.red_dot} The '{workspace}' workspace was not found.")
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace_name = fabric.resolve_workspace_name(workspace_id)
else:
dfW = list_workspaces(workspace=workspace)
if not dfW.empty:
workspace_name = dfW["Name"].iloc[0]
workspace_id = dfW["Id"].iloc[0]
else:
raise ValueError(
f"{icons.red_dot} The '{workspace}' workspace was not found."
)

return workspace_name, workspace_id

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

return df


def get_capacity_assignment_status(workspace: Optional[str | UUID] = None):
"""
Gets the status of the assignment-to-capacity operation for the specified workspace.
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>`_.
Parameters
----------
workspace : str | UUID, default=None
The Fabric workspace name or id.
Defaults to None which resolves to the workspace of the attached lakehouse
or if no lakehouse attached, resolves to the workspace of the notebook.
Returns
-------
pandas.DataFrame
A pandas dataframe showing the status of the assignment-to-capacity operation for the specified workspace.
"""

(workspace_name, workspace_id) = _resolve_workspace_name_and_id(workspace)

df = pd.DataFrame(
columns=[
"Status",
"Activity Id",
"Start Time",
"End Time",
"Capacity Id",
"Capacity Name",
]
)

client = fabric.FabricRestClient()
response = client.get(f"/v1.0/myorg/groups/{workspace_id}/CapacityAssignmentStatus")

if response.status_code != 200:
raise FabricHTTPException(response)

v = response.json()
capacity_id = v.get("capacityId")

(capacity_name, capacity_id) = _resolve_capacity_name_and_id(capacity=capacity_id)

new_data = {
"Status": v.get("status"),
"Activity Id": v.get("activityId"),
"Start Time": v.get("startTime"),
"End Time": v.get("endTime"),
"Capacity Id": capacity_id,
"Capacity Name": capacity_name,
}

df = pd.concat([df, pd.DataFrame([new_data])], ignore_index=True)

return df
2 changes: 1 addition & 1 deletion src/sempy_labs/admin/_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def scan_workspaces(
Returns
-------
dictionary
dict
A json object with the scan result.
"""
scan_result = {
Expand Down

0 comments on commit 05f2849

Please sign in to comment.