Skip to content

Commit ee6cb60

Browse files
committed
Merge branch 'm-kovalsky/operations_agent-package'
2 parents 45f1efd + 38a67e5 commit ee6cb60

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ._items import (
2+
list_event_schema_sets,
3+
delete_event_schema_set,
4+
)
5+
6+
__all__ = [
7+
"list_event_schema_sets",
8+
"delete_event_schema_set",
9+
]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import pandas as pd
2+
from typing import Optional
3+
from sempy_labs._helper_functions import (
4+
_base_api,
5+
_create_dataframe,
6+
delete_item,
7+
resolve_workspace_id,
8+
)
9+
from uuid import UUID
10+
from sempy._utils._log import log
11+
12+
13+
@log
14+
def list_event_schema_sets(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
15+
"""
16+
Returns a list of Event Schema Sets from the specified workspace.
17+
18+
This is a wrapper function for the following API: `Items - List Event Schema Sets <https://learn.microsoft.com/rest/api/fabric/eventschemaset/items/list-event-schema-sets>`_.
19+
Parameters
20+
----------
21+
workspace : str | uuid.UUID, default=None
22+
The Fabric workspace name or ID.
23+
Defaults to None which resolves to the workspace of the attached lakehouse
24+
or if no lakehouse attached, resolves to the workspace of the notebook.
25+
26+
Returns
27+
-------
28+
pandas.DataFrame
29+
A pandas dataframe showing the Event Schema Sets within a workspace.
30+
"""
31+
workspace_id = resolve_workspace_id(workspace)
32+
33+
columns = {
34+
"Event Schema Set Name": "str",
35+
"Event Schema Set Id": "str",
36+
"Description": "str",
37+
"OneLake Root Path": "str",
38+
}
39+
df = _create_dataframe(columns=columns)
40+
41+
responses = _base_api(
42+
request=f"v1/workspaces/{workspace_id}/eventSchemaSets",
43+
client="fabric_sp",
44+
uses_pagination=True,
45+
)
46+
47+
rows = []
48+
49+
for r in responses:
50+
for v in r.get("value", []):
51+
row = {
52+
"Event Schema Set Name": v.get("displayName"),
53+
"Event Schema Set Id": v.get("id"),
54+
"Description": v.get("description"),
55+
"OneLake Root Path": v.get("properties", {}).get("oneLakeRootPath"),
56+
}
57+
rows.append(row)
58+
59+
if rows:
60+
df = pd.DataFrame(rows, columns=list(columns.keys()))
61+
62+
return df
63+
64+
65+
@log
66+
def delete_event_schema_set(
67+
event_schema_set: str | UUID, workspace: Optional[str | UUID] = None
68+
):
69+
"""
70+
Deletes an Event Schema Set from the specified workspace.
71+
72+
This is a wrapper function for the following API: `Items - Delete Event Schema Set <https://learn.microsoft.com/rest/api/fabric/eventschemaset/items/delete-event-schema-set>`_.
73+
74+
Parameters
75+
----------
76+
event_schema_set : str | uuid.UUID
77+
The Event Schema Set name or ID to delete.
78+
workspace : str | uuid.UUID, default=None
79+
The Fabric workspace name or ID.
80+
Defaults to None which resolves to the workspace of the attached lakehouse
81+
or if no lakehouse attached, resolves to the workspace of the notebook.
82+
"""
83+
84+
delete_item(item=event_schema_set, type="EventSchemaSet", workspace=workspace)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ._items import (
2+
list_operations_agents,
3+
delete_operations_agent,
4+
)
5+
6+
__all__ = [
7+
"list_operations_agents",
8+
"delete_operations_agent",
9+
]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import pandas as pd
2+
from typing import Optional
3+
from sempy_labs._helper_functions import (
4+
_base_api,
5+
_create_dataframe,
6+
delete_item,
7+
resolve_workspace_id,
8+
)
9+
from uuid import UUID
10+
from sempy._utils._log import log
11+
12+
13+
@log
14+
def list_operations_agents(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
15+
"""
16+
Returns a list of Operations Agents from the specified workspace.
17+
18+
This is a wrapper function for the following API: `Items - List Operations Agents <https://learn.microsoft.com/rest/api/fabric/operationsagent/items/list-operations-agents>`_.
19+
20+
Parameters
21+
----------
22+
workspace : str | uuid.UUID, default=None
23+
The Fabric workspace name or ID.
24+
Defaults to None which resolves to the workspace of the attached lakehouse
25+
or if no lakehouse attached, resolves to the workspace of the notebook.
26+
27+
Returns
28+
-------
29+
pandas.DataFrame
30+
A pandas dataframe showing the Operations Agents within a workspace.
31+
"""
32+
workspace_id = resolve_workspace_id(workspace)
33+
34+
columns = {
35+
"Operations Agent Name": "str",
36+
"Operations Agent Id": "str",
37+
"Description": "str",
38+
"State": "str",
39+
}
40+
df = _create_dataframe(columns=columns)
41+
42+
responses = _base_api(
43+
request=f"v1/workspaces/{workspace_id}/OperationsAgents",
44+
client="fabric_sp",
45+
uses_pagination=True,
46+
)
47+
48+
rows = []
49+
50+
for r in responses:
51+
for v in r.get("value", []):
52+
row = {
53+
"Operations Agent Name": v.get("displayName"),
54+
"Operations Agent Id": v.get("id"),
55+
"Description": v.get("description"),
56+
"State": v.get("properties", {}).get("state"),
57+
}
58+
rows.append(row)
59+
60+
return df
61+
62+
63+
@log
64+
def delete_operations_agent(
65+
operations_agent: str | UUID, workspace: Optional[str | UUID] = None
66+
):
67+
"""
68+
Deletes an Operations Agent from the specified workspace.
69+
70+
This is a wrapper function for the following API: `Items - Delete Operations Agent <https://learn.microsoft.com/rest/api/fabric/operationsagent/items/delete-operations-agent>`_.
71+
72+
Parameters
73+
----------
74+
operations_agent : str | uuid.UUID
75+
The Operations Agent name or ID to delete.
76+
workspace : str | uuid.UUID, default=None
77+
The Fabric workspace name or ID.
78+
Defaults to None which resolves to the workspace of the attached lakehouse
79+
or if no lakehouse attached, resolves to the workspace of the notebook.
80+
"""
81+
82+
delete_item(item=operations_agent, type="OperationsAgent", workspace=workspace)

0 commit comments

Comments
 (0)