msfabricpysdkcore 0.0.13__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msfabricpysdkcore/__init__.py +2 -1
- msfabricpysdkcore/admin_item.py +19 -45
- msfabricpysdkcore/admin_workspace.py +13 -60
- msfabricpysdkcore/adminapi.py +401 -476
- msfabricpysdkcore/auth.py +10 -6
- msfabricpysdkcore/client.py +124 -7
- msfabricpysdkcore/coreapi.py +2570 -822
- msfabricpysdkcore/deployment_pipeline.py +34 -146
- msfabricpysdkcore/domain.py +20 -219
- msfabricpysdkcore/environment.py +13 -172
- msfabricpysdkcore/fabric_azure_capacity.py +77 -0
- msfabricpysdkcore/fabric_azure_client.py +228 -0
- msfabricpysdkcore/item.py +55 -331
- msfabricpysdkcore/job_instance.py +8 -22
- msfabricpysdkcore/lakehouse.py +9 -118
- msfabricpysdkcore/long_running_operation.py +7 -37
- msfabricpysdkcore/onelakeshortcut.py +7 -21
- msfabricpysdkcore/otheritems.py +66 -91
- msfabricpysdkcore/spark_custom_pool.py +7 -47
- msfabricpysdkcore/tests/test_admin_apis.py +9 -10
- msfabricpysdkcore/tests/test_datapipelines.py +15 -18
- msfabricpysdkcore/tests/test_deployment_pipeline.py +3 -3
- msfabricpysdkcore/tests/test_domains.py +6 -5
- msfabricpysdkcore/tests/test_environments.py +54 -5
- msfabricpysdkcore/tests/test_evenhouses.py +47 -0
- msfabricpysdkcore/tests/test_evenstreams.py +20 -20
- msfabricpysdkcore/tests/test_external_data_shares.py +3 -3
- msfabricpysdkcore/tests/test_fabric_azure_client.py +78 -0
- msfabricpysdkcore/tests/test_git.py +8 -9
- msfabricpysdkcore/tests/test_items.py +81 -0
- msfabricpysdkcore/tests/test_jobs.py +2 -2
- msfabricpysdkcore/tests/test_kql_queryset.py +49 -0
- msfabricpysdkcore/tests/test_kqldatabases.py +3 -3
- msfabricpysdkcore/tests/test_lakehouse.py +84 -0
- msfabricpysdkcore/tests/test_ml_experiments.py +47 -0
- msfabricpysdkcore/tests/test_ml_models.py +47 -0
- msfabricpysdkcore/tests/test_notebooks.py +57 -0
- msfabricpysdkcore/tests/test_one_lake_data_access_security.py +2 -4
- msfabricpysdkcore/tests/test_other_items.py +45 -0
- msfabricpysdkcore/tests/test_reports.py +52 -0
- msfabricpysdkcore/tests/test_semantic_model.py +50 -0
- msfabricpysdkcore/tests/test_shortcuts.py +4 -4
- msfabricpysdkcore/tests/test_spark.py +9 -9
- msfabricpysdkcore/tests/test_sparkjobdefinition.py +2 -2
- msfabricpysdkcore/tests/test_warehouses.py +50 -0
- msfabricpysdkcore/tests/test_workspaces_capacities.py +16 -13
- msfabricpysdkcore/workspace.py +397 -1163
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.2.dist-info}/METADATA +72 -10
- msfabricpysdkcore-0.1.2.dist-info/RECORD +55 -0
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.2.dist-info}/WHEEL +1 -1
- msfabricpysdkcore-0.0.13.dist-info/RECORD +0 -41
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.2.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.2.dist-info}/top_level.txt +0 -0
msfabricpysdkcore/coreapi.py
CHANGED
@@ -1,776 +1,2421 @@
|
|
1
|
-
import requests
|
2
1
|
import json
|
3
2
|
from time import sleep
|
4
3
|
|
5
|
-
from msfabricpysdkcore.capacity import Capacity
|
6
4
|
from msfabricpysdkcore.client import FabricClient
|
7
|
-
from msfabricpysdkcore.deployment_pipeline import DeploymentPipeline
|
8
|
-
from msfabricpysdkcore.long_running_operation import LongRunningOperation
|
9
|
-
from msfabricpysdkcore.workspace import Workspace
|
10
5
|
|
11
6
|
class FabricClientCore(FabricClient):
|
12
7
|
"""FabricClientCore class to interact with Fabric Core APIs"""
|
13
8
|
|
14
9
|
def __init__(self, tenant_id = None, client_id = None, client_secret = None, silent=False) -> None:
|
15
10
|
"""Initialize FabricClientCore object"""
|
16
|
-
super().__init__(
|
11
|
+
super().__init__(scope="https://api.fabric.microsoft.com/.default",
|
12
|
+
tenant_id=tenant_id,
|
13
|
+
client_id=client_id,
|
14
|
+
client_secret=client_secret, silent=silent)
|
17
15
|
|
16
|
+
def long_running_operation(self, response_headers):
|
17
|
+
"""Check the status of a long running operation"""
|
18
|
+
from msfabricpysdkcore.long_running_operation import check_long_running_operation
|
18
19
|
|
19
|
-
|
20
|
-
"""List all workspaces in the tenant"""
|
20
|
+
return check_long_running_operation(response_headers, self)
|
21
21
|
|
22
|
+
### Capacities
|
23
|
+
|
24
|
+
def get_capacity(self, capacity_id = None, capacity_name = None):
|
25
|
+
"""Get a capacity
|
26
|
+
|
27
|
+
Args:
|
28
|
+
capacity_id (str): The ID of the capacity
|
29
|
+
capacity_name (str): The name of the capacity
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
Capacity: The capacity object
|
33
|
+
|
34
|
+
Raises:
|
35
|
+
ValueError: If no capacity is found
|
36
|
+
"""
|
37
|
+
if capacity_id is None and capacity_name is None:
|
38
|
+
raise ValueError("Either capacity_id or capacity_name must be provided")
|
39
|
+
caps = self.list_capacities()
|
40
|
+
for cap in caps:
|
41
|
+
if capacity_id and cap.id == capacity_id:
|
42
|
+
return cap
|
43
|
+
if capacity_name and cap.display_name == capacity_name:
|
44
|
+
return cap
|
45
|
+
raise ValueError("No capacity found")
|
46
|
+
|
47
|
+
def list_capacities(self):
|
48
|
+
"""List all capacities in the tenant
|
49
|
+
Returns:
|
50
|
+
list: The list of capacities
|
51
|
+
"""
|
52
|
+
from msfabricpysdkcore.capacity import Capacity
|
53
|
+
url = "https://api.fabric.microsoft.com/v1/capacities"
|
54
|
+
|
55
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error listing capacities", return_format="value_json", paging=True)
|
56
|
+
|
57
|
+
items = [Capacity.from_dict(i) for i in items]
|
58
|
+
return items
|
59
|
+
|
60
|
+
# Deployment Pipelines
|
61
|
+
|
62
|
+
def deploy_stage_content(self, deployment_pipeline_id, source_stage_id, target_stage_id, created_workspace_details = None,
|
63
|
+
items = None, note = None, wait_for_completion = True):
|
64
|
+
"""Deploy stage content
|
65
|
+
Args:
|
66
|
+
deployment_pipeline_id (str): The ID of the deployment pipeline
|
67
|
+
source_stage_id (str): The ID of the source stage
|
68
|
+
target_stage_id (str): The ID of the target stage
|
69
|
+
created_workspace_details (list): A list of created workspace details
|
70
|
+
items (list): A list of items
|
71
|
+
note (str): A note
|
72
|
+
wait_for_completion (bool): Whether to wait for the deployment to complete
|
73
|
+
Returns:
|
74
|
+
Details about the dpeloyment
|
75
|
+
"""
|
76
|
+
|
77
|
+
# POST https://api.fabric.microsoft.com/v1/deploymentPipelines/{deploymentPipelineId}/deploy
|
78
|
+
|
79
|
+
url = f"https://api.fabric.microsoft.com/v1/deploymentPipelines/{deployment_pipeline_id}/deploy"
|
80
|
+
|
81
|
+
body = {
|
82
|
+
"sourceStageId": source_stage_id,
|
83
|
+
"targetStageId": target_stage_id
|
84
|
+
}
|
85
|
+
|
86
|
+
if created_workspace_details:
|
87
|
+
body["createdWorkspaceDetails"] = created_workspace_details
|
88
|
+
if items:
|
89
|
+
body["items"] = items
|
90
|
+
if note:
|
91
|
+
body["note"] = note
|
92
|
+
|
93
|
+
json_operation_result = self.calling_routine(url, operation="POST", body=body, response_codes=[200, 202, 429], error_message="Error deploying stage content",
|
94
|
+
return_format="json+operation_result", wait_for_completion=wait_for_completion)
|
95
|
+
|
96
|
+
return json_operation_result
|
97
|
+
|
98
|
+
def get_deployment_pipeline(self, deployment_pipeline_id):
|
99
|
+
"""Get a deployment pipeline
|
100
|
+
Args:
|
101
|
+
deployment_pipeline_id (str): The ID of the deployment pipeline
|
102
|
+
Returns:
|
103
|
+
DeploymentPipeline: The deployment pipeline
|
104
|
+
"""
|
105
|
+
from msfabricpysdkcore.deployment_pipeline import DeploymentPipeline
|
106
|
+
url = f"https://api.fabric.microsoft.com/v1/deploymentPipelines/{deployment_pipeline_id}"
|
107
|
+
|
108
|
+
result_json = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting deployment pipeline", return_format="json")
|
109
|
+
|
110
|
+
return DeploymentPipeline.from_dict(result_json, self)
|
111
|
+
|
112
|
+
def get_deployment_pipeline_stages_items(self, pipeline_id, stage_id = None, stage_name = None):
|
113
|
+
print("DEPRECATED: Use list_deployment_pipeline_stages_items instead")
|
114
|
+
return self.list_deployment_pipeline_stages_items(pipeline_id, stage_id, stage_name)
|
115
|
+
|
116
|
+
def list_deployment_pipeline_stages_items(self, deployment_pipeline_id, stage_id = None, stage_name = None):
|
117
|
+
"""List the items in a deployment stage
|
118
|
+
Args:
|
119
|
+
pipeline_id (str): The ID of the deployment pipeline
|
120
|
+
stage_id (str): The ID of the deployment stage
|
121
|
+
stage_name (str): The name of the deployment stage
|
122
|
+
Returns:
|
123
|
+
list: List of DeploymentStageItem objects
|
124
|
+
"""
|
125
|
+
|
126
|
+
if stage_id == None and stage_name == None:
|
127
|
+
raise Exception("Please provide either stage_id or stage_name")
|
128
|
+
|
129
|
+
if stage_id is None:
|
130
|
+
stages = self.list_deployment_pipeline_stages(deployment_pipeline_id)
|
131
|
+
dep_pip_stages = [stage for stage in stages if stage.display_name == stage_name]
|
132
|
+
if len(dep_pip_stages) == 0:
|
133
|
+
raise Exception(f"Stage with name {stage_name} not found")
|
134
|
+
stage_id = dep_pip_stages[0].id
|
135
|
+
|
136
|
+
url = f"https://api.fabric.microsoft.com/v1/deploymentPipelines/{deployment_pipeline_id}/stages/{stage_id}/items"
|
137
|
+
|
138
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
139
|
+
error_message="Error getting deployment pipeline stage items", return_format="value_json", paging=True)
|
140
|
+
|
141
|
+
return items
|
142
|
+
|
143
|
+
def get_deployment_pipeline_stages(self, pipeline_id):
|
144
|
+
"""Get the stages of a deployment pipeline
|
145
|
+
Args:
|
146
|
+
pipeline_id (str): The ID of the deployment pipeline
|
147
|
+
Returns:
|
148
|
+
list: List of DeploymentPipelineStage objects
|
149
|
+
"""
|
150
|
+
print("DEPRECATED: Use list_deployment_pipeline_stages instead")
|
151
|
+
return self.list_deployment_pipeline_stages(pipeline_id)
|
152
|
+
|
153
|
+
def list_deployment_pipeline_stages(self, deployment_pipeline_id):
|
154
|
+
"""Get the stages of a deployment pipeline
|
155
|
+
Args:
|
156
|
+
pipeline_id (str): The ID of the deployment pipeline
|
157
|
+
Returns:
|
158
|
+
list: List of DeploymentPipelineStage objects
|
159
|
+
"""
|
160
|
+
from msfabricpysdkcore.deployment_pipeline import Deployment_Pipeline_Stage
|
161
|
+
|
162
|
+
url = f"https://api.fabric.microsoft.com/v1/deploymentPipelines/{deployment_pipeline_id}/stages"
|
163
|
+
|
164
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
165
|
+
error_message="Error getting deployment pipeline stages", return_format="value_json", paging=True)
|
166
|
+
|
167
|
+
for item in items:
|
168
|
+
item["deploymentPipelineId"] = deployment_pipeline_id
|
169
|
+
stages = [Deployment_Pipeline_Stage.from_dict(item, self) for item in items]
|
170
|
+
|
171
|
+
return stages
|
172
|
+
|
173
|
+
def list_deployment_pipelines(self):
|
174
|
+
"""List deployment pipelines
|
175
|
+
Returns:
|
176
|
+
list: List of DeploymentPipeline objects
|
177
|
+
"""
|
178
|
+
from msfabricpysdkcore.deployment_pipeline import DeploymentPipeline
|
179
|
+
|
180
|
+
url = "https://api.fabric.microsoft.com/v1/deploymentPipelines"
|
181
|
+
|
182
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
183
|
+
error_message="Error listing deployment pipelines", return_format="value_json", paging=True)
|
184
|
+
|
185
|
+
|
186
|
+
dep_pipes = [DeploymentPipeline.from_dict(i, core_client=self) for i in items]
|
187
|
+
|
188
|
+
return dep_pipes
|
189
|
+
|
190
|
+
# External Data Shares
|
191
|
+
|
192
|
+
# create
|
193
|
+
|
194
|
+
def create_external_data_share(self, workspace_id, item_id, paths, recipient):
|
195
|
+
"""Create an external data share in an item
|
196
|
+
Args:
|
197
|
+
workspace_id (str): The ID of the workspace
|
198
|
+
item_id (str): The ID of the item
|
199
|
+
paths (list): The paths to share
|
200
|
+
recipient (str): The recipient of the share
|
201
|
+
Returns:
|
202
|
+
dict: The external data share
|
203
|
+
"""
|
204
|
+
|
205
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/externalDataShares"
|
206
|
+
|
207
|
+
body = {
|
208
|
+
'paths': paths,
|
209
|
+
'recipient': recipient
|
210
|
+
}
|
211
|
+
response_json = self.calling_routine(url, operation="POST", body=body, response_codes=[201, 429],
|
212
|
+
error_message="Error creating external data share", return_format="json")
|
213
|
+
return response_json
|
214
|
+
|
215
|
+
def get_external_data_share(self, workspace_id, item_id, external_data_share_id):
|
216
|
+
"""Get an external data share in an item
|
217
|
+
Args:
|
218
|
+
workspace_id (str): The ID of the workspace
|
219
|
+
item_id (str): The ID of the item
|
220
|
+
external_data_share_id (str): The ID of the external data share
|
221
|
+
Returns:
|
222
|
+
dict: The external data share
|
223
|
+
"""
|
224
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/externalDataShares/{external_data_share_id}"
|
225
|
+
response_json = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
226
|
+
error_message="Error getting external data share", return_format="json")
|
227
|
+
return response_json
|
228
|
+
|
229
|
+
# list
|
230
|
+
|
231
|
+
def list_external_data_shares_in_item(self, workspace_id, item_id):
|
232
|
+
"""List external data shares in an item
|
233
|
+
Args:
|
234
|
+
workspace_id (str): The ID of the workspace
|
235
|
+
item_id (str): The ID of the item
|
236
|
+
Returns:
|
237
|
+
list: The list of external data shares
|
238
|
+
"""
|
239
|
+
|
240
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/externalDataShares"
|
241
|
+
|
242
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
243
|
+
error_message="Error listing external data shares", return_format="value_json", paging=True)
|
244
|
+
return items
|
245
|
+
|
246
|
+
# revoke
|
247
|
+
|
248
|
+
def revoke_external_data_share(self, workspace_id, item_id, external_data_share_id):
|
249
|
+
"""Revoke an external data share in an item
|
250
|
+
Args:
|
251
|
+
workspace_id (str): The ID of the workspace
|
252
|
+
item_id (str): The ID of the item
|
253
|
+
external_data_share_id (str): The ID of the external data share
|
254
|
+
Returns:
|
255
|
+
int: The status code of the response
|
256
|
+
"""
|
257
|
+
|
258
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/externalDataShares/{external_data_share_id}/revoke"
|
259
|
+
|
260
|
+
response = self.calling_routine(url, operation="POST", response_codes=[200, 429], error_message="Error revoking external data share", return_format="response")
|
261
|
+
return response.status_code
|
262
|
+
|
263
|
+
# Git
|
264
|
+
|
265
|
+
def commit_to_git(self, workspace_id, mode, comment=None, items=None, workspace_head=None):
|
266
|
+
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/commitToGit
|
267
|
+
"""Commit to git
|
268
|
+
Args:
|
269
|
+
workspace_id (str): The ID of the workspace
|
270
|
+
mode (str): The mode of the commit
|
271
|
+
comment (str): The comment of the commit
|
272
|
+
items (list): The list of items
|
273
|
+
workspace_head (str): The workspace head
|
274
|
+
Returns:
|
275
|
+
int: The status code of the response
|
276
|
+
"""
|
277
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/commitToGit"
|
278
|
+
|
279
|
+
body = {
|
280
|
+
'mode': mode
|
281
|
+
}
|
282
|
+
|
283
|
+
if comment:
|
284
|
+
body['comment'] = comment
|
285
|
+
if items:
|
286
|
+
body['items'] = items
|
287
|
+
if workspace_head:
|
288
|
+
body['workspaceHead'] = workspace_head
|
289
|
+
|
290
|
+
response = self.calling_routine(url=url, operation="POST", body=body,
|
291
|
+
response_codes=[200, 202, 429],
|
292
|
+
error_message="Error committing to git", return_format="response")
|
293
|
+
|
294
|
+
return response.status_code
|
295
|
+
|
296
|
+
def git_connect(self, workspace_id, git_provider_details):
|
297
|
+
"""Connect git
|
298
|
+
Args:
|
299
|
+
workspace_id (str): The ID of the workspace
|
300
|
+
git_provider_details (dict): The git provider details
|
301
|
+
Returns:
|
302
|
+
int: The status code of the response
|
303
|
+
"""
|
304
|
+
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/connect
|
305
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/connect"
|
306
|
+
|
307
|
+
payload = {
|
308
|
+
'gitProviderDetails': git_provider_details
|
309
|
+
}
|
310
|
+
|
311
|
+
response = self.calling_routine(url=url, operation="POST", body=payload,
|
312
|
+
response_codes=[200, 202, 429],
|
313
|
+
error_message="Error connecting git", return_format="response")
|
314
|
+
|
315
|
+
return response.status_code
|
316
|
+
|
317
|
+
def git_disconnect(self, workspace_id):
|
318
|
+
"""Disconnect git
|
319
|
+
Args:
|
320
|
+
workspace_id (str): The ID of the workspace
|
321
|
+
Returns:
|
322
|
+
int: The status code of the response
|
323
|
+
"""
|
324
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/disconnect"
|
325
|
+
|
326
|
+
response = self.calling_routine(url=url, operation="POST", response_codes=[200, 204, 429],
|
327
|
+
error_message="Error disconnecting git", return_format="response")
|
328
|
+
return response.status_code
|
329
|
+
|
330
|
+
def git_get_connection(self, workspace_id):
|
331
|
+
"""Get git connection info
|
332
|
+
Args:
|
333
|
+
workspace_id (str): The ID of the workspace
|
334
|
+
Returns:
|
335
|
+
dict: The git connection info
|
336
|
+
"""
|
337
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/connection"
|
338
|
+
|
339
|
+
response_json = self.calling_routine(url=url, operation="GET", response_codes=[200, 429],
|
340
|
+
error_message="Error getting git connection info", return_format="json")
|
341
|
+
|
342
|
+
return response_json
|
343
|
+
|
344
|
+
def git_get_status(self, workspace_id):
|
345
|
+
"""Get git connection status
|
346
|
+
Args:
|
347
|
+
workspace_id (str): The ID of the workspace
|
348
|
+
Returns:
|
349
|
+
dict: The git connection status
|
350
|
+
"""
|
351
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/status"
|
352
|
+
|
353
|
+
response_json = self.calling_routine(url=url, operation="GET", response_codes=[200, 429],
|
354
|
+
error_message="Error getting git connection status",
|
355
|
+
return_format="json")
|
356
|
+
|
357
|
+
return response_json
|
358
|
+
|
359
|
+
def git_initialize_connection(self, workspace_id, initialization_strategy):
|
360
|
+
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/initializeConnection
|
361
|
+
"""Initialize git connection
|
362
|
+
Args:
|
363
|
+
workspace_id (str): The ID of the workspace
|
364
|
+
initialization_strategy (dict): The initialization strategy
|
365
|
+
Returns:
|
366
|
+
int: The status code of the response
|
367
|
+
"""
|
368
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/initializeConnection"
|
369
|
+
|
370
|
+
body = {'initializeGitConnectionRequest':initialization_strategy}
|
371
|
+
|
372
|
+
response = self.calling_routine(url=url, operation="POST", body=body, response_codes=[200, 202, 429],
|
373
|
+
error_message="Error initializing connection", return_format="response")
|
374
|
+
|
375
|
+
return response.status_code
|
376
|
+
|
377
|
+
def update_from_git(self, workspace_id, remote_commit_hash, conflict_resolution = None,
|
378
|
+
options = None, workspace_head = None):
|
379
|
+
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/updateFromGit
|
380
|
+
"""Update from git"""
|
381
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/git/updateFromGit"
|
382
|
+
|
383
|
+
body = {
|
384
|
+
"remoteCommitHash" : remote_commit_hash
|
385
|
+
}
|
386
|
+
|
387
|
+
if conflict_resolution:
|
388
|
+
body['conflictResolution'] = conflict_resolution
|
389
|
+
if options:
|
390
|
+
body['options'] = options
|
391
|
+
if workspace_head:
|
392
|
+
body['workspaceHead'] = workspace_head
|
393
|
+
|
394
|
+
response = self.calling_routine(url=url, operation="POST", body=body,
|
395
|
+
response_codes=[200, 202, 429],
|
396
|
+
error_message="Error updating from git", return_format="response")
|
397
|
+
|
398
|
+
return response.status_code
|
399
|
+
|
400
|
+
|
401
|
+
# Items
|
402
|
+
|
403
|
+
# Helper Functions
|
404
|
+
|
405
|
+
def get_item_by_name(self, workspace_id, item_name, item_type):
|
406
|
+
"""Get an item from a workspace by name
|
407
|
+
Args:
|
408
|
+
workspace_id (str): The ID of the workspace
|
409
|
+
item_name (str): The name of the item
|
410
|
+
item_type (str): The type of the item
|
411
|
+
Returns:
|
412
|
+
Item: The item object
|
413
|
+
"""
|
414
|
+
ws_items = self.list_items(workspace_id = workspace_id, with_properties=False)
|
415
|
+
for item in ws_items:
|
416
|
+
if item.display_name == item_name and item.type == item_type:
|
417
|
+
return self.get_item(workspace_id, item.id, item_type)
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
def get_item_specific(self, workspace_id, item_dict):
|
422
|
+
"""Get the item object based on the type
|
423
|
+
Args:
|
424
|
+
workspace_id (str): The ID of the workspace
|
425
|
+
item_dict (dict): The dictionary representing the item
|
426
|
+
Returns:
|
427
|
+
Item: The item object
|
428
|
+
"""
|
429
|
+
from msfabricpysdkcore.item import Item
|
430
|
+
|
431
|
+
if item_dict["type"] == "DataPipeline":
|
432
|
+
return self.get_data_pipeline(workspace_id, item_dict["id"])
|
433
|
+
if item_dict["type"] == "Eventstream":
|
434
|
+
return self.get_eventstream(workspace_id, item_dict["id"])
|
435
|
+
if item_dict["type"] == "Eventhouse":
|
436
|
+
return self.get_eventhouse(workspace_id, item_dict["id"])
|
437
|
+
if item_dict["type"] == "KQLDatabase":
|
438
|
+
return self.get_kql_database(workspace_id, item_dict["id"])
|
439
|
+
if item_dict["type"] == "KQLQueryset":
|
440
|
+
return self.get_kql_queryset(workspace_id, item_dict["id"])
|
441
|
+
if item_dict["type"] == "Lakehouse":
|
442
|
+
return self.get_lakehouse(workspace_id, item_dict["id"])
|
443
|
+
if item_dict["type"] == "MLExperiment":
|
444
|
+
return self.get_ml_experiment(workspace_id, item_dict["id"])
|
445
|
+
if item_dict["type"] == "MLModel":
|
446
|
+
return self.get_ml_model(workspace_id, item_dict["id"])
|
447
|
+
if item_dict["type"] == "Notebook":
|
448
|
+
return self.get_notebook(workspace_id, item_dict["id"])
|
449
|
+
if item_dict["type"] == "Report":
|
450
|
+
return self.get_report(workspace_id, item_dict["id"])
|
451
|
+
if item_dict["type"] == "SemanticModel":
|
452
|
+
return self.get_semantic_model(workspace_id, item_dict["id"])
|
453
|
+
if item_dict["type"] == "SparkJobDefinition":
|
454
|
+
return self.get_spark_job_definition(workspace_id, item_dict["id"])
|
455
|
+
if item_dict["type"] == "Warehouse":
|
456
|
+
return self.get_warehouse(workspace_id, item_dict["id"])
|
457
|
+
if item_dict["type"] == "Environment":
|
458
|
+
return self.get_environment(workspace_id, item_dict["id"])
|
459
|
+
|
460
|
+
item_obj = Item.from_dict(item_dict, core_client=self)
|
461
|
+
return item_obj
|
462
|
+
|
463
|
+
def get_item_object_w_properties(self, workspace_id, item_list):
|
464
|
+
"""Get the item object with properties
|
465
|
+
Args:
|
466
|
+
workspace_id (str): The ID of the workspace
|
467
|
+
item_list (list): The list of items
|
468
|
+
Returns:
|
469
|
+
list: The list of item objects
|
470
|
+
"""
|
471
|
+
|
472
|
+
new_item_list = [self.get_item_specific(workspace_id, item) for item in item_list]
|
473
|
+
return new_item_list
|
474
|
+
|
475
|
+
# Create
|
476
|
+
|
477
|
+
def create_item(self, workspace_id, display_name, type, definition = None, description = None, wait_for_completion = True, **kwargs):
|
478
|
+
"""Create an item in a workspace
|
479
|
+
Args:
|
480
|
+
workspace_id (str): The ID of the workspace
|
481
|
+
display_name (str): The display name of the item
|
482
|
+
type (str): The type of the item
|
483
|
+
definition (dict): The definition of the item
|
484
|
+
description (str): The description of the item
|
485
|
+
kwargs: Additional arguments
|
486
|
+
Returns:
|
487
|
+
Item: The created item
|
488
|
+
"""
|
489
|
+
|
490
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items"
|
491
|
+
body = {
|
492
|
+
'displayName': display_name,
|
493
|
+
'type': type
|
494
|
+
}
|
495
|
+
|
496
|
+
if definition:
|
497
|
+
body['definition'] = definition
|
498
|
+
if description:
|
499
|
+
body['description'] = description
|
500
|
+
|
501
|
+
if type in ["dataPipelines",
|
502
|
+
"environments",
|
503
|
+
"eventhouses",
|
504
|
+
"eventstreams",
|
505
|
+
"kqlDatabases",
|
506
|
+
"lakehouses",
|
507
|
+
"mlExperiments",
|
508
|
+
"mlModels",
|
509
|
+
"notebooks",
|
510
|
+
"reports",
|
511
|
+
"semanticModels",
|
512
|
+
"sparkJobDefinitions",
|
513
|
+
"warehouses"]:
|
514
|
+
|
515
|
+
if type == "kqlDatabases":
|
516
|
+
if "creation_payload" not in kwargs:
|
517
|
+
raise Exception("creation_payload is required for KQLDatabase")
|
518
|
+
body["creationPayload"] = kwargs["creation_payload"]
|
519
|
+
|
520
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/{type}"
|
521
|
+
body.pop('type')
|
522
|
+
|
523
|
+
|
524
|
+
item_dict = self.calling_routine(url, operation="POST",
|
525
|
+
body=body, response_codes=[201, 202, 429],
|
526
|
+
error_message="Error creating item", return_format="json+operation_result",
|
527
|
+
wait_for_completion=wait_for_completion)
|
528
|
+
|
529
|
+
|
530
|
+
if item_dict is None or "no_operation_result" in item_dict:
|
531
|
+
print("Item not returned by API, trying to get it by name")
|
532
|
+
item = None
|
533
|
+
i = 0
|
534
|
+
|
535
|
+
type_mapping = {"dataPipelines": "DataPipeline",
|
536
|
+
"environments": "Environment",
|
537
|
+
"eventhouses": "Eventhouse",
|
538
|
+
"eventstreams": "Eventstream",
|
539
|
+
"kqlDatabases": "KQLDatabase",
|
540
|
+
"lakehouses": "Lakehouse",
|
541
|
+
"mlExperiments": "MLExperiment",
|
542
|
+
"mlModels": "MLModel",
|
543
|
+
"notebooks": "Notebook",
|
544
|
+
"reports": "Report",
|
545
|
+
"semanticModels": "SemanticModel",
|
546
|
+
"sparkJobDefinitions": "SparkJobDefinition",
|
547
|
+
"warehouses": "Warehouse"
|
548
|
+
}
|
549
|
+
|
550
|
+
if type in type_mapping.keys():
|
551
|
+
type = type_mapping[type]
|
552
|
+
while item is None and i < 12:
|
553
|
+
item = self.get_item_by_name(workspace_id, display_name, type)
|
554
|
+
if item is not None:
|
555
|
+
return item
|
556
|
+
print("Item not found, waiting 5 seconds")
|
557
|
+
sleep(5)
|
558
|
+
i += 1
|
559
|
+
|
560
|
+
print("Item not found after 1 minute, returning None")
|
561
|
+
return None
|
562
|
+
|
563
|
+
return self.get_item_specific(workspace_id, item_dict)
|
564
|
+
|
565
|
+
# Get
|
566
|
+
|
567
|
+
def get_item(self, workspace_id, item_id = None, item_name = None, item_type = None):
|
568
|
+
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items/{itemId}
|
569
|
+
"""Get an item from a workspace
|
570
|
+
Args:
|
571
|
+
workspace_id (str): The ID of the workspace
|
572
|
+
item_id (str): The ID of the item
|
573
|
+
item_name (str): The name of the item
|
574
|
+
item_type (str): The type of the item
|
575
|
+
Returns:
|
576
|
+
Item: The item object
|
577
|
+
Raises:
|
578
|
+
Exception: If item_id or the combination item_name + item_type is required
|
579
|
+
"""
|
580
|
+
if item_type:
|
581
|
+
if item_type.lower() == "datapipeline":
|
582
|
+
return self.get_data_pipeline(workspace_id, item_id, item_name)
|
583
|
+
if item_type.lower() == "eventstream":
|
584
|
+
return self.get_eventstream(workspace_id, item_id, item_name)
|
585
|
+
if item_type.lower() == "kqldatabase":
|
586
|
+
return self.get_kql_database(workspace_id, item_id, item_name)
|
587
|
+
if item_type.lower() == "kqlqueryset":
|
588
|
+
return self.get_kql_queryset(workspace_id, item_id, item_name)
|
589
|
+
if item_type.lower() == "lakehouse":
|
590
|
+
return self.get_lakehouse(workspace_id, item_id, item_name)
|
591
|
+
if item_type.lower() == "mlmodel":
|
592
|
+
return self.get_ml_model(workspace_id, item_id, item_name)
|
593
|
+
if item_type.lower() == "mlexperiment":
|
594
|
+
return self.get_ml_experiment(workspace_id, item_id, item_name)
|
595
|
+
if item_type.lower() == "notebook":
|
596
|
+
return self.get_notebook(workspace_id, item_id, item_name)
|
597
|
+
if item_type.lower() == "report":
|
598
|
+
return self.get_report(workspace_id, item_id, item_name)
|
599
|
+
if item_type.lower() == "semanticmodel":
|
600
|
+
return self.get_semantic_model(workspace_id, item_id, item_name)
|
601
|
+
if item_type.lower() == "sparkjobdefinition":
|
602
|
+
return self.get_spark_job_definition(workspace_id, item_id, item_name)
|
603
|
+
if item_type.lower() == "warehouse":
|
604
|
+
return self.get_warehouse(workspace_id, item_id, item_name)
|
605
|
+
|
606
|
+
if item_id is None and item_name is not None and item_type is not None:
|
607
|
+
return self.get_item_by_name(workspace_id, item_name, item_type)
|
608
|
+
elif item_id is None:
|
609
|
+
raise Exception("item_id or the combination item_name + item_type is required")
|
610
|
+
|
611
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}"
|
612
|
+
|
613
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting item", return_format="json")
|
614
|
+
|
615
|
+
return self.get_item_specific(workspace_id=workspace_id, item_dict = item_dict)
|
616
|
+
|
617
|
+
# Delete
|
618
|
+
|
619
|
+
def delete_item(self, workspace_id, item_id, type = None):
|
620
|
+
"""Delete an item from a workspace
|
621
|
+
Args:
|
622
|
+
workspace_id (str): The ID of the workspace
|
623
|
+
item_id (str): The ID of the item
|
624
|
+
type (str): The type of the item
|
625
|
+
Returns:
|
626
|
+
int: The status code of the response
|
627
|
+
"""
|
628
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}"
|
629
|
+
if type:
|
630
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/{type}/{item_id}"
|
631
|
+
|
632
|
+
response = self.calling_routine(url, operation="DELETE", response_codes=[200, 429], return_format="response",
|
633
|
+
error_message="Error deleting item")
|
634
|
+
|
635
|
+
return response.status_code
|
636
|
+
|
637
|
+
# List
|
638
|
+
|
639
|
+
def list_items(self, workspace_id, with_properties = False, type = None):
|
640
|
+
"""List items in a workspace
|
641
|
+
Args:
|
642
|
+
workspace_id (str): The ID of the workspace
|
643
|
+
with_properties (bool): Whether to get the item object with properties
|
644
|
+
type (str): The type of the item
|
645
|
+
Returns:
|
646
|
+
list: The list of items
|
647
|
+
"""
|
648
|
+
from msfabricpysdkcore.item import Item
|
649
|
+
|
650
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items"
|
651
|
+
if type:
|
652
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/{type}"
|
653
|
+
|
654
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
655
|
+
error_message="Error listing items", return_format="value_json", paging=True)
|
656
|
+
|
657
|
+
if with_properties:
|
658
|
+
items = self.get_item_object_w_properties(items)
|
659
|
+
else:
|
660
|
+
items = [Item.from_dict(item, core_client=self) for item in items]
|
661
|
+
|
662
|
+
return items
|
663
|
+
|
664
|
+
|
665
|
+
def get_item_definition(self, workspace_id, item_id, type = None, format = None):
|
666
|
+
"""Get the item definition
|
667
|
+
Args:
|
668
|
+
workspace_id (str): The ID of the workspace
|
669
|
+
item_id (str): The ID of the item
|
670
|
+
type (str): The type of the item
|
671
|
+
format (str): The format of the item
|
672
|
+
Returns:
|
673
|
+
dict: The item definition
|
674
|
+
"""
|
675
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/getDefinition"
|
676
|
+
if type:
|
677
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/{type}/{item_id}/getDefinition"
|
678
|
+
|
679
|
+
if format:
|
680
|
+
url += f"?format={format}"
|
681
|
+
|
682
|
+
return self.calling_routine(url, operation="POST", response_codes=[200, 202, 429],
|
683
|
+
error_message="Error getting item definition",
|
684
|
+
return_format="json+operation_result")
|
685
|
+
|
686
|
+
|
687
|
+
def update_item(self, workspace_id, item_id, display_name = None, description = None, type = None, return_item="Default"):
|
688
|
+
"""Update the item
|
689
|
+
Args:
|
690
|
+
workspace_id (str): The ID of the workspace
|
691
|
+
item_id (str): The ID of the item
|
692
|
+
display_name (str): The display name of the item
|
693
|
+
description (str): The description of the item
|
694
|
+
type (str): The type of the item
|
695
|
+
Returns:
|
696
|
+
dict: The updated item
|
697
|
+
"""
|
698
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}"
|
699
|
+
if type:
|
700
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/{type}/{item_id}"
|
701
|
+
|
702
|
+
payload = dict()
|
703
|
+
if display_name:
|
704
|
+
payload['displayName'] = display_name
|
705
|
+
if description:
|
706
|
+
payload['description'] = description
|
707
|
+
|
708
|
+
resp_dict = self.calling_routine(url, operation="PATCH", body=payload,
|
709
|
+
response_codes=[200, 429], error_message="Error updating item",
|
710
|
+
return_format="json")
|
711
|
+
if return_item == "Default":
|
712
|
+
print("""Warning: Updating an item currently will make invoke an additional API call to get the item object.
|
713
|
+
This default behaviour will change in newer versions of the SDK.
|
714
|
+
To keep this behaviour, set return_item=True in the function call.""")
|
715
|
+
if return_item:
|
716
|
+
return self.get_item_specific(workspace_id, resp_dict)
|
717
|
+
return resp_dict
|
718
|
+
|
719
|
+
def update_item_definition(self, workspace_id, item_id, definition, type = None, wait_for_completion=True):
|
720
|
+
"""Update the item definition
|
721
|
+
Args:
|
722
|
+
workspace_id (str): The ID of the workspace
|
723
|
+
item_id (str): The ID of the item
|
724
|
+
definition (dict): The definition of the item
|
725
|
+
type (str): The type of the item
|
726
|
+
Returns:
|
727
|
+
requests.Response: The response object
|
728
|
+
"""
|
729
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/updateDefinition"
|
730
|
+
|
731
|
+
if type:
|
732
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/{type}/{item_id}/updateDefinition"
|
733
|
+
|
734
|
+
payload = {
|
735
|
+
'definition': definition
|
736
|
+
}
|
737
|
+
|
738
|
+
response = self.calling_routine(url, operation="POST", body=payload, response_codes=[200, 202, 429],
|
739
|
+
error_message="Error updating item definition", return_format="response",
|
740
|
+
wait_for_completion=wait_for_completion)
|
741
|
+
return response
|
742
|
+
|
743
|
+
# Job Scheduler
|
744
|
+
|
745
|
+
def cancel_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
746
|
+
"""Cancel the job instance
|
747
|
+
Args:
|
748
|
+
workspace_id (str): The ID of the workspace
|
749
|
+
item_id (str): The ID of the item
|
750
|
+
job_instance_id (str): The ID of the job instance
|
751
|
+
Returns:
|
752
|
+
int: The status code of the response
|
753
|
+
"""
|
754
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/jobs/instances/{job_instance_id}/cancel"
|
755
|
+
|
756
|
+
response = self.calling_routine(url=url, operation="POST", response_codes=[202, 429],
|
757
|
+
error_message="Error cancelling job instance", return_format="response",
|
758
|
+
wait_for_completion=False)
|
759
|
+
|
760
|
+
return response.status_code
|
761
|
+
|
762
|
+
|
763
|
+
def get_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
764
|
+
"""Get the job instance of the item
|
765
|
+
Args:
|
766
|
+
workspace_id (str): The ID of the workspace
|
767
|
+
item_id (str): The ID of the item
|
768
|
+
job_instance_id (str): The ID of the job instance
|
769
|
+
Returns:
|
770
|
+
JobInstance: The job instance object
|
771
|
+
"""
|
772
|
+
from msfabricpysdkcore.job_instance import JobInstance
|
773
|
+
|
774
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/jobs/instances/{job_instance_id}"
|
775
|
+
|
776
|
+
job_dict = self.calling_routine(url=url, operation="GET", response_codes=[200, 429],
|
777
|
+
error_message="Error getting job instance", return_format="json")
|
778
|
+
|
779
|
+
job_dict['workspaceId'] = workspace_id
|
780
|
+
job_dict['itemId'] = item_id
|
781
|
+
return JobInstance.from_dict(job_dict, core_client=self)
|
782
|
+
|
783
|
+
|
784
|
+
def run_on_demand_item_job(self, workspace_id, item_id, job_type, execution_data = None):
|
785
|
+
"""Run an on demand job on the item
|
786
|
+
Args:
|
787
|
+
workspace_id (str): The ID of the workspace
|
788
|
+
item_id (str): The ID of the item
|
789
|
+
job_type (str): The type of the job
|
790
|
+
execution_data (dict): The execution data of the job
|
791
|
+
Returns:
|
792
|
+
JobInstance: The job instance object
|
793
|
+
"""
|
794
|
+
|
795
|
+
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items/{itemId}/jobs/instances?jobType={jobType}
|
796
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/jobs/instances?jobType={job_type}"
|
797
|
+
payload = {
|
798
|
+
'executionData': execution_data
|
799
|
+
}
|
800
|
+
|
801
|
+
response = self.calling_routine(url, operation="POST", body=payload, response_codes=[202, 429],
|
802
|
+
error_message="Error running on demand job",
|
803
|
+
wait_for_completion=False, return_format="response")
|
804
|
+
|
805
|
+
job_instance_id = response.headers["Location"].split("/")[-1]
|
806
|
+
job_instance = self.get_item_job_instance(workspace_id, item_id, job_instance_id=job_instance_id)
|
807
|
+
return job_instance
|
808
|
+
|
809
|
+
# long running operations
|
810
|
+
|
811
|
+
def get_operation_results(self, operation_id):
|
812
|
+
"""Get the results of an operation
|
813
|
+
Args:
|
814
|
+
operation_id (str): The ID of the operation
|
815
|
+
Returns:
|
816
|
+
dict: The results of the operation
|
817
|
+
"""
|
818
|
+
url = f"https://api.fabric.microsoft.com/v1/operations/{operation_id}/result"
|
819
|
+
|
820
|
+
response = self.calling_routine(url=url, operation="GET", response_codes=[200, 429],
|
821
|
+
error_message="Error getting operation results", return_format="response",
|
822
|
+
continue_on_error_code=True)
|
823
|
+
if response.status_code == 400:
|
824
|
+
return {"no_operation_result": True}
|
825
|
+
return json.loads(response.text)
|
826
|
+
|
827
|
+
def get_operation_state(self, operation_id):
|
828
|
+
"""Get the state of an operation
|
829
|
+
Args:
|
830
|
+
operation_id (str): The ID of the operation
|
831
|
+
Returns:
|
832
|
+
dict: The state of the operation
|
833
|
+
"""
|
834
|
+
url = f"https://api.fabric.microsoft.com/v1/operations/{operation_id}"
|
835
|
+
|
836
|
+
response_json = self.calling_routine(url=url, operation="GET", response_codes=[200, 429],
|
837
|
+
error_message="Error getting operation state", return_format="json")
|
838
|
+
|
839
|
+
return response_json
|
840
|
+
|
841
|
+
# One Lake Data Access Security
|
842
|
+
|
843
|
+
# create and update
|
844
|
+
|
845
|
+
def create_or_update_data_access_roles(self, workspace_id, item_id, data_access_roles, dryrun = False, etag_match = None):
|
846
|
+
# PUT https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items/{itemId}/dataAccessRoles
|
847
|
+
|
848
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/dataAccessRoles"
|
849
|
+
|
850
|
+
if dryrun:
|
851
|
+
url += "?dryrun=true"
|
852
|
+
|
853
|
+
headers = self.auth.get_headers()
|
854
|
+
if etag_match:
|
855
|
+
if 'If-Match' in etag_match:
|
856
|
+
headers['If-Match'] = etag_match['If-Match']
|
857
|
+
elif 'If-None-Match' in etag_match:
|
858
|
+
headers['If-None-Match'] = etag_match['If-None-Match']
|
859
|
+
else:
|
860
|
+
raise Exception("Etag match should include If-Match or If-None-Match")
|
861
|
+
|
862
|
+
body = {"value" : data_access_roles}
|
863
|
+
|
864
|
+
response = self.calling_routine(url, operation="PUT", body=body, headers=headers,
|
865
|
+
response_codes=[200, 429], error_message="Error creating or updating data access roles", return_format="response")
|
866
|
+
|
867
|
+
return response
|
868
|
+
|
869
|
+
|
870
|
+
# list
|
871
|
+
|
872
|
+
def list_data_access_roles(self, workspace_id, item_id):
|
873
|
+
|
874
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/dataAccessRoles"
|
875
|
+
|
876
|
+
items, etag = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error listing data access roles", return_format="value_json+etag")
|
877
|
+
return items, etag
|
878
|
+
|
879
|
+
# ShortCuts
|
880
|
+
|
881
|
+
def create_shortcut(self, workspace_id, item_id, path, name, target):
|
882
|
+
"""Create a shortcut in the item
|
883
|
+
Args:
|
884
|
+
workspace_id (str): The ID of the workspace
|
885
|
+
item_id (str): The ID of the item
|
886
|
+
path (str): The path of the shortcut
|
887
|
+
name (str): The name of the shortcut
|
888
|
+
target (str): The target of the shortcut
|
889
|
+
Returns:
|
890
|
+
OneLakeShortcut: The created shortcut
|
891
|
+
"""
|
892
|
+
from msfabricpysdkcore.onelakeshortcut import OneLakeShortcut
|
893
|
+
|
894
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/shortcuts"
|
895
|
+
|
896
|
+
body = {'name': name,
|
897
|
+
'path': path,
|
898
|
+
'target': target}
|
899
|
+
|
900
|
+
response_json = self.calling_routine(url, operation="POST", body=body,
|
901
|
+
response_codes=[201, 429], error_message="Error creating shortcut",
|
902
|
+
return_format="json")
|
903
|
+
|
904
|
+
shortcut_dict = response_json
|
905
|
+
shortcut_dict['workspaceId'] = workspace_id
|
906
|
+
shortcut_dict['itemId'] = item_id
|
907
|
+
return OneLakeShortcut.from_dict(shortcut_dict,
|
908
|
+
core_client = self)
|
909
|
+
|
910
|
+
|
911
|
+
def get_shortcut(self, workspace_id, item_id, path, name):
|
912
|
+
"""Get the shortcut in the item
|
913
|
+
Args:
|
914
|
+
workspace_id (str): The ID of the workspace
|
915
|
+
item_id (str): The ID of the item
|
916
|
+
path (str): The path of the shortcut
|
917
|
+
name (str): The name of the shortcut
|
918
|
+
Returns:
|
919
|
+
OneLakeShortcut: The shortcut object
|
920
|
+
"""
|
921
|
+
from msfabricpysdkcore.onelakeshortcut import OneLakeShortcut
|
922
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/shortcuts/{path}/{name}"
|
923
|
+
|
924
|
+
shortcut_dict = self.calling_routine(url=url, operation="GET",
|
925
|
+
response_codes=[200, 429], error_message="Error getting shortcut",
|
926
|
+
return_format="json")
|
927
|
+
|
928
|
+
shortcut_dict['workspaceId'] = workspace_id
|
929
|
+
shortcut_dict['itemId'] = id
|
930
|
+
return OneLakeShortcut.from_dict(shortcut_dict,
|
931
|
+
core_client = self)
|
932
|
+
|
933
|
+
def delete_shortcut(self, workspace_id, item_id, path, name):
|
934
|
+
"""Delete the shortcut
|
935
|
+
Args:
|
936
|
+
workspace_id (str): The ID of the workspace
|
937
|
+
item_id (str): The ID of the item
|
938
|
+
path (str): The path of the shortcut
|
939
|
+
name (str): The name of the shortcut
|
940
|
+
Returns:
|
941
|
+
int: The status code of the response
|
942
|
+
"""
|
943
|
+
|
944
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/items/{item_id}/shortcuts/{path}/{name}"
|
945
|
+
response = self.calling_routine(url=url, operation="DELETE",
|
946
|
+
response_codes=[200, 429], error_message="Error creating shortcut",
|
947
|
+
return_format="response")
|
948
|
+
|
949
|
+
|
950
|
+
return response.status_code
|
951
|
+
|
952
|
+
### Workspaces
|
953
|
+
|
954
|
+
def add_workspace_role_assignment(self, workspace_id, role, principal):
|
955
|
+
"""Add a role assignment to a workspace
|
956
|
+
Args:
|
957
|
+
workspace_id (str): The ID of the workspace
|
958
|
+
role (str): The role to assign
|
959
|
+
principal (str): The principal to assign the role to
|
960
|
+
Returns:
|
961
|
+
int: The status code of the response
|
962
|
+
"""
|
963
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/roleAssignments"
|
964
|
+
|
965
|
+
payload = {
|
966
|
+
'principal': principal,
|
967
|
+
'role': role
|
968
|
+
}
|
969
|
+
|
970
|
+
response = self.calling_routine(url, operation="POST", body=payload, response_codes=[201, 429], error_message="Error adding role assignments", return_format="response")
|
971
|
+
|
972
|
+
return response.status_code
|
973
|
+
|
974
|
+
def assign_to_capacity(self, workspace_id, capacity_id, wait_for_completion=True):
|
975
|
+
"""Assign a workspace to a capacity
|
976
|
+
Args:
|
977
|
+
workspace_id (str): The ID of the workspace
|
978
|
+
capacity_id (str): The ID of the capacity
|
979
|
+
wait_for_completion (bool): Whether to wait for the operation to complete
|
980
|
+
Returns:
|
981
|
+
int: The status code of the response
|
982
|
+
"""
|
983
|
+
|
984
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/assignToCapacity"
|
985
|
+
|
986
|
+
body = {
|
987
|
+
'capacityId': capacity_id
|
988
|
+
}
|
989
|
+
|
990
|
+
response = self.calling_routine(url, operation="POST", body=body, response_codes=[202, 429], error_message="Error assigning capacity", return_format="response", wait_for_completion=wait_for_completion)
|
991
|
+
|
992
|
+
return response.status_code
|
993
|
+
|
994
|
+
def create_workspace(self, display_name, capacity_id = None, description = None, exists_ok = True):
|
995
|
+
"""Create a workspace
|
996
|
+
Args:
|
997
|
+
display_name (str): The display name of the workspace
|
998
|
+
capacity_id (str): The ID of the capacity to assign the workspace to
|
999
|
+
description (str): The description of the workspace
|
1000
|
+
exists_ok (bool): Whether to return the existing workspace if it already exists
|
1001
|
+
Returns:
|
1002
|
+
Workspace: The created workspace
|
1003
|
+
"""
|
1004
|
+
from msfabricpysdkcore.workspace import Workspace
|
1005
|
+
|
1006
|
+
body = dict()
|
1007
|
+
body["displayName"] = display_name
|
1008
|
+
if capacity_id:
|
1009
|
+
body["capacityId"] = capacity_id
|
1010
|
+
if description:
|
1011
|
+
body["description"] = description
|
1012
|
+
|
22
1013
|
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
23
|
-
if continuationToken:
|
24
|
-
url = f"{url}?continuationToken={continuationToken}"
|
25
|
-
|
26
|
-
for _ in range(10):
|
27
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
28
|
-
if response.status_code == 429:
|
29
|
-
print("Too many requests, waiting 10 seconds")
|
30
|
-
sleep(10)
|
31
|
-
continue
|
32
|
-
if response.status_code not in (200, 429):
|
33
|
-
print(response.status_code)
|
34
|
-
print(response.text)
|
35
|
-
raise Exception(f"Error listing workspaces: {response.status_code}, {response.text}")
|
36
|
-
break
|
37
|
-
resp_dict = json.loads(response.text)
|
38
|
-
ws_list = resp_dict["value"]
|
39
|
-
ws_list = [Workspace.from_dict(ws, auth=self.auth) for ws in ws_list]
|
40
|
-
|
41
|
-
if "continuationToken" in resp_dict:
|
42
|
-
ws_list_next = self.list_workspaces(continuationToken=resp_dict["continuationToken"])
|
43
|
-
ws_list.extend(ws_list_next)
|
44
1014
|
|
45
|
-
|
46
|
-
|
1015
|
+
response = self.calling_routine(url, operation="POST", body=body, response_codes=[201, 429], error_message="Error creating workspace", return_format="response", continue_on_error_code=True)
|
1016
|
+
ws_dict = json.loads(response.text)
|
1017
|
+
if response.status_code not in (201, 429):
|
1018
|
+
if "errorCode" in ws_dict and ws_dict["errorCode"] == "WorkspaceNameAlreadyExists" and exists_ok:
|
1019
|
+
return self.get_workspace_by_name(display_name)
|
1020
|
+
else:
|
1021
|
+
raise Exception(f"Error creating workspace: {response.status_code}, {response.text}")
|
1022
|
+
|
1023
|
+
ws = Workspace.from_dict(ws_dict, core_client=self)
|
1024
|
+
return ws
|
1025
|
+
|
1026
|
+
def delete_workspace(self, workspace_id = None, display_name = None):
|
1027
|
+
"""Delete a workspace
|
1028
|
+
Args:
|
1029
|
+
workspace_id (str): The ID of the workspace
|
1030
|
+
display_name (str): The display name of the workspace
|
1031
|
+
Returns:
|
1032
|
+
int: The status code of the response
|
1033
|
+
"""
|
1034
|
+
if workspace_id is None and display_name is None:
|
1035
|
+
raise ValueError("Either workspace_id or display_name must be provided")
|
1036
|
+
if workspace_id is None:
|
1037
|
+
ws = self.get_workspace_by_name(display_name)
|
1038
|
+
workspace_id = ws.id
|
1039
|
+
|
1040
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}"
|
1041
|
+
|
1042
|
+
response = self.calling_routine(url, operation="DELETE", response_codes=[200, 429], error_message="Error deleting workspace", return_format="response")
|
1043
|
+
|
1044
|
+
return response.status_code
|
1045
|
+
|
1046
|
+
def delete_workspace_role_assignment(self, workspace_id, workspace_role_assignment_id):
|
1047
|
+
"""Delete a role assignment from the workspace
|
1048
|
+
Args:
|
1049
|
+
workspace_id (str): The ID of the workspace
|
1050
|
+
workspace_role_assignment_id (str): The ID of the role assignment
|
1051
|
+
Returns:
|
1052
|
+
int: The status code of the response
|
1053
|
+
"""
|
1054
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/roleAssignments/{workspace_role_assignment_id}"
|
1055
|
+
|
1056
|
+
response = self.calling_routine(url, operation="DELETE", response_codes=[200, 429], error_message="Error deleting role assignments", return_format="response")
|
1057
|
+
|
1058
|
+
return response.status_code
|
1059
|
+
|
1060
|
+
def deprovision_identity(self, workspace_id):
|
1061
|
+
"""Deprovision an identity for a workspace
|
1062
|
+
Args:
|
1063
|
+
workspace_id (str): The ID of the workspace
|
1064
|
+
Returns:
|
1065
|
+
requests.Response: The response object
|
1066
|
+
"""
|
1067
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/deprovisionIdentity"
|
1068
|
+
|
1069
|
+
response = self.calling_routine(url, operation="POST", response_codes=[200, 201, 202, 429], error_message="Error deprovisioning identity", return_format="response")
|
1070
|
+
|
1071
|
+
return response
|
1072
|
+
|
1073
|
+
def get_workspace(self, id = None, name = None):
|
1074
|
+
"""Get workspace by id or name
|
1075
|
+
Args:
|
1076
|
+
id (str): The ID of the workspace
|
1077
|
+
name (str): The name of the workspace
|
1078
|
+
Returns:
|
1079
|
+
Workspace: The workspace object
|
1080
|
+
Raises:
|
1081
|
+
ValueError: If neither id nor name is provided
|
1082
|
+
"""
|
1083
|
+
if id:
|
1084
|
+
return self.get_workspace_by_id(id)
|
1085
|
+
if name:
|
1086
|
+
return self.get_workspace_by_name(name)
|
1087
|
+
raise ValueError("Either id or name must be provided")
|
1088
|
+
|
1089
|
+
def get_workspace_by_id(self, id):
|
1090
|
+
"""Get workspace by id
|
1091
|
+
Args:
|
1092
|
+
id (str): The ID of the workspace
|
1093
|
+
Returns:
|
1094
|
+
Workspace: The workspace object
|
1095
|
+
"""
|
1096
|
+
from msfabricpysdkcore.workspace import Workspace
|
1097
|
+
|
1098
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{id}"
|
1099
|
+
|
1100
|
+
ws_dict = self.calling_routine(url, operation="GET", response_codes=[200, 404], error_message="Error getting workspace", return_format="json")
|
1101
|
+
|
1102
|
+
ws = Workspace.from_dict(ws_dict, core_client=self)
|
1103
|
+
|
1104
|
+
return ws
|
1105
|
+
|
47
1106
|
def get_workspace_by_name(self, name):
|
48
|
-
"""Get workspace by name
|
1107
|
+
"""Get workspace by name
|
1108
|
+
Args:
|
1109
|
+
name (str): The name of the workspace
|
1110
|
+
Returns:
|
1111
|
+
Workspace: The workspace object
|
1112
|
+
"""
|
49
1113
|
ws_list = self.list_workspaces()
|
50
1114
|
for ws in ws_list:
|
51
1115
|
if ws.display_name == name:
|
52
1116
|
return ws
|
53
1117
|
|
54
|
-
def
|
55
|
-
"""Get
|
56
|
-
|
1118
|
+
def get_workspace_role_assignment(self, workspace_id, workspace_role_assignment_id):
|
1119
|
+
"""Get a role assignment for a workspace
|
1120
|
+
Args:
|
1121
|
+
workspace_id (str): The ID of the workspace
|
1122
|
+
workspace_role_assignment_id (str): The ID of the role assignment
|
1123
|
+
Returns:
|
1124
|
+
dict: The role assignment
|
1125
|
+
"""
|
1126
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/roleAssignments/{workspace_role_assignment_id}"
|
57
1127
|
|
1128
|
+
return self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting role assignments", return_format="json")
|
1129
|
+
|
1130
|
+
def list_workspace_role_assignments(self, workspace_id):
|
1131
|
+
"""List role assignments for the workspace
|
1132
|
+
Args:
|
1133
|
+
workspace_id (str): The ID of the workspace
|
1134
|
+
Returns:
|
1135
|
+
list: The list of role assignments
|
1136
|
+
"""
|
1137
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/roleAssignments"
|
58
1138
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
sleep(10)
|
64
|
-
continue
|
65
|
-
if response.status_code not in (200, 429):
|
66
|
-
print(response.status_code)
|
67
|
-
print(response.text)
|
68
|
-
raise Exception(f"Error getting workspace: {response.status_code} {response.text}")
|
69
|
-
break
|
70
|
-
ws_dict = json.loads(response.text)
|
71
|
-
ws = Workspace.from_dict(ws_dict, auth=self.auth)
|
1139
|
+
|
1140
|
+
role_assignments = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1141
|
+
error_message="Error listing workspace role assignments", return_format = "value_json",
|
1142
|
+
paging = True)
|
72
1143
|
|
73
|
-
return
|
1144
|
+
return role_assignments
|
1145
|
+
|
1146
|
+
def list_workspaces(self):
|
1147
|
+
"""List all workspaces in the tenant
|
1148
|
+
Returns:
|
1149
|
+
list: The list of workspaces
|
1150
|
+
"""
|
1151
|
+
from msfabricpysdkcore.workspace import Workspace
|
1152
|
+
|
1153
|
+
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
1154
|
+
|
1155
|
+
ws_list = self.calling_routine(url, operation="GET", response_codes=[200], error_message="Error listing workspaces", return_format="value_json", paging=True)
|
1156
|
+
ws_list = [Workspace.from_dict(ws, core_client=self) for ws in ws_list]
|
1157
|
+
|
1158
|
+
return ws_list
|
74
1159
|
|
1160
|
+
def provision_identity(self, workspace_id):
|
1161
|
+
"""Provision an identity for a workspace
|
1162
|
+
Args:
|
1163
|
+
workspace_id (str): The ID of the workspace
|
1164
|
+
Returns:
|
1165
|
+
requests.Response: The response object
|
1166
|
+
"""
|
1167
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/provisionIdentity"
|
1168
|
+
|
1169
|
+
response = self.calling_routine(url, operation="POST", response_codes=[200, 201, 202, 429], error_message="Error provisioning identity", return_format="response")
|
1170
|
+
return response
|
75
1171
|
|
76
|
-
def
|
77
|
-
"""
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
1172
|
+
def unassign_from_capacity(self, workspace_id, wait_for_completion = True):
|
1173
|
+
"""Unassign a workspace from a capacity
|
1174
|
+
Args:
|
1175
|
+
workspace_id (str): The ID of the workspace
|
1176
|
+
wait_for_completion (bool): Whether to wait for the operation to complete
|
1177
|
+
Returns:
|
1178
|
+
int: The status code of the response
|
1179
|
+
"""
|
1180
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/unassignFromCapacity"
|
1181
|
+
|
1182
|
+
response = self.calling_routine(url, operation="POST", response_codes=[202, 429], error_message="Error unassigning capacity", return_format="response", wait_for_completion=wait_for_completion)
|
1183
|
+
|
1184
|
+
return response.status_code
|
1185
|
+
|
83
1186
|
|
84
|
-
def
|
85
|
-
"""
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
1187
|
+
def update_workspace(self, workspace_id, display_name = None, description = None):
|
1188
|
+
"""Update the workspace
|
1189
|
+
Args:
|
1190
|
+
workspace_id (str): The ID of the workspace
|
1191
|
+
display_name (str): The display name of the workspace
|
1192
|
+
description (str): The description of the workspace
|
1193
|
+
Returns:
|
1194
|
+
Workspace: The updated workspace
|
1195
|
+
"""
|
1196
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}"
|
1197
|
+
|
91
1198
|
body = dict()
|
92
|
-
|
93
|
-
|
94
|
-
body["capacityId"] = capacity_id
|
1199
|
+
if display_name:
|
1200
|
+
body["displayName"] = display_name
|
95
1201
|
if description:
|
96
1202
|
body["description"] = description
|
97
|
-
|
98
|
-
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
99
1203
|
|
100
|
-
|
101
|
-
response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
|
102
|
-
if response.status_code == 429:
|
103
|
-
print("Too many requests, waiting 10 seconds")
|
104
|
-
sleep(10)
|
105
|
-
continue
|
106
|
-
ws_dict = json.loads(response.text)
|
107
|
-
if response.status_code not in (201, 429):
|
108
|
-
if "errorCode" in ws_dict and ws_dict["errorCode"] == "WorkspaceNameAlreadyExists" and exists_ok:
|
109
|
-
return self.get_workspace_by_name(display_name)
|
110
|
-
else:
|
111
|
-
print(response.status_code)
|
112
|
-
print(response.text)
|
113
|
-
raise Exception(f"Error creating workspace: {response.text}")
|
114
|
-
break
|
115
|
-
|
116
|
-
ws = Workspace.from_dict(ws_dict, auth=self.auth)
|
117
|
-
return ws
|
118
|
-
|
119
|
-
def delete_workspace(self, workspace_id = None, display_name = None):
|
120
|
-
"""Delete a workspace"""
|
121
|
-
if workspace_id is None and display_name is None:
|
122
|
-
raise ValueError("Either workspace_id or display_name must be provided")
|
123
|
-
ws = self.get_workspace(id = workspace_id, name = display_name)
|
124
|
-
reponse = ws.delete()
|
125
|
-
return reponse
|
126
|
-
|
127
|
-
def add_workspace_role_assignment(self, workspace_id, role, principal):
|
128
|
-
"""Add a role assignment to a workspace"""
|
129
|
-
ws = self.get_workspace_by_id(workspace_id)
|
130
|
-
return ws.add_role_assignment(role, principal)
|
131
|
-
|
132
|
-
def delete_workspace_role_assignment(self, workspace_id, workspace_role_assignment_id):
|
133
|
-
"""Delete a role assignment from a workspace"""
|
134
|
-
ws = self.get_workspace_by_id(workspace_id)
|
135
|
-
return ws.delete_role_assignment(workspace_role_assignment_id)
|
136
|
-
|
137
|
-
def update_workspace(self, workspace_id, display_name = None, description = None):
|
138
|
-
"""Update a workspace"""
|
139
|
-
ws = self.get_workspace_by_id(workspace_id)
|
140
|
-
return ws.update(display_name, description)
|
1204
|
+
response = self.calling_routine(url, operation="PATCH", body=body, response_codes=[200, 429], error_message="Error updating workspace", return_format="response")
|
141
1205
|
|
142
|
-
|
143
|
-
"""Get a role assignment for a workspace"""
|
144
|
-
ws = self.get_workspace_by_id(workspace_id)
|
145
|
-
return ws.get_role_assignment(workspace_role_assignment_id)
|
146
|
-
|
147
|
-
def update_workspace_role_assignment(self, workspace_id, role, workspace_role_assignment_id):
|
148
|
-
"""Update a role assignment for a workspace"""
|
149
|
-
ws = self.get_workspace_by_id(workspace_id)
|
150
|
-
return ws.update_role_assignment(role, workspace_role_assignment_id)
|
1206
|
+
assert response.status_code == 200
|
151
1207
|
|
152
|
-
|
153
|
-
"""Assign a workspace to a capacity"""
|
154
|
-
ws = self.get_workspace_by_id(workspace_id)
|
155
|
-
return ws.assign_to_capacity(capacity_id)
|
156
|
-
|
157
|
-
def unassign_from_capacity(self, workspace_id):
|
158
|
-
"""Unassign a workspace from a capacity"""
|
159
|
-
ws = self.get_workspace_by_id(workspace_id)
|
160
|
-
return ws.unassign_from_capacity()
|
161
|
-
|
162
|
-
def provision_identity(self, workspace_id):
|
163
|
-
"""Provision an identity for a workspace"""
|
164
|
-
ws = self.get_workspace_by_id(workspace_id)
|
165
|
-
return ws.provision_identity()
|
166
|
-
|
167
|
-
def deprovision_identity(self, workspace_id):
|
168
|
-
"""Deprovision an identity for a workspace"""
|
169
|
-
ws = self.get_workspace_by_id(workspace_id)
|
170
|
-
return ws.deprovision_identity()
|
171
|
-
|
172
|
-
def list_capacities(self, continuationToken = None):
|
173
|
-
"""List all capacities in the tenant"""
|
174
|
-
url = "https://api.fabric.microsoft.com/v1/capacities"
|
1208
|
+
return self.get_workspace_by_id(workspace_id)
|
175
1209
|
|
176
|
-
if continuationToken:
|
177
|
-
url = f"{url}?continuationToken={continuationToken}"
|
178
|
-
|
179
|
-
for _ in range(10):
|
180
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
181
|
-
if response.status_code == 429:
|
182
|
-
print("Too many requests, waiting 10 seconds")
|
183
|
-
sleep(10)
|
184
|
-
continue
|
185
|
-
if response.status_code not in (200, 429):
|
186
|
-
print(response.status_code)
|
187
|
-
print(response.text)
|
188
|
-
raise Exception(f"Error listing capacities: {response.text}")
|
189
|
-
break
|
190
|
-
|
191
|
-
resp_dict = json.loads(response.text)
|
192
|
-
items = resp_dict["value"]
|
193
|
-
|
194
|
-
if "continuationToken" in resp_dict:
|
195
|
-
cap_list_next = self.list_capacities(continuationToken=resp_dict["continuationToken"])
|
196
|
-
items.extend(cap_list_next)
|
197
|
-
|
198
|
-
items = json.loads(response.text)["value"]
|
199
|
-
items = [Capacity.from_dict(i) for i in items]
|
200
|
-
return items
|
201
1210
|
|
202
|
-
|
203
|
-
|
204
|
-
"""Create an item in a workspace"""
|
205
|
-
ws = self.get_workspace_by_id(workspace_id)
|
206
|
-
|
207
|
-
return ws.create_item(display_name = display_name,
|
208
|
-
type = type,
|
209
|
-
definition = definition,
|
210
|
-
description = description)
|
211
|
-
|
212
|
-
def get_item(self, workspace_id = None,
|
213
|
-
item_id = None, workspace_name = None, item_name = None, item_type = None):
|
214
|
-
"""Get an item from a workspace"""
|
215
|
-
ws = self.get_workspace(id = workspace_id, name = workspace_name)
|
216
|
-
return ws.get_item(item_id = item_id, item_name = item_name, item_type = item_type)
|
217
|
-
|
218
|
-
def delete_item(self, workspace_id, item_id):
|
219
|
-
"""Delete an item from a workspace"""
|
220
|
-
ws = self.get_workspace_by_id(workspace_id)
|
221
|
-
return ws.delete_item(item_id)
|
222
|
-
|
223
|
-
def list_items(self, workspace_id, with_properties = False):
|
224
|
-
"""List items in a workspace"""
|
225
|
-
ws = self.get_workspace_by_id(workspace_id)
|
226
|
-
return ws.list_items(with_properties=with_properties)
|
227
|
-
|
228
|
-
def get_item_definition(self, workspace_id, item_id):
|
229
|
-
"""Get the definition of an item"""
|
230
|
-
ws = self.get_workspace_by_id(workspace_id)
|
231
|
-
return ws.get_item_definition(item_id)
|
232
|
-
|
233
|
-
def update_item(self, workspace_id, item_id, display_name = None, description = None):
|
234
|
-
"""Update an item in a workspace"""
|
235
|
-
ws = self.get_workspace_by_id(workspace_id)
|
236
|
-
return ws.get_item(item_id).update(display_name, description)
|
237
|
-
|
238
|
-
def update_item_definition(self, workspace_id, item_id, definition):
|
239
|
-
"""Update the definition of an item"""
|
240
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
241
|
-
return ws.get_item(item_id=item_id).update_definition(definition=definition)
|
242
|
-
|
243
|
-
def create_shortcut(self, workspace_id, item_id, path, name, target):
|
244
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
245
|
-
return ws.get_item(item_id=item_id).create_shortcut(path=path, name=name, target=target)
|
246
|
-
|
247
|
-
def get_shortcut(self, workspace_id, item_id, path, name):
|
248
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
249
|
-
return ws.get_item(item_id=item_id).get_shortcut(path=path, name=name)
|
250
|
-
|
251
|
-
def delete_shortcut(self, workspace_id, item_id, path, name):
|
252
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
253
|
-
return ws.get_item(item_id=item_id).delete_shortcut(path=path, name=name)
|
254
|
-
|
255
|
-
def get_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
256
|
-
"""Get a job instance for an item"""
|
257
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
258
|
-
return ws.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id)
|
259
|
-
|
260
|
-
def run_on_demand_item_job(self, workspace_id, item_id, job_type, execution_data = None):
|
261
|
-
"""Run an on demand job for an item"""
|
262
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
263
|
-
return ws.get_item(item_id=item_id).run_on_demand_item_job(job_type=job_type, execution_data=execution_data)
|
264
|
-
|
265
|
-
def cancel_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
266
|
-
"""Cancel a job instance for an item"""
|
267
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
268
|
-
return ws.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id).cancel()
|
269
|
-
|
270
|
-
def commit_to_git(self, workspace_id,mode, comment=None, items=None, workspace_head=None):
|
271
|
-
"""Commit changes to git"""
|
272
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
273
|
-
return ws.commit_to_git(mode=mode, comment=comment, items=items, workspace_head=workspace_head)
|
274
|
-
|
275
|
-
def git_connect(self, workspace_id, git_provider_details):
|
276
|
-
"""Connect to git"""
|
277
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
278
|
-
return ws.git_connect(git_provider_details=git_provider_details)
|
279
|
-
|
280
|
-
def git_disconnect(self, workspace_id):
|
281
|
-
"""Disconnect from git"""
|
282
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
283
|
-
return ws.git_disconnect()
|
284
|
-
|
285
|
-
def git_get_connection(self, workspace_id):
|
286
|
-
"""Get git connection details"""
|
287
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
288
|
-
return ws.git_get_connection()
|
289
|
-
|
290
|
-
def git_get_status(self, workspace_id):
|
291
|
-
"""Get git status"""
|
292
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
293
|
-
return ws.git_get_status()
|
294
|
-
|
295
|
-
def git_initialize_connection(self, workspace_id, initialization_strategy):
|
296
|
-
"""Initialize git"""
|
297
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
298
|
-
return ws.git_initialize_connection(initialization_strategy=initialization_strategy)
|
299
|
-
|
300
|
-
def update_from_git(self, workspace_id, remote_commit_hash, conflict_resolution = None, options = None, workspace_head = None):
|
301
|
-
"""Update workspace from git"""
|
302
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
303
|
-
return ws.update_from_git(remote_commit_hash=remote_commit_hash,
|
304
|
-
conflict_resolution=conflict_resolution,
|
305
|
-
options=options,
|
306
|
-
workspace_head=workspace_head)
|
307
|
-
|
308
|
-
def get_capacity(self, capacity_id = None, capacity_name = None):
|
309
|
-
"""Get a capacity
|
310
|
-
|
1211
|
+
def update_workspace_role_assignment(self, workspace_id, role, workspace_role_assignment_id):
|
1212
|
+
"""Update a role assignment for a workspace
|
311
1213
|
Args:
|
312
|
-
|
313
|
-
|
314
|
-
|
1214
|
+
workspace_id (str): The ID of the workspace
|
1215
|
+
role (str): The role to assign
|
1216
|
+
workspace_role_assignment_id (str): The ID of the role assignment
|
315
1217
|
Returns:
|
316
|
-
|
317
|
-
|
318
|
-
Raises:
|
319
|
-
ValueError: If no capacity is found
|
1218
|
+
int: The status code of the response
|
320
1219
|
"""
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
if capacity_id and cap.id == capacity_id:
|
326
|
-
return cap
|
327
|
-
if capacity_name and cap.display_name == capacity_name:
|
328
|
-
return cap
|
329
|
-
raise ValueError("No capacity found")
|
330
|
-
|
1220
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/roleAssignments/{workspace_role_assignment_id}"
|
1221
|
+
body = {
|
1222
|
+
'role': role
|
1223
|
+
}
|
331
1224
|
|
332
|
-
|
1225
|
+
response = self.calling_routine(url, operation="PATCH", body=body, response_codes=[200, 429], error_message="Error updating role assignments", return_format="response")
|
333
1226
|
|
334
|
-
|
335
|
-
"""Get the results of an operation"""
|
336
|
-
lro = LongRunningOperation(operation_id=operation_id, auth=self.auth)
|
337
|
-
return lro.get_operation_results()
|
1227
|
+
return response.status_code
|
338
1228
|
|
339
|
-
def get_operation_state(self, operation_id):
|
340
|
-
"""Get the state of an operation"""
|
341
|
-
lro = LongRunningOperation(operation_id=operation_id, auth=self.auth)
|
342
|
-
return lro.get_operation_state()
|
343
1229
|
|
1230
|
+
|
344
1231
|
# list things
|
345
|
-
|
346
1232
|
def list_dashboards(self, workspace_id):
|
347
|
-
|
348
|
-
return
|
1233
|
+
"""List dashboards in a workspace"""
|
1234
|
+
return self.list_items(workspace_id, type="dashboards")
|
349
1235
|
|
350
1236
|
def list_datamarts(self, workspace_id):
|
351
|
-
|
352
|
-
return
|
1237
|
+
"""List datamarts in a workspace"""
|
1238
|
+
return self.list_items(workspace_id, type="datamarts")
|
353
1239
|
|
354
1240
|
def list_paginated_reports(self, workspace_id):
|
355
|
-
|
356
|
-
return
|
357
|
-
|
1241
|
+
"""List paginated reports in a workspace"""
|
1242
|
+
return self.list_items(workspace_id, type="paginatedReports")
|
1243
|
+
|
358
1244
|
def list_sql_endpoints(self, workspace_id):
|
359
|
-
|
360
|
-
return
|
361
|
-
|
1245
|
+
"""List sql endpoints in a workspace"""
|
1246
|
+
return self.list_items(workspace_id, type="sqlEndpoints")
|
1247
|
+
|
362
1248
|
def list_mirrored_warehouses(self, workspace_id):
|
363
|
-
|
364
|
-
return
|
1249
|
+
"""List mirrored warehouses in a workspace"""
|
1250
|
+
return self.list_items(workspace_id, type="mirroredWarehouses")
|
365
1251
|
|
366
1252
|
# dataPipelines
|
367
1253
|
|
368
|
-
def create_data_pipeline(self, workspace_id, display_name, description = None):
|
1254
|
+
def create_data_pipeline(self, workspace_id, display_name, definition = None, description = None):
|
369
1255
|
"""Create a data pipeline in a workspace"""
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
ws = self.get_workspace_by_id(workspace_id)
|
376
|
-
return ws.list_data_pipelines(with_properties = with_properties)
|
377
|
-
|
378
|
-
def get_data_pipeline(self, workspace_id, data_pipeline_id = None, data_pipeline_name = None):
|
379
|
-
"""Get a data pipeline from a workspace"""
|
380
|
-
ws = self.get_workspace_by_id(workspace_id)
|
381
|
-
return ws.get_data_pipeline(data_pipeline_id = data_pipeline_id, data_pipeline_name = data_pipeline_name)
|
1256
|
+
return self.create_item(workspace_id=workspace_id,
|
1257
|
+
display_name = display_name,
|
1258
|
+
type = "dataPipelines",
|
1259
|
+
definition = definition,
|
1260
|
+
description = description)
|
382
1261
|
|
383
1262
|
def delete_data_pipeline(self, workspace_id, data_pipeline_id):
|
384
|
-
"""Delete a data pipeline from a workspace
|
385
|
-
|
386
|
-
|
1263
|
+
"""Delete a data pipeline from a workspace
|
1264
|
+
Args:
|
1265
|
+
workspace_id (str): The ID of the workspace
|
1266
|
+
data_pipeline_id (str): The ID of the data pipeline
|
1267
|
+
Returns:
|
1268
|
+
int: The status code of the response
|
1269
|
+
"""
|
1270
|
+
return self.delete_item(workspace_id, item_id=data_pipeline_id, type="dataPipelines")
|
1271
|
+
|
1272
|
+
def get_data_pipeline(self, workspace_id, data_pipeline_id = None, data_pipeline_name = None):
|
1273
|
+
"""Get a data pipeline from a workspace
|
1274
|
+
Args:
|
1275
|
+
workspace_id (str): The ID of the workspace
|
1276
|
+
data_pipeline_id (str): The ID of the data pipeline
|
1277
|
+
data_pipeline_name (str): The name of the data pipeline
|
1278
|
+
Returns:
|
1279
|
+
DataPipeline: The data pipeline object
|
1280
|
+
"""
|
1281
|
+
from msfabricpysdkcore.otheritems import DataPipeline
|
1282
|
+
|
1283
|
+
if data_pipeline_id is None and data_pipeline_name is not None:
|
1284
|
+
data_pipelines = self.list_data_pipelines(workspace_id)
|
1285
|
+
dps = [dp for dp in data_pipelines if dp.display_name == data_pipeline_name]
|
1286
|
+
if len(dps) == 0:
|
1287
|
+
raise Exception(f"Data pipeline with name {data_pipeline_name} not found")
|
1288
|
+
data_pipeline_id = dps[0].id
|
1289
|
+
elif data_pipeline_id is None:
|
1290
|
+
raise Exception("data_pipeline_id or the data_pipeline_name is required")
|
1291
|
+
|
1292
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/dataPipelines/{data_pipeline_id}"
|
1293
|
+
|
1294
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1295
|
+
error_message="Error getting data pipeline", return_format="json")
|
387
1296
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
1297
|
+
dp = DataPipeline.from_dict(item_dict, core_client=self)
|
1298
|
+
dp.get_definition()
|
1299
|
+
return dp
|
1300
|
+
|
1301
|
+
def list_data_pipelines(self, workspace_id, with_properties = False):
|
1302
|
+
"""List data pipelines in a workspace
|
1303
|
+
Args:
|
1304
|
+
workspace_id (str): The ID of the workspace
|
1305
|
+
with_properties (bool): Whether to get the item object with properties
|
1306
|
+
Returns:
|
1307
|
+
list: The list of data pipelines
|
1308
|
+
"""
|
1309
|
+
return self.list_items(workspace_id, type="dataPipelines", with_properties=with_properties)
|
1310
|
+
|
1311
|
+
def update_data_pipeline(self, workspace_id, data_pipeline_id, display_name = None, description = None, return_item="Default"):
|
1312
|
+
"""Update a data pipeline in a workspace
|
1313
|
+
Args:
|
1314
|
+
workspace_id (str): The ID of the workspace
|
1315
|
+
data_pipeline_id (str): The ID of the data pipeline
|
1316
|
+
display_name (str): The display name of the data pipeline
|
1317
|
+
description (str): The description of the data pipeline
|
1318
|
+
Returns:
|
1319
|
+
dict: The updated data pipeline
|
1320
|
+
"""
|
1321
|
+
return self.update_item(workspace_id, item_id=data_pipeline_id, display_name=display_name, description=description, type="dataPipelines",
|
1322
|
+
return_item=return_item)
|
1323
|
+
|
392
1324
|
|
393
1325
|
# environments
|
394
1326
|
|
395
|
-
def list_environments(self, workspace_id, with_properties = False):
|
396
|
-
"""List environments in a workspace"""
|
397
|
-
ws = self.get_workspace_by_id(workspace_id)
|
398
|
-
return ws.list_environments(with_properties = with_properties)
|
399
|
-
|
400
1327
|
def create_environment(self, workspace_id, display_name, description = None):
|
401
|
-
"""Create an environment in a workspace
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
1328
|
+
"""Create an environment in a workspace
|
1329
|
+
Args:
|
1330
|
+
workspace_id (str): The ID of the workspace
|
1331
|
+
display_name (str): The display name of the environment
|
1332
|
+
description (str): The description of the environment
|
1333
|
+
Returns:
|
1334
|
+
dict: The created environment
|
1335
|
+
"""
|
1336
|
+
return self.create_item(workspace_id=workspace_id,
|
1337
|
+
display_name = display_name,
|
1338
|
+
type = "environments",
|
1339
|
+
definition = None,
|
1340
|
+
description = description)
|
409
1341
|
|
410
1342
|
def delete_environment(self, workspace_id, environment_id):
|
411
|
-
"""Delete an environment from a workspace
|
412
|
-
|
413
|
-
|
1343
|
+
"""Delete an environment from a workspace
|
1344
|
+
Args:
|
1345
|
+
workspace_id (str): The ID of the workspace
|
1346
|
+
environment_id (str): The ID of the environment
|
1347
|
+
Returns:
|
1348
|
+
int: The status code of the response
|
1349
|
+
"""
|
1350
|
+
return self.delete_item(workspace_id, item_id=environment_id, type="environments")
|
414
1351
|
|
415
|
-
def
|
416
|
-
"""
|
417
|
-
|
418
|
-
|
1352
|
+
def get_environment(self, workspace_id, environment_id = None, environment_name = None):
|
1353
|
+
"""Get an environment from a workspace
|
1354
|
+
Args:
|
1355
|
+
workspace_id (str): The ID of the workspace
|
1356
|
+
environment_id (str): The ID of the environment
|
1357
|
+
environment_name (str): The name of the environment
|
1358
|
+
Returns:
|
1359
|
+
dict: The environment
|
1360
|
+
"""
|
1361
|
+
from msfabricpysdkcore.environment import Environment
|
1362
|
+
if environment_id is None and environment_name is not None:
|
1363
|
+
envs = self.list_environments(workspace_id)
|
1364
|
+
envs = [env for env in envs if env.display_name == environment_name]
|
1365
|
+
if len(envs) == 0:
|
1366
|
+
raise Exception(f"Environment with name {environment_name} not found")
|
1367
|
+
environment_id = envs[0].id
|
1368
|
+
elif environment_id is None:
|
1369
|
+
raise Exception("environment_id or the environment_name is required")
|
1370
|
+
|
1371
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}"
|
1372
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1373
|
+
error_message="Error getting environment", return_format="json")
|
1374
|
+
env = Environment.from_dict(item_dict, core_client=self)
|
1375
|
+
return env
|
1376
|
+
|
1377
|
+
def list_environments(self, workspace_id, with_properties = False):
|
1378
|
+
"""List environments in a workspace
|
1379
|
+
Args:
|
1380
|
+
workspace_id (str): The ID of the workspace
|
1381
|
+
with_properties (bool): Whether to get the item object with properties
|
1382
|
+
Returns:
|
1383
|
+
list: The list of environments
|
1384
|
+
"""
|
1385
|
+
return self.list_items(workspace_id, type="environments", with_properties=with_properties)
|
419
1386
|
|
1387
|
+
def update_environment(self, workspace_id, environment_id, display_name = None, description = None, return_item="Default"):
|
1388
|
+
"""Update an environment in a workspace
|
1389
|
+
Args:
|
1390
|
+
workspace_id (str): The ID of the workspace
|
1391
|
+
environment_id (str): The ID of the environment
|
1392
|
+
display_name (str): The display name of the environment
|
1393
|
+
description (str): The description of the environment
|
1394
|
+
Returns:
|
1395
|
+
dict: The updated environment
|
1396
|
+
"""
|
1397
|
+
return self.update_item(workspace_id, item_id=environment_id, display_name=display_name, description=description,
|
1398
|
+
type="environments", return_item=return_item)
|
1399
|
+
|
420
1400
|
# environmentSparkCompute
|
421
1401
|
|
422
1402
|
def get_published_settings(self, workspace_id, environment_id):
|
423
|
-
"""Get published settings
|
424
|
-
|
425
|
-
|
426
|
-
|
1403
|
+
"""Get the published settings of the environment
|
1404
|
+
Args:
|
1405
|
+
workspace_id (str): The ID of the workspace
|
1406
|
+
environment_id (str): The ID of the environment
|
1407
|
+
Returns:
|
1408
|
+
dict: The published settings
|
1409
|
+
"""
|
1410
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/sparkcompute"
|
1411
|
+
|
1412
|
+
resp_json = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting published settings", return_format="json")
|
1413
|
+
return resp_json
|
1414
|
+
|
427
1415
|
def get_staging_settings(self, workspace_id, environment_id):
|
428
|
-
"""Get staging settings
|
429
|
-
|
430
|
-
|
1416
|
+
"""Get the staging settings of the environment
|
1417
|
+
Args:
|
1418
|
+
workspace_id (str): The ID of the workspace
|
1419
|
+
environment_id (str): The ID of the environment
|
1420
|
+
Returns:
|
1421
|
+
dict: The staging settings
|
1422
|
+
"""
|
1423
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/sparkcompute"
|
1424
|
+
|
1425
|
+
resp_json = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting staging settings", return_format="json")
|
1426
|
+
return resp_json
|
431
1427
|
|
432
1428
|
def update_staging_settings(self, workspace_id, environment_id,
|
433
1429
|
driver_cores = None, driver_memory = None, dynamic_executor_allocation = None,
|
434
1430
|
executor_cores = None, executor_memory = None, instance_pool = None,
|
435
1431
|
runtime_version = None, spark_properties = None):
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
1432
|
+
"""Update the staging settings of the environment
|
1433
|
+
Args:
|
1434
|
+
workspace_id (str): The ID of the workspace
|
1435
|
+
environment_id (str): The ID of the environment
|
1436
|
+
driver_cores (int): The number of driver cores
|
1437
|
+
driver_memory (str): The memory for the driver
|
1438
|
+
dynamic_executor_allocation (bool): Whether to dynamically allocate executors
|
1439
|
+
executor_cores (int): The number of executor cores
|
1440
|
+
executor_memory (str): The memory for the executor
|
1441
|
+
instance_pool (str): The instance pool
|
1442
|
+
runtime_version (str): The runtime version
|
1443
|
+
spark_properties (dict): The spark properties
|
1444
|
+
Returns:
|
1445
|
+
dict: The updated staging settings
|
1446
|
+
"""
|
1447
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/sparkcompute"
|
1448
|
+
body = {}
|
1449
|
+
if driver_cores is not None:
|
1450
|
+
body['driverCores'] = driver_cores
|
1451
|
+
if driver_memory is not None:
|
1452
|
+
body['driverMemory'] = driver_memory
|
1453
|
+
if dynamic_executor_allocation is not None:
|
1454
|
+
body['dynamicExecutorAllocation'] = dynamic_executor_allocation
|
1455
|
+
if executor_cores is not None:
|
1456
|
+
body['executorCores'] = executor_cores
|
1457
|
+
if executor_memory is not None:
|
1458
|
+
body['executorMemory'] = executor_memory
|
1459
|
+
if instance_pool is not None:
|
1460
|
+
body['instancePool'] = instance_pool
|
1461
|
+
if runtime_version is not None:
|
1462
|
+
body['runtimeVersion'] = runtime_version
|
1463
|
+
if spark_properties is not None:
|
1464
|
+
body['sparkProperties'] = spark_properties
|
1465
|
+
|
1466
|
+
respone_json = self.calling_routine(url, operation="PATCH", body=body, response_codes=[200, 429],
|
1467
|
+
error_message="Error updating staging settings", return_format="json")
|
1468
|
+
|
1469
|
+
return respone_json
|
1470
|
+
|
1471
|
+
|
1472
|
+
# environmentSparkLibraries
|
1473
|
+
|
1474
|
+
def cancel_publish(self, workspace_id, environment_id):
|
1475
|
+
"""Cancel the publishing of the staging settings and libraries of the environment
|
1476
|
+
Args:
|
1477
|
+
workspace_id (str): The ID of the workspace
|
1478
|
+
environment_id (str): The ID of the environment
|
1479
|
+
Returns:
|
1480
|
+
dict: The operation result or response value
|
1481
|
+
"""
|
1482
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/cancelPublish"
|
1483
|
+
|
1484
|
+
resp_dict = self.calling_routine(url, operation="POST", response_codes=[200, 429], error_message="Error canceling publish", return_format="json")
|
1485
|
+
return resp_dict
|
1486
|
+
|
1487
|
+
def delete_staging_library(self, workspace_id, environment_id, library_to_delete):
|
1488
|
+
"""Delete a library from the staging libraries of the environment
|
1489
|
+
Args:
|
1490
|
+
workspace_id (str): The ID of the workspace
|
1491
|
+
environment_id (str): The ID of the environment
|
1492
|
+
library_to_delete (str): The library to delete
|
1493
|
+
Returns:
|
1494
|
+
requests.Response: The response object
|
1495
|
+
"""
|
1496
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries?libraryToDelete={library_to_delete}"
|
1497
|
+
|
1498
|
+
response = self.calling_routine(url, operation="DELETE", response_codes=[200, 429], error_message="Error deleting staging library", return_format="response")
|
1499
|
+
|
1500
|
+
return response
|
1501
|
+
|
1502
|
+
def get_published_libraries(self, workspace_id, environment_id):
|
1503
|
+
"""Get the published libraries of the environment
|
1504
|
+
Args:
|
1505
|
+
workspace_id (str): The ID of the workspace
|
1506
|
+
environment_id (str): The ID of the environment
|
1507
|
+
Returns:
|
1508
|
+
dict: The published libraries
|
1509
|
+
"""
|
1510
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/libraries"
|
1511
|
+
|
1512
|
+
resp_json = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting published libraries", return_format="json")
|
1513
|
+
return resp_json
|
1514
|
+
|
1515
|
+
def get_staging_libraries(self, workspace_id, environment_id):
|
1516
|
+
"""Get the staging libraries of the environment
|
1517
|
+
Args:
|
1518
|
+
workspace_id (str): The ID of the workspace
|
1519
|
+
environment_id (str): The ID of the environment
|
1520
|
+
Returns:
|
1521
|
+
dict: The staging libraries
|
1522
|
+
"""
|
1523
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries"
|
1524
|
+
|
1525
|
+
resp_json = self.calling_routine(url, operation="GET", response_codes=[200, 429], error_message="Error getting staging libraries", return_format="json")
|
1526
|
+
return resp_json
|
1527
|
+
|
1528
|
+
def publish_environment(self, workspace_id, environment_id):
|
1529
|
+
"""Publish the staging settings and libraries of the environment
|
1530
|
+
Args:
|
1531
|
+
workspace_id (str): The ID of the workspace
|
1532
|
+
environment_id (str): The ID of the environment
|
1533
|
+
Returns:
|
1534
|
+
dict: The operation result or response value
|
1535
|
+
"""
|
1536
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/publish"
|
445
1537
|
|
446
|
-
|
447
|
-
|
1538
|
+
resp_dict = self.calling_routine(url, operation="POST", response_codes=[200, 429], error_message="Error publishing staging",
|
1539
|
+
return_format="json+operation_result")
|
448
1540
|
|
449
|
-
|
450
|
-
"""Get published libraries for an environment"""
|
451
|
-
ws = self.get_workspace_by_id(workspace_id)
|
452
|
-
return ws.get_environment(environment_id).get_published_libraries()
|
453
|
-
|
454
|
-
def get_staging_libraries(self, workspace_id, environment_id):
|
455
|
-
"""Get staging libraries for an environment"""
|
456
|
-
ws = self.get_workspace_by_id(workspace_id)
|
457
|
-
return ws.get_environment(environment_id).get_staging_libraries()
|
1541
|
+
return resp_dict
|
458
1542
|
|
459
1543
|
def upload_staging_library(self, workspace_id, environment_id, file_path):
|
460
|
-
"""Update staging libraries for an environment
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
return ws.get_environment(environment_id).delete_staging_library(library_to_delete)
|
1544
|
+
"""Update staging libraries for an environment
|
1545
|
+
Args:
|
1546
|
+
workspace_id (str): The ID of the workspace
|
1547
|
+
environment_id (str): The ID of the environment
|
1548
|
+
file_path (str): The file path to upload
|
1549
|
+
Returns:
|
1550
|
+
requests.Response: The response object
|
1551
|
+
"""
|
1552
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries"
|
1553
|
+
response = self.calling_routine(url, operation="POST", file_path=file_path, response_codes=[200, 429],
|
1554
|
+
error_message="Error uploading staging library", return_format="response")
|
1555
|
+
return response
|
473
1556
|
|
474
|
-
def cancel_publish(self, workspace_id, environment_id):
|
475
|
-
"""Cancel publishing an environment"""
|
476
|
-
ws = self.get_workspace_by_id(workspace_id)
|
477
|
-
return ws.get_environment(environment_id).cancel_publish()
|
478
1557
|
|
1558
|
+
|
479
1559
|
# eventhouses
|
480
1560
|
|
481
|
-
def list_eventhouses(self, workspace_id):
|
482
|
-
"""List eventhouses in a workspace"""
|
483
|
-
ws = self.get_workspace_by_id(workspace_id)
|
484
|
-
return ws.list_eventhouses()
|
485
|
-
|
486
1561
|
def create_eventhouse(self, workspace_id, display_name, description = None):
|
487
|
-
"""Create an eventhouse in a workspace
|
488
|
-
|
489
|
-
|
1562
|
+
"""Create an eventhouse in a workspace
|
1563
|
+
Args:
|
1564
|
+
workspace_id (str): The ID of the workspace
|
1565
|
+
display_name (str): The display name of the eventhouse
|
1566
|
+
description (str): The description of the eventhouse
|
1567
|
+
Returns:
|
1568
|
+
Eventhouse: The created eventhouse
|
1569
|
+
"""
|
1570
|
+
return self.create_item(workspace_id=workspace_id,
|
1571
|
+
display_name = display_name,
|
1572
|
+
type = "eventhouses",
|
1573
|
+
definition = None,
|
1574
|
+
description = description)
|
1575
|
+
|
1576
|
+
def delete_eventhouse(self, workspace_id, eventhouse_id):
|
1577
|
+
"""Delete an eventhouse from a workspace
|
1578
|
+
Args:
|
1579
|
+
workspace_id (str): The ID of the workspace
|
1580
|
+
eventhouse_id (str): The ID of the eventhouse
|
1581
|
+
Returns:
|
1582
|
+
int: The status code of the response
|
1583
|
+
"""
|
1584
|
+
return self.delete_item(workspace_id, eventhouse_id, type="eventhouses")
|
490
1585
|
|
491
1586
|
def get_eventhouse(self, workspace_id, eventhouse_id = None, eventhouse_name = None):
|
492
|
-
"""Get an eventhouse from a workspace
|
493
|
-
|
494
|
-
|
1587
|
+
"""Get an eventhouse from a workspace
|
1588
|
+
Args:
|
1589
|
+
workspace_id (str): The ID of the workspace
|
1590
|
+
eventhouse_id (str): The ID of the eventhouse
|
1591
|
+
eventhouse_name (str): The name of the eventhouse
|
1592
|
+
Returns:
|
1593
|
+
Eventhouse: The eventhouse object
|
1594
|
+
"""
|
1595
|
+
from msfabricpysdkcore.otheritems import Eventhouse
|
1596
|
+
if eventhouse_id is None and eventhouse_name is not None:
|
1597
|
+
ehs = self.list_eventhouses(workspace_id)
|
1598
|
+
ehs = [eh for eh in ehs if eh.display_name == eventhouse_name]
|
1599
|
+
if len(ehs) == 0:
|
1600
|
+
raise Exception(f"Eventhouse with name {eventhouse_name} not found")
|
1601
|
+
eventhouse_id = ehs[0].id
|
1602
|
+
if eventhouse_id is None:
|
1603
|
+
raise Exception("eventhouse_id or the eventhouse_name is required")
|
1604
|
+
|
1605
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/eventhouses/{eventhouse_id}"
|
1606
|
+
|
1607
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1608
|
+
error_message="Error getting eventhouse", return_format="json")
|
1609
|
+
return Eventhouse.from_dict(item_dict, core_client=self)
|
495
1610
|
|
496
|
-
def
|
497
|
-
"""
|
498
|
-
|
499
|
-
|
1611
|
+
def list_eventhouses(self, workspace_id, with_properties = False):
|
1612
|
+
"""List eventhouses in a workspace
|
1613
|
+
Args:
|
1614
|
+
workspace_id (str): The ID of the workspace
|
1615
|
+
with_properties (bool): Whether to get the item object with properties
|
1616
|
+
Returns:
|
1617
|
+
list: The list of eventhouses
|
1618
|
+
"""
|
1619
|
+
return self.list_items(workspace_id=workspace_id, type="eventhouses", with_properties=with_properties)
|
500
1620
|
|
501
|
-
def update_eventhouse(self, workspace_id, eventhouse_id, display_name = None, description = None):
|
502
|
-
"""Update an eventhouse in a workspace
|
503
|
-
|
504
|
-
|
1621
|
+
def update_eventhouse(self, workspace_id, eventhouse_id, display_name = None, description = None, return_item="Default"):
|
1622
|
+
"""Update an eventhouse in a workspace
|
1623
|
+
Args:
|
1624
|
+
workspace_id (str): The ID of the workspace
|
1625
|
+
eventhouse_id (str): The ID of the eventhouse
|
1626
|
+
display_name (str): The display name of the eventhouse
|
1627
|
+
description (str): The description of the eventhouse
|
1628
|
+
Returns:
|
1629
|
+
dict: The updated eventhouse
|
1630
|
+
"""
|
1631
|
+
return self.update_item(workspace_id=workspace_id, item_id=eventhouse_id,
|
1632
|
+
display_name=display_name, description=description, type="eventhouses", return_item=return_item)
|
505
1633
|
|
506
1634
|
# eventstreams
|
507
1635
|
|
508
|
-
def list_eventstreams(self, workspace_id):
|
509
|
-
"""List eventstreams in a workspace"""
|
510
|
-
ws = self.get_workspace_by_id(workspace_id)
|
511
|
-
return ws.list_eventstreams()
|
512
|
-
|
513
1636
|
def create_eventstream(self, workspace_id, display_name, description = None):
|
514
|
-
"""Create an eventstream in a workspace
|
515
|
-
|
516
|
-
|
1637
|
+
"""Create an eventstream in a workspace
|
1638
|
+
Args:
|
1639
|
+
workspace_id (str): The ID of the workspace
|
1640
|
+
display_name (str): The display name of the eventstream
|
1641
|
+
description (str): The description of the eventstream
|
1642
|
+
Returns:
|
1643
|
+
dict: The created eventstream
|
1644
|
+
"""
|
1645
|
+
return self.create_item(workspace_id = workspace_id,
|
1646
|
+
display_name = display_name,
|
1647
|
+
type = "eventstreams",
|
1648
|
+
definition = None,
|
1649
|
+
description = description)
|
517
1650
|
|
1651
|
+
|
518
1652
|
def get_eventstream(self, workspace_id, eventstream_id = None, eventstream_name = None):
|
519
|
-
"""Get an eventstream from a workspace
|
520
|
-
|
521
|
-
|
1653
|
+
"""Get an eventstream from a workspace
|
1654
|
+
Args:
|
1655
|
+
workspace_id (str): The ID of the workspace
|
1656
|
+
eventstream_id (str): The ID of the eventstream
|
1657
|
+
eventstream_name (str): The name of the eventstream
|
1658
|
+
Returns:
|
1659
|
+
Eventstream: The eventstream object
|
1660
|
+
"""
|
1661
|
+
from msfabricpysdkcore.otheritems import Eventstream
|
1662
|
+
if eventstream_id is None and eventstream_name is not None:
|
1663
|
+
evstreams = self.list_eventstreams(workspace_id)
|
1664
|
+
evstreams = [ev for ev in evstreams if ev.display_name == eventstream_name]
|
1665
|
+
if len(evstreams) == 0:
|
1666
|
+
raise Exception(f"Eventstream with name {eventstream_name} not found")
|
1667
|
+
eventstream_id = evstreams[0].id
|
1668
|
+
if eventstream_id is None:
|
1669
|
+
raise Exception("eventstream_id or the eventstream_name is required")
|
1670
|
+
|
1671
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/eventstreams/{eventstream_id}"
|
522
1672
|
|
1673
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1674
|
+
error_message="Error getting eventstream", return_format="json")
|
1675
|
+
return Eventstream.from_dict(item_dict, core_client=self)
|
1676
|
+
|
523
1677
|
def delete_eventstream(self, workspace_id, eventstream_id):
|
524
|
-
"""Delete an eventstream from a workspace
|
525
|
-
|
526
|
-
|
1678
|
+
"""Delete an eventstream from a workspace
|
1679
|
+
Args:
|
1680
|
+
workspace_id (str): The ID of the workspace
|
1681
|
+
eventstream_id (str): The ID of the eventstream
|
1682
|
+
Returns:
|
1683
|
+
int: The status code of the response
|
1684
|
+
"""
|
1685
|
+
return self.delete_item(workspace_id, eventstream_id, type="eventstreams")
|
527
1686
|
|
528
|
-
def
|
529
|
-
"""
|
530
|
-
|
531
|
-
|
1687
|
+
def list_eventstreams(self, workspace_id, with_properties = False):
|
1688
|
+
"""List eventstreams in a workspace
|
1689
|
+
Args:
|
1690
|
+
workspace_id (str): The ID of the workspace
|
1691
|
+
with_properties (bool): Whether to get the item object with properties
|
1692
|
+
Returns:
|
1693
|
+
list: The list of event
|
1694
|
+
"""
|
1695
|
+
return self.list_items(workspace_id=workspace_id, type="eventstreams", with_properties=with_properties)
|
1696
|
+
|
1697
|
+
def update_eventstream(self, workspace_id, eventstream_id, display_name = None, description = None, return_item="Default"):
|
1698
|
+
"""Update an eventstream in a workspace
|
1699
|
+
Args:
|
1700
|
+
workspace_id (str): The ID of the workspace
|
1701
|
+
eventstream_id (str): The ID of the eventstream
|
1702
|
+
display_name (str): The display name of the eventstream
|
1703
|
+
description (str): The description of the eventstream
|
1704
|
+
Returns:
|
1705
|
+
dict: The updated eventstream
|
1706
|
+
"""
|
1707
|
+
return self.update_item(workspace_id, eventstream_id, display_name = display_name, description = description,
|
1708
|
+
type= "eventstreams", return_item=return_item)
|
532
1709
|
|
533
1710
|
# kqlDatabases
|
534
1711
|
|
535
|
-
def list_kql_databases(self, workspace_id):
|
536
|
-
"""List kql databases in a workspace"""
|
537
|
-
ws = self.get_workspace_by_id(workspace_id)
|
538
|
-
return ws.list_kql_databases()
|
539
|
-
|
540
1712
|
def create_kql_database(self, workspace_id, creation_payload, display_name, description = None):
|
541
|
-
"""Create a kql database in a workspace
|
542
|
-
|
543
|
-
|
544
|
-
|
1713
|
+
"""Create a kql database in a workspace
|
1714
|
+
Args:
|
1715
|
+
workspace_id (str): The ID of the workspace
|
1716
|
+
creation_payload (dict): The creation payload
|
1717
|
+
display_name (str): The display name of the kql database
|
1718
|
+
description (str): The description of the kql database
|
1719
|
+
Returns:
|
1720
|
+
dict: The created kql database
|
1721
|
+
"""
|
1722
|
+
return self.create_item(workspace_id = workspace_id,
|
1723
|
+
display_name = display_name,
|
1724
|
+
type = "kqlDatabases",
|
1725
|
+
description = description,
|
1726
|
+
creation_payload = creation_payload)
|
1727
|
+
|
1728
|
+
def delete_kql_database(self, workspace_id, kql_database_id):
|
1729
|
+
"""Delete a kql database from a workspace
|
1730
|
+
Args:
|
1731
|
+
workspace_id (str): The ID of the workspace
|
1732
|
+
kql_database_id (str): The ID of the kql database
|
1733
|
+
Returns:
|
1734
|
+
int: The status code of the response
|
1735
|
+
"""
|
1736
|
+
return self.delete_item(workspace_id, kql_database_id, type="kqlDatabases")
|
1737
|
+
|
545
1738
|
def get_kql_database(self, workspace_id, kql_database_id = None, kql_database_name = None):
|
546
|
-
"""Get a kql database from a workspace
|
547
|
-
|
548
|
-
|
1739
|
+
"""Get a kql database from a workspace
|
1740
|
+
Args:
|
1741
|
+
workspace_id (str): The ID of the workspace
|
1742
|
+
kql_database_id (str): The ID of the kql database
|
1743
|
+
kql_database_name (str): The name of the kql database
|
1744
|
+
Returns:
|
1745
|
+
KQLDatabase: The kql database object
|
1746
|
+
"""
|
1747
|
+
from msfabricpysdkcore.otheritems import KQLDatabase
|
1748
|
+
if kql_database_id is None and kql_database_name is not None:
|
1749
|
+
kql_databases = self.list_kql_databases(workspace_id)
|
1750
|
+
kql_databases = [kd for kd in kql_databases if kd.display_name == kql_database_name]
|
1751
|
+
if len(kql_databases) == 0:
|
1752
|
+
raise Exception(f"Kql database with name {kql_database_name} not found")
|
1753
|
+
kql_database_id = kql_databases[0].id
|
1754
|
+
if kql_database_id is None:
|
1755
|
+
raise Exception("kql_database_id or the kql_database_name is required")
|
1756
|
+
|
1757
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/kqlDatabases/{kql_database_id}"
|
549
1758
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
1759
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1760
|
+
error_message="Error getting kql database", return_format="json")
|
1761
|
+
return KQLDatabase.from_dict(item_dict, core_client=self)
|
1762
|
+
|
1763
|
+
def list_kql_databases(self, workspace_id, with_properties = False):
|
1764
|
+
"""List kql databases in a workspace
|
1765
|
+
Args:
|
1766
|
+
workspace_id (str): The ID of the workspace
|
1767
|
+
with_properties (bool): Whether to get the item object with properties
|
1768
|
+
Returns:
|
1769
|
+
list: The list of kql databases"""
|
1770
|
+
return self.list_items(workspace_id=workspace_id, type="kqlDatabases", with_properties=with_properties)
|
554
1771
|
|
555
|
-
def update_kql_database(self, workspace_id, kql_database_id, display_name = None, description = None):
|
556
|
-
"""Update a kql database in a workspace
|
557
|
-
|
558
|
-
|
1772
|
+
def update_kql_database(self, workspace_id, kql_database_id, display_name = None, description = None, return_item="Default"):
|
1773
|
+
"""Update a kql database in a workspace
|
1774
|
+
Args:
|
1775
|
+
workspace_id (str): The ID of the workspace
|
1776
|
+
kql_database_id (str): The ID of the kql database
|
1777
|
+
display_name (str): The display name of the kql database
|
1778
|
+
description (str): The description of the kql database
|
1779
|
+
Returns:
|
1780
|
+
dict: The updated kql database
|
1781
|
+
"""
|
1782
|
+
return self.update_item(workspace_id, kql_database_id, display_name = display_name,
|
1783
|
+
description = description, type= "kqlDatabases", return_item=return_item)
|
559
1784
|
|
560
1785
|
# kqlQuerysets
|
561
1786
|
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
1787
|
+
|
1788
|
+
def delete_kql_queryset(self, workspace_id, kql_queryset_id):
|
1789
|
+
"""Delete a kql queryset from a workspace
|
1790
|
+
Args:
|
1791
|
+
workspace_id (str): The ID of the workspace
|
1792
|
+
kql_queryset_id (str): The ID of the kql queryset
|
1793
|
+
Returns:
|
1794
|
+
int: The status code of the response
|
1795
|
+
"""
|
1796
|
+
return self.delete_item(workspace_id, kql_queryset_id, type="kqlQuerysets")
|
566
1797
|
|
567
1798
|
def get_kql_queryset(self, workspace_id, kql_queryset_id = None, kql_queryset_name = None):
|
568
|
-
"""Get a kql queryset from a workspace
|
569
|
-
|
570
|
-
|
1799
|
+
"""Get a kql queryset from a workspace
|
1800
|
+
Args:
|
1801
|
+
workspace_id (str): The ID of the workspace
|
1802
|
+
kql_queryset_id (str): The ID of the kql queryset
|
1803
|
+
kql_queryset_name (str): The name of the kql queryset
|
1804
|
+
Returns:
|
1805
|
+
KQLQueryset: The kql queryset object
|
1806
|
+
"""
|
1807
|
+
from msfabricpysdkcore.otheritems import KQLQueryset
|
1808
|
+
if kql_queryset_id is None and kql_queryset_name is not None:
|
1809
|
+
kql_querysets = self.list_kql_querysets(workspace_id)
|
1810
|
+
kql_querysets = [kq for kq in kql_querysets if kq.display_name == kql_queryset_name]
|
1811
|
+
if len(kql_querysets) == 0:
|
1812
|
+
raise Exception(f"Kql queryset with name {kql_queryset_name} not found")
|
1813
|
+
kql_queryset_id = kql_querysets[0].id
|
1814
|
+
if kql_queryset_id is None:
|
1815
|
+
raise Exception("kql_queryset_id or the kql_queryset_name is required")
|
1816
|
+
|
1817
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/kqlQuerysets/{kql_queryset_id}"
|
1818
|
+
|
1819
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1820
|
+
error_message="Error getting kql queryset", return_format="json")
|
1821
|
+
|
1822
|
+
return KQLQueryset.from_dict(item_dict, core_client=self)
|
1823
|
+
|
1824
|
+
def update_kql_queryset(self, workspace_id, kql_queryset_id, display_name = None, description = None, return_item="Default"):
|
1825
|
+
"""Update a kql queryset in a workspace
|
1826
|
+
Args:
|
1827
|
+
workspace_id (str): The ID of the workspace
|
1828
|
+
kql_queryset_id (str): The ID of the kql queryset
|
1829
|
+
display_name (str): The display name of the kql queryset
|
1830
|
+
description (str): The description of the kql queryset
|
1831
|
+
Returns:
|
1832
|
+
dict: The updated kql queryset
|
1833
|
+
"""
|
1834
|
+
return self.update_item(workspace_id, kql_queryset_id, display_name = display_name,
|
1835
|
+
description = description, type= "kqlQuerysets", return_item=return_item)
|
1836
|
+
|
1837
|
+
def list_kql_querysets(self, workspace_id, with_properties = False):
|
1838
|
+
"""List kql querysets in a workspace
|
1839
|
+
Args:
|
1840
|
+
workspace_id (str): The ID of the workspace
|
1841
|
+
with_properties (bool): Whether to get the item object with properties
|
1842
|
+
Returns:
|
1843
|
+
list: The list of kql querysets
|
1844
|
+
"""
|
1845
|
+
return self.list_items(workspace_id=workspace_id, type="kqlQuerysets", with_properties=with_properties)
|
571
1846
|
|
572
|
-
def update_kql_queryset(self, workspace_id, kql_queryset_id, display_name = None, description = None):
|
573
|
-
"""Update a kql queryset in a workspace"""
|
574
|
-
ws = self.get_workspace_by_id(workspace_id)
|
575
|
-
return ws.update_kql_queryset(kql_queryset_id, display_name = display_name, description = description)
|
576
|
-
|
577
|
-
def delete_kql_queryset(self, workspace_id, kql_queryset_id):
|
578
|
-
"""Delete a kql queryset from a workspace"""
|
579
|
-
ws = self.get_workspace_by_id(workspace_id)
|
580
|
-
return ws.delete_kql_queryset(kql_queryset_id)
|
581
1847
|
|
582
1848
|
# lakehouses
|
583
1849
|
|
584
|
-
def
|
585
|
-
|
586
|
-
|
587
|
-
|
1850
|
+
def run_on_demand_table_maintenance(self, workspace_id, lakehouse_id,
|
1851
|
+
execution_data = None,
|
1852
|
+
job_type = "TableMaintenance", wait_for_completion = False):
|
1853
|
+
"""Run on demand table maintenance
|
1854
|
+
Args:
|
1855
|
+
workspace_id (str): The ID of the workspace
|
1856
|
+
lakehouse_id (str): The ID of the lakehouse
|
1857
|
+
execution_data (dict): The execution data
|
1858
|
+
job_type (str): The job type
|
1859
|
+
wait_for_completion (bool): Whether to wait for the operation to complete
|
1860
|
+
Returns:
|
1861
|
+
dict: The operation result or response value
|
1862
|
+
"""
|
1863
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}/jobs/instances?jobType={job_type}"
|
1864
|
+
|
1865
|
+
body = {
|
1866
|
+
"executionData": execution_data
|
1867
|
+
}
|
1868
|
+
|
1869
|
+
respone_operation_result = self.calling_routine(url, operation="POST", body=body, response_codes=[200, 202, 429],
|
1870
|
+
error_message="Error running on demand table maintenance",
|
1871
|
+
return_format="response+operation_result", wait_for_completion=wait_for_completion)
|
1872
|
+
|
1873
|
+
return respone_operation_result
|
588
1874
|
|
589
1875
|
def create_lakehouse(self, workspace_id, display_name, description = None):
|
590
|
-
"""Create a lakehouse in a workspace
|
591
|
-
|
592
|
-
|
1876
|
+
"""Create a lakehouse in a workspace
|
1877
|
+
Args:
|
1878
|
+
workspace_id (str): The ID of the workspace
|
1879
|
+
display_name (str): The display name of the lakehouse
|
1880
|
+
description (str): The description of the lakehouse
|
1881
|
+
Returns:
|
1882
|
+
dict: The created lakehouse
|
1883
|
+
"""
|
1884
|
+
return self.create_item(workspace_id = workspace_id,
|
1885
|
+
display_name = display_name,
|
1886
|
+
type = "lakehouses",
|
1887
|
+
description = description)
|
593
1888
|
|
594
1889
|
def delete_lakehouse(self, workspace_id, lakehouse_id):
|
595
|
-
"""Delete a lakehouse from a workspace
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
return
|
1890
|
+
"""Delete a lakehouse from a workspace
|
1891
|
+
Args:
|
1892
|
+
workspace_id (str): The ID of the workspace
|
1893
|
+
lakehouse_id (str): The ID of the lakehouse
|
1894
|
+
Returns:
|
1895
|
+
int: The status code of the response
|
1896
|
+
"""
|
1897
|
+
return self.delete_item(workspace_id, lakehouse_id, type="lakehouses")
|
603
1898
|
|
604
1899
|
def get_lakehouse(self, workspace_id, lakehouse_id = None, lakehouse_name = None):
|
605
|
-
"""Get a lakehouse from a workspace
|
606
|
-
|
607
|
-
|
1900
|
+
"""Get a lakehouse from a workspace
|
1901
|
+
Args:
|
1902
|
+
workspace_id (str): The ID of the workspace
|
1903
|
+
lakehouse_id (str): The ID of the lakehouse
|
1904
|
+
lakehouse_name (str): The name of the lakehouse
|
1905
|
+
Returns:
|
1906
|
+
Lakehouse: The lakehouse object
|
1907
|
+
"""
|
1908
|
+
from msfabricpysdkcore.lakehouse import Lakehouse
|
1909
|
+
if lakehouse_id is None and lakehouse_name is not None:
|
1910
|
+
lakehouses = self.list_lakehouses(workspace_id)
|
1911
|
+
lakehouses = [lh for lh in lakehouses if lh.display_name == lakehouse_name]
|
1912
|
+
if len(lakehouses) == 0:
|
1913
|
+
raise Exception(f"Lakehouse with name {lakehouse_name} not found")
|
1914
|
+
lakehouse_id = lakehouses[0].id
|
1915
|
+
if lakehouse_id is None:
|
1916
|
+
raise Exception("lakehouse_id or the lakehouse_name is required")
|
1917
|
+
|
1918
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}"
|
1919
|
+
|
1920
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1921
|
+
error_message="Error getting lakehouse", return_format="json")
|
1922
|
+
return Lakehouse.from_dict(item_dict, core_client=self)
|
1923
|
+
|
1924
|
+
def list_lakehouses(self, workspace_id, with_properties = False):
|
1925
|
+
"""List lakehouses in a workspace
|
1926
|
+
Args:
|
1927
|
+
workspace_id (str): The ID of the workspace
|
1928
|
+
with_properties (bool): Whether to get the item object with properties
|
1929
|
+
Returns:
|
1930
|
+
list: The list of lakehouses
|
1931
|
+
"""
|
1932
|
+
return self.list_items(workspace_id, type="lakehouses", with_properties = with_properties)
|
1933
|
+
|
1934
|
+
def update_lakehouse(self, workspace_id, lakehouse_id, display_name = None, description = None, return_item="Default"):
|
1935
|
+
"""Update a lakehouse in a workspace
|
1936
|
+
Args:
|
1937
|
+
workspace_id (str): The ID of the workspace
|
1938
|
+
lakehouse_id (str): The ID of the lakehouse
|
1939
|
+
display_name (str): The display name of the lakehouse
|
1940
|
+
description (str): The description of the lakehouse
|
1941
|
+
Returns:
|
1942
|
+
dict: The updated lakehouse
|
1943
|
+
"""
|
1944
|
+
return self.update_item(workspace_id, item_id=lakehouse_id, display_name = display_name, description = description,
|
1945
|
+
type="lakehouses", return_item=return_item)
|
1946
|
+
|
608
1947
|
|
609
1948
|
def list_tables(self, workspace_id, lakehouse_id):
|
610
|
-
|
611
|
-
|
1949
|
+
"""List all tables in the lakehouse
|
1950
|
+
Args:
|
1951
|
+
workspace_id (str): The ID of the workspace
|
1952
|
+
lakehouse_id (str): The ID of the lakehouse
|
1953
|
+
Returns:
|
1954
|
+
list: The list of tables
|
1955
|
+
"""
|
1956
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}/tables"
|
1957
|
+
|
1958
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
1959
|
+
error_message="Error listing tables", return_format="data", paging=True)
|
1960
|
+
|
1961
|
+
return items
|
1962
|
+
|
1963
|
+
def check_if_table_is_created(self, workspace_id, lakehouse_id, table_name):
|
1964
|
+
"""Check if the table is created
|
1965
|
+
Args:
|
1966
|
+
workspace_id (str): The ID of the workspace
|
1967
|
+
lakehouse_id (str): The ID of the lakehouse
|
1968
|
+
table_name (str): The name of the table
|
1969
|
+
Returns:
|
1970
|
+
bool: Whether the table is created
|
1971
|
+
"""
|
1972
|
+
for _ in range(60):
|
1973
|
+
table_names = [table["name"] for table in self.list_tables(workspace_id, lakehouse_id)]
|
1974
|
+
if table_name in table_names:
|
1975
|
+
return True
|
1976
|
+
sleep(3)
|
1977
|
+
return False
|
612
1978
|
|
613
1979
|
def load_table(self, workspace_id, lakehouse_id, table_name, path_type, relative_path,
|
614
1980
|
file_extension = None, format_options = None,
|
615
1981
|
mode = None, recursive = None, wait_for_completion = True):
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
1982
|
+
"""Load a table in the lakehouse
|
1983
|
+
Args:
|
1984
|
+
workspace_id (str): The ID of the workspace
|
1985
|
+
lakehouse_id (str): The ID of the lakehouse
|
1986
|
+
table_name (str): The name of the table
|
1987
|
+
path_type (str): The path type
|
1988
|
+
relative_path (str): The relative path
|
1989
|
+
file_extension (str): The file extension
|
1990
|
+
format_options (dict): The format options
|
1991
|
+
mode (str): The mode
|
1992
|
+
recursive (bool): Whether to load recursively
|
1993
|
+
wait_for_completion (bool): Whether to wait for the operation to complete
|
1994
|
+
Returns:
|
1995
|
+
int: The status code of the response
|
1996
|
+
"""
|
1997
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}/tables/{table_name}/load"
|
1998
|
+
|
1999
|
+
body = {
|
2000
|
+
"relativePath": relative_path,
|
2001
|
+
"pathType": path_type,
|
2002
|
+
}
|
2003
|
+
|
2004
|
+
if file_extension:
|
2005
|
+
body["fileExtension"] = file_extension
|
2006
|
+
if format_options:
|
2007
|
+
body["formatOptions"] = format_options
|
2008
|
+
if mode:
|
2009
|
+
body["mode"] = mode
|
2010
|
+
if recursive:
|
2011
|
+
body["recursive"] = recursive
|
2012
|
+
|
2013
|
+
response = self.calling_routine(url, operation="POST", body=body, response_codes=[202, 429],
|
2014
|
+
error_message="Error loading table", return_format="response",
|
2015
|
+
wait_for_completion=False)
|
2016
|
+
|
2017
|
+
if wait_for_completion:
|
2018
|
+
success = self.check_if_table_is_created(workspace_id = workspace_id,
|
2019
|
+
lakehouse_id = lakehouse_id,
|
2020
|
+
table_name = table_name)
|
2021
|
+
|
2022
|
+
if not success:
|
2023
|
+
print("Warning: Table not created after 3 minutes")
|
2024
|
+
else:
|
2025
|
+
print("Table created")
|
2026
|
+
return response.status_code
|
629
2027
|
|
630
2028
|
# mlExperiments
|
631
2029
|
|
632
|
-
|
633
|
-
"""List ml experiments in a workspace"""
|
634
|
-
ws = self.get_workspace_by_id(workspace_id)
|
635
|
-
return ws.list_ml_experiments()
|
636
|
-
|
2030
|
+
|
637
2031
|
def create_ml_experiment(self, workspace_id, display_name, description = None):
|
638
|
-
"""Create an ml experiment in a workspace
|
639
|
-
|
640
|
-
|
2032
|
+
"""Create an ml experiment in a workspace
|
2033
|
+
Args:
|
2034
|
+
workspace_id (str): The ID of the workspace
|
2035
|
+
display_name (str): The display name of the ml experiment
|
2036
|
+
description (str): The description of the ml experiment
|
2037
|
+
Returns:
|
2038
|
+
dict: The created ml experiment
|
2039
|
+
"""
|
2040
|
+
return self.create_item(workspace_id = workspace_id,
|
2041
|
+
display_name = display_name,
|
2042
|
+
type = "mlExperiments",
|
2043
|
+
description = description)
|
2044
|
+
|
2045
|
+
def delete_ml_experiment(self, workspace_id, ml_experiment_id):
|
2046
|
+
"""Delete an ml experiment from a workspace
|
2047
|
+
Args:
|
2048
|
+
workspace_id (str): The ID of the workspace
|
2049
|
+
ml_experiment_id (str): The ID of the ml experiment
|
2050
|
+
Returns:
|
2051
|
+
int: The status code of the response
|
2052
|
+
"""
|
2053
|
+
return self.delete_item(workspace_id, ml_experiment_id, type="mlExperiments")
|
641
2054
|
|
642
2055
|
def get_ml_experiment(self, workspace_id, ml_experiment_id = None, ml_experiment_name = None):
|
643
|
-
"""Get an ml experiment from a workspace
|
644
|
-
|
645
|
-
|
2056
|
+
"""Get an ml experiment from a workspace
|
2057
|
+
Args:
|
2058
|
+
workspace_id (str): The ID of the workspace
|
2059
|
+
ml_experiment_id (str): The ID of the ml experiment
|
2060
|
+
ml_experiment_name (str): The name of the ml experiment
|
2061
|
+
Returns:
|
2062
|
+
MLExperiment: The ml experiment object
|
2063
|
+
"""
|
2064
|
+
from msfabricpysdkcore.otheritems import MLExperiment
|
2065
|
+
if ml_experiment_id is None and ml_experiment_name is not None:
|
2066
|
+
ml_experiments = self.list_ml_experiments(workspace_id)
|
2067
|
+
ml_experiments = [ml for ml in ml_experiments if ml.display_name == ml_experiment_name]
|
2068
|
+
if len(ml_experiments) == 0:
|
2069
|
+
raise Exception(f"ML experiment with name {ml_experiment_name} not found")
|
2070
|
+
ml_experiment_id = ml_experiments[0].id
|
2071
|
+
if ml_experiment_id is None:
|
2072
|
+
raise Exception("ml_experiment_id or the ml_experiment_name is required")
|
2073
|
+
|
2074
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/mlExperiments/{ml_experiment_id}"
|
2075
|
+
|
2076
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2077
|
+
error_message="Error getting ml experiment", return_format="json")
|
2078
|
+
return MLExperiment.from_dict(item_dict, core_client=self)
|
2079
|
+
|
2080
|
+
def list_ml_experiments(self, workspace_id, with_properties = False):
|
2081
|
+
"""List ml experiments in a workspace
|
2082
|
+
Args:
|
2083
|
+
workspace_id (str): The ID of the workspace
|
2084
|
+
with_properties (bool): Whether to get the item object with properties
|
2085
|
+
Returns:
|
2086
|
+
list: The list of ml experiments
|
2087
|
+
"""
|
2088
|
+
return self.list_items(workspace_id=workspace_id, type="mlExperiments", with_properties = with_properties)
|
646
2089
|
|
647
|
-
def
|
648
|
-
"""
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
2090
|
+
def update_ml_experiment(self, workspace_id, ml_experiment_id, display_name = None, description = None, return_item="Default"):
|
2091
|
+
"""Update an ml experiment in a workspace
|
2092
|
+
Args:
|
2093
|
+
workspace_id (str): The ID of the workspace
|
2094
|
+
ml_experiment_id (str): The ID of the ml experiment
|
2095
|
+
display_name (str): The display name of the ml experiment
|
2096
|
+
description (str): The description of the ml experiment
|
2097
|
+
Returns:
|
2098
|
+
dict: The updated ml experiment
|
2099
|
+
"""
|
2100
|
+
return self.update_item(workspace_id, ml_experiment_id, display_name = display_name, description = description,
|
2101
|
+
type="mlExperiments", return_item=return_item)
|
656
2102
|
|
657
2103
|
# mlModels
|
658
2104
|
|
659
|
-
def list_ml_models(self, workspace_id):
|
660
|
-
"""List ml models in a workspace"""
|
661
|
-
ws = self.get_workspace_by_id(workspace_id)
|
662
|
-
return ws.list_ml_models()
|
663
|
-
|
664
2105
|
def create_ml_model(self, workspace_id, display_name, description = None):
|
665
|
-
"""Create an ml model in a workspace
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
2106
|
+
"""Create an ml model in a workspace
|
2107
|
+
Args:
|
2108
|
+
workspace_id (str): The ID of the workspace
|
2109
|
+
display_name (str): The display name of the ml model
|
2110
|
+
description (str): The description of the ml model
|
2111
|
+
Returns:
|
2112
|
+
dict: The created ml model
|
2113
|
+
"""
|
2114
|
+
return self.create_item(workspace_id = workspace_id, display_name = display_name, type = "mlModels", description = description,
|
2115
|
+
wait_for_completion = True)
|
673
2116
|
|
674
2117
|
def delete_ml_model(self, workspace_id, ml_model_id):
|
675
|
-
"""Delete an ml model from a workspace
|
676
|
-
|
677
|
-
|
2118
|
+
"""Delete an ml model from a workspace
|
2119
|
+
Args:
|
2120
|
+
workspace_id (str): The ID of the workspace
|
2121
|
+
ml_model_id (str): The ID of the ml model
|
2122
|
+
Returns:
|
2123
|
+
int: The status code of the response
|
2124
|
+
"""
|
2125
|
+
return self.delete_item(workspace_id, ml_model_id, type="mlModels")
|
2126
|
+
|
2127
|
+
def get_ml_model(self, workspace_id, ml_model_id = None, ml_model_name = None):
|
2128
|
+
"""Get an ml model from a workspace
|
2129
|
+
Args:
|
2130
|
+
workspace_id (str): The ID of the workspace
|
2131
|
+
ml_model_id (str): The ID of the ml model
|
2132
|
+
ml_model_name (str): The name of the ml model
|
2133
|
+
Returns:
|
2134
|
+
MLModel: The ml model object
|
2135
|
+
"""
|
2136
|
+
from msfabricpysdkcore.otheritems import MLModel
|
2137
|
+
if ml_model_id is None and ml_model_name is not None:
|
2138
|
+
ml_models = self.list_ml_models(workspace_id)
|
2139
|
+
ml_models = [ml for ml in ml_models if ml.display_name == ml_model_name]
|
2140
|
+
if len(ml_models) == 0:
|
2141
|
+
raise Exception(f"ML model with name {ml_model_name} not found")
|
2142
|
+
ml_model_id = ml_models[0].id
|
2143
|
+
if ml_model_id is None:
|
2144
|
+
raise Exception("ml_model_id or the ml_model_name is required")
|
2145
|
+
|
2146
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/mlModels/{ml_model_id}"
|
2147
|
+
|
2148
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2149
|
+
error_message="Error getting ml model", return_format="json")
|
2150
|
+
|
2151
|
+
return MLModel.from_dict(item_dict, core_client=self)
|
2152
|
+
|
2153
|
+
def list_ml_models(self, workspace_id, with_properties=False):
|
2154
|
+
"""List ml models in a workspace
|
2155
|
+
Args:
|
2156
|
+
workspace_id (str): The ID of the workspace
|
2157
|
+
with_properties (bool): Whether to get the item object with properties
|
2158
|
+
Returns:
|
2159
|
+
list: The list of ml models
|
2160
|
+
"""
|
2161
|
+
return self.list_items(workspace_id=workspace_id, type="mlModels", with_properties = with_properties)
|
678
2162
|
|
679
|
-
def update_ml_model(self, workspace_id, ml_model_id, display_name = None, description = None):
|
680
|
-
"""Update an ml model in a workspace
|
681
|
-
|
682
|
-
|
2163
|
+
def update_ml_model(self, workspace_id, ml_model_id, display_name = None, description = None, return_item="Default"):
|
2164
|
+
"""Update an ml model in a workspace
|
2165
|
+
Args:
|
2166
|
+
workspace_id (str): The ID of the workspace
|
2167
|
+
ml_model_id (str): The ID of the ml model
|
2168
|
+
display_name (str): The display name of the ml model
|
2169
|
+
description (str): The description of the ml model
|
2170
|
+
Returns:
|
2171
|
+
dict: The updated ml model
|
2172
|
+
"""
|
2173
|
+
return self.update_item(workspace_id, ml_model_id, display_name = display_name, description = description,
|
2174
|
+
type="mlModels", return_item=return_item)
|
683
2175
|
|
684
2176
|
# notebooks
|
685
2177
|
|
686
|
-
def list_notebooks(self, workspace_id):
|
687
|
-
"""List notebooks in a workspace"""
|
688
|
-
ws = self.get_workspace_by_id(workspace_id)
|
689
|
-
return ws.list_notebooks()
|
690
|
-
|
691
2178
|
def create_notebook(self, workspace_id, display_name, definition = None, description = None):
|
692
|
-
"""Create a notebook in a workspace
|
693
|
-
|
694
|
-
|
2179
|
+
"""Create a notebook in a workspace
|
2180
|
+
Args:
|
2181
|
+
workspace_id (str): The ID of the workspace
|
2182
|
+
display_name (str): The display name of the notebook
|
2183
|
+
definition (dict): The definition of the notebook
|
2184
|
+
description (str): The description of the notebook
|
2185
|
+
Returns:
|
2186
|
+
dict: The created notebook
|
2187
|
+
"""
|
2188
|
+
return self.create_item(workspace_id = workspace_id, display_name = display_name, type = "notebooks", definition = definition, description = description)
|
695
2189
|
|
696
2190
|
def get_notebook(self, workspace_id, notebook_id = None, notebook_name = None):
|
697
|
-
"""Get a notebook from a workspace
|
698
|
-
|
699
|
-
|
2191
|
+
"""Get a notebook from a workspace
|
2192
|
+
Args:
|
2193
|
+
workspace_id (str): The ID of the workspace
|
2194
|
+
notebook_id (str): The ID of the notebook
|
2195
|
+
notebook_name (str): The name of the notebook
|
2196
|
+
Returns:
|
2197
|
+
Notebook: The notebook object"""
|
2198
|
+
from msfabricpysdkcore.otheritems import Notebook
|
2199
|
+
if notebook_id is None and notebook_name is not None:
|
2200
|
+
notebooks = self.list_notebooks(workspace_id)
|
2201
|
+
notebooks = [nb for nb in notebooks if nb.display_name == notebook_name]
|
2202
|
+
if len(notebooks) == 0:
|
2203
|
+
raise Exception(f"Notebook with name {notebook_name} not found")
|
2204
|
+
notebook_id = notebooks[0].id
|
2205
|
+
if notebook_id is None:
|
2206
|
+
raise Exception("notebook_id or the notebook_name is required")
|
2207
|
+
|
2208
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/notebooks/{notebook_id}"
|
2209
|
+
|
2210
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2211
|
+
error_message="Error getting notebook", return_format="json")
|
2212
|
+
|
2213
|
+
notebook = Notebook.from_dict(item_dict, core_client=self)
|
2214
|
+
notebook.get_definition()
|
2215
|
+
return notebook
|
2216
|
+
|
700
2217
|
|
2218
|
+
def get_notebook_definition(self, workspace_id, notebook_id, format = None):
|
2219
|
+
"""Get the definition of a notebook
|
2220
|
+
Args:
|
2221
|
+
workspace_id (str): The ID of the workspace
|
2222
|
+
notebook_id (str): The ID of the notebook
|
2223
|
+
format (str): The format of the definition
|
2224
|
+
Returns:
|
2225
|
+
dict: The definition of the notebook
|
2226
|
+
"""
|
2227
|
+
return self.get_item_definition(workspace_id, notebook_id, type="notebooks", format=format)
|
2228
|
+
|
701
2229
|
def delete_notebook(self, workspace_id, notebook_id):
|
702
|
-
"""Delete a notebook from a workspace
|
703
|
-
|
704
|
-
|
2230
|
+
"""Delete a notebook from a workspace
|
2231
|
+
Args:
|
2232
|
+
workspace_id (str): The ID of the workspace
|
2233
|
+
notebook_id (str): The ID of the notebook
|
2234
|
+
Returns:
|
2235
|
+
int: The status code of the response
|
2236
|
+
"""
|
2237
|
+
return self.delete_item(workspace_id, notebook_id, type="notebooks")
|
2238
|
+
|
2239
|
+
def list_notebooks(self, workspace_id, with_properties = False):
|
2240
|
+
"""List notebooks in a workspace
|
2241
|
+
Args:
|
2242
|
+
workspace_id (str): The ID of the workspace
|
2243
|
+
with_properties (bool): Whether to get the item object with properties
|
2244
|
+
Returns:
|
2245
|
+
list: The list of notebooks
|
2246
|
+
"""
|
2247
|
+
return self.list_items(workspace_id = workspace_id, type = "notebooks", with_properties = with_properties)
|
705
2248
|
|
706
|
-
def update_notebook(self, workspace_id, notebook_id, display_name = None, description = None):
|
707
|
-
"""Update a notebook in a workspace
|
708
|
-
|
709
|
-
|
2249
|
+
def update_notebook(self, workspace_id, notebook_id, display_name = None, description = None, return_item="Default"):
|
2250
|
+
"""Update a notebook in a workspace
|
2251
|
+
Args:
|
2252
|
+
workspace_id (str): The ID of the workspace
|
2253
|
+
notebook_id (str): The ID of the notebook
|
2254
|
+
display_name (str): The display name of the notebook
|
2255
|
+
description (str): The description of the notebook
|
2256
|
+
Returns:
|
2257
|
+
dict: The updated notebook
|
2258
|
+
"""
|
2259
|
+
return self.update_item(workspace_id, notebook_id, display_name = display_name, description = description,
|
2260
|
+
type="notebooks", return_item=return_item)
|
710
2261
|
|
711
|
-
def get_notebook_definition(self, workspace_id, notebook_id, format = None):
|
712
|
-
"""Get the definition of a notebook"""
|
713
|
-
ws = self.get_workspace_by_id(workspace_id)
|
714
|
-
return ws.get_notebook_definition(notebook_id, format = format)
|
715
|
-
|
716
2262
|
def update_notebook_definition(self, workspace_id, notebook_id, definition):
|
717
|
-
"""Update the definition of a notebook
|
718
|
-
|
719
|
-
|
2263
|
+
"""Update the definition of a notebook
|
2264
|
+
Args:
|
2265
|
+
workspace_id (str): The ID of the workspace
|
2266
|
+
notebook_id (str): The ID of the notebook
|
2267
|
+
definition (dict): The definition of the notebook
|
2268
|
+
Returns:
|
2269
|
+
dict: The updated notebook
|
2270
|
+
"""
|
2271
|
+
return self.update_item_definition(workspace_id, notebook_id, definition, type="notebooks")
|
720
2272
|
|
721
2273
|
# reports
|
722
2274
|
|
723
|
-
def list_reports(self, workspace_id, with_properties = False):
|
724
|
-
"""List reports in a workspace"""
|
725
|
-
ws = self.get_workspace_by_id(workspace_id)
|
726
|
-
return ws.list_reports(with_properties = with_properties)
|
727
|
-
|
728
2275
|
def create_report(self, workspace_id, display_name, definition = None, description = None):
|
729
|
-
"""Create a report in a workspace
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
2276
|
+
"""Create a report in a workspace
|
2277
|
+
Args:
|
2278
|
+
workspace_id (str): The ID of the workspace
|
2279
|
+
display_name (str): The display name of the report
|
2280
|
+
definition (dict): The definition of the report
|
2281
|
+
description (str): The description of the report
|
2282
|
+
Returns:
|
2283
|
+
dict: The created report
|
2284
|
+
"""
|
2285
|
+
return self.create_item(workspace_id = workspace_id, display_name = display_name, type = "reports", definition = definition, description = description)
|
737
2286
|
|
738
2287
|
def delete_report(self, workspace_id, report_id):
|
739
|
-
"""Delete a report from a workspace
|
740
|
-
|
741
|
-
|
2288
|
+
"""Delete a report from a workspace
|
2289
|
+
Args:
|
2290
|
+
workspace_id (str): The ID of the workspace
|
2291
|
+
report_id (str): The ID of the report
|
2292
|
+
Returns:
|
2293
|
+
int: The status code of the response
|
2294
|
+
"""
|
2295
|
+
return self.delete_item(workspace_id, report_id, type="reports")
|
742
2296
|
|
2297
|
+
def get_report(self, workspace_id, report_id = None, report_name = None):
|
2298
|
+
"""Get a report from a workspace
|
2299
|
+
Args:
|
2300
|
+
workspace_id (str): The ID of the workspace
|
2301
|
+
report_id (str): The ID of the report
|
2302
|
+
report_name (str): The name of the report
|
2303
|
+
Returns:
|
2304
|
+
Report: The report object
|
2305
|
+
"""
|
2306
|
+
from msfabricpysdkcore.otheritems import Report
|
2307
|
+
if report_id is None and report_name is not None:
|
2308
|
+
reports = self.list_reports(workspace_id)
|
2309
|
+
reports = [rp for rp in reports if rp.display_name == report_name]
|
2310
|
+
if len(reports) == 0:
|
2311
|
+
raise Exception(f"Report with name {report_name} not found")
|
2312
|
+
report_id = reports[0].id
|
2313
|
+
if report_id is None:
|
2314
|
+
raise Exception("report_id or the report_name is required")
|
2315
|
+
|
2316
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/reports/{report_id}"
|
2317
|
+
|
2318
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2319
|
+
error_message="Error getting report", return_format="json")
|
2320
|
+
|
2321
|
+
report = Report.from_dict(item_dict, core_client=self)
|
2322
|
+
report.get_definition()
|
2323
|
+
return report
|
2324
|
+
|
2325
|
+
|
743
2326
|
def get_report_definition(self, workspace_id, report_id, format = None):
|
744
|
-
"""Get the definition of a report
|
745
|
-
|
746
|
-
|
2327
|
+
"""Get the definition of a report
|
2328
|
+
Args:
|
2329
|
+
workspace_id (str): The ID of the workspace
|
2330
|
+
report_id (str): The ID of the report
|
2331
|
+
format (str): The format of the definition
|
2332
|
+
Returns:
|
2333
|
+
dict: The definition of the report
|
2334
|
+
"""
|
2335
|
+
return self.get_item_definition(workspace_id, report_id, type="reports", format=format)
|
747
2336
|
|
2337
|
+
def list_reports(self, workspace_id, with_properties = False):
|
2338
|
+
"""List reports in a workspace
|
2339
|
+
Args:
|
2340
|
+
workspace_id (str): The ID of the workspace
|
2341
|
+
with_properties (bool): Whether to get the item object with properties
|
2342
|
+
Returns:
|
2343
|
+
list: The list of reports
|
2344
|
+
"""
|
2345
|
+
return self.list_items(workspace_id = workspace_id, type = "reports", with_properties = with_properties)
|
2346
|
+
|
748
2347
|
def update_report_definition(self, workspace_id, report_id, definition):
|
749
|
-
"""Update the definition of a report
|
750
|
-
|
751
|
-
|
2348
|
+
"""Update the definition of a report
|
2349
|
+
Args:
|
2350
|
+
workspace_id (str): The ID of the workspace
|
2351
|
+
report_id (str): The ID of the report
|
2352
|
+
definition (dict): The definition of the report
|
2353
|
+
Returns:
|
2354
|
+
Report: The updated report
|
2355
|
+
"""
|
2356
|
+
return self.update_item_definition(workspace_id, report_id, definition, type="reports")
|
752
2357
|
|
753
2358
|
# semanticModels
|
754
2359
|
|
755
2360
|
def list_semantic_models(self, workspace_id, with_properties = False):
|
756
|
-
"""List semantic models in a workspace
|
757
|
-
|
758
|
-
|
2361
|
+
"""List semantic models in a workspace
|
2362
|
+
Args:
|
2363
|
+
workspace_id (str): The ID of the workspace
|
2364
|
+
with_properties (bool): Whether to get the item object with properties
|
2365
|
+
Returns:
|
2366
|
+
list: The list of semantic models
|
2367
|
+
"""
|
2368
|
+
return self.list_items(workspace_id = workspace_id, type = "semanticModels", with_properties = with_properties)
|
759
2369
|
|
760
2370
|
def create_semantic_model(self, workspace_id, display_name, definition = None, description = None):
|
761
|
-
"""Create a semantic model in a workspace
|
762
|
-
|
763
|
-
|
2371
|
+
"""Create a semantic model in a workspace
|
2372
|
+
Args:
|
2373
|
+
workspace_id (str): The ID of the workspace
|
2374
|
+
display_name (str): The display name of the semantic model
|
2375
|
+
definition (dict): The definition of the semantic model
|
2376
|
+
description (str): The description of the semantic model
|
2377
|
+
Returns:
|
2378
|
+
dict: The created semantic model
|
2379
|
+
"""
|
2380
|
+
return self.create_item(workspace_id = workspace_id, display_name = display_name, type = "semanticModels", definition = definition, description = description)
|
764
2381
|
|
765
2382
|
def get_semantic_model(self, workspace_id, semantic_model_id = None, semantic_model_name = None):
|
766
|
-
"""Get a semantic model from a workspace
|
767
|
-
|
768
|
-
|
2383
|
+
"""Get a semantic model from a workspace
|
2384
|
+
Args:
|
2385
|
+
workspace_id (str): The ID of the workspace
|
2386
|
+
semantic_model_id (str): The ID of the semantic model
|
2387
|
+
semantic_model_name (str): The name of the semantic model
|
2388
|
+
Returns:
|
2389
|
+
SemanticModel: The semantic model object
|
2390
|
+
"""
|
2391
|
+
from msfabricpysdkcore.otheritems import SemanticModel
|
2392
|
+
if semantic_model_id is None and semantic_model_name is not None:
|
2393
|
+
semantic_models = self.list_semantic_models(workspace_id)
|
2394
|
+
semantic_models = [sm for sm in semantic_models if sm.display_name == semantic_model_name]
|
2395
|
+
if len(semantic_models) == 0:
|
2396
|
+
raise Exception(f"Semantic model with name {semantic_model_name} not found")
|
2397
|
+
semantic_model_id = semantic_models[0].id
|
2398
|
+
if semantic_model_id is None:
|
2399
|
+
raise Exception("semantic_model_id or the semantic_model_name is required")
|
2400
|
+
|
2401
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/semanticModels/{semantic_model_id}"
|
2402
|
+
|
2403
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2404
|
+
error_message="Error getting semantic model", return_format="json")
|
2405
|
+
semmodel = SemanticModel.from_dict(item_dict, core_client=self)
|
2406
|
+
semmodel.get_definition()
|
2407
|
+
|
2408
|
+
return semmodel
|
769
2409
|
|
770
2410
|
def delete_semantic_model(self, workspace_id, semantic_model_id):
|
771
|
-
"""Delete a semantic model from a workspace
|
772
|
-
|
773
|
-
|
2411
|
+
"""Delete a semantic model from a workspace
|
2412
|
+
Args:
|
2413
|
+
workspace_id (str): The ID of the workspace
|
2414
|
+
semantic_model_id (str): The ID of the semantic model
|
2415
|
+
Returns:
|
2416
|
+
int: The status code of the response
|
2417
|
+
"""
|
2418
|
+
return self.delete_item(workspace_id, semantic_model_id, type="semanticModels")
|
774
2419
|
|
775
2420
|
# def update_semantic_model(self, workspace_id, semantic_model_id, display_name = None, description = None):
|
776
2421
|
# """Update a semantic model in a workspace"""
|
@@ -778,212 +2423,150 @@ class FabricClientCore(FabricClient):
|
|
778
2423
|
# return ws.update_semantic_model(semantic_model_id, display_name = display_name, description = description)
|
779
2424
|
|
780
2425
|
def get_semantic_model_definition(self, workspace_id, semantic_model_id, format = None):
|
781
|
-
"""Get the definition of a semantic model
|
782
|
-
|
783
|
-
|
2426
|
+
"""Get the definition of a semantic model
|
2427
|
+
Args:
|
2428
|
+
workspace_id (str): The ID of the workspace
|
2429
|
+
semantic_model_id (str): The ID of the semantic model
|
2430
|
+
format (str): The format of the definition
|
2431
|
+
Returns:
|
2432
|
+
dict: The definition of the semantic model
|
2433
|
+
"""
|
2434
|
+
return self.get_item_definition(workspace_id, semantic_model_id, type="semanticModels", format=format)
|
784
2435
|
|
785
2436
|
def update_semantic_model_definition(self, workspace_id, semantic_model_id, definition):
|
786
|
-
"""Update the definition of a semantic model
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
"""
|
794
|
-
|
795
|
-
return ws.list_spark_job_definitions(with_properties = with_properties)
|
796
|
-
|
797
|
-
def create_spark_job_definition(self, workspace_id, display_name, definition = None, description = None):
|
798
|
-
"""Create a spark job definition in a workspace"""
|
799
|
-
ws = self.get_workspace_by_id(workspace_id)
|
800
|
-
return ws.create_spark_job_definition(display_name = display_name, definition = definition, description = description)
|
801
|
-
|
802
|
-
def get_spark_job_definition(self, workspace_id, spark_job_definition_id = None, spark_job_definition_name = None):
|
803
|
-
"""Get a spark job definition from a workspace"""
|
804
|
-
ws = self.get_workspace_by_id(workspace_id)
|
805
|
-
return ws.get_spark_job_definition(spark_job_definition_id = spark_job_definition_id, spark_job_definition_name = spark_job_definition_name)
|
806
|
-
|
807
|
-
def delete_spark_job_definition(self, workspace_id, spark_job_definition_id):
|
808
|
-
"""Delete a spark job definition from a workspace"""
|
809
|
-
ws = self.get_workspace_by_id(workspace_id)
|
810
|
-
return ws.delete_spark_job_definition(spark_job_definition_id)
|
811
|
-
|
812
|
-
def update_spark_job_definition(self, workspace_id, spark_job_definition_id, display_name = None, description = None):
|
813
|
-
"""Update a spark job definition in a workspace"""
|
814
|
-
ws = self.get_workspace_by_id(workspace_id)
|
815
|
-
return ws.update_spark_job_definition(spark_job_definition_id, display_name = display_name, description = description)
|
816
|
-
|
817
|
-
def get_spark_job_definition_definition(self, workspace_id, spark_job_definition_id, format = None):
|
818
|
-
"""Get the definition of a spark job definition"""
|
819
|
-
ws = self.get_workspace_by_id(workspace_id)
|
820
|
-
return ws.get_spark_job_definition_definition(spark_job_definition_id, format = format)
|
821
|
-
|
822
|
-
def update_spark_job_definition_definition(self, workspace_id, spark_job_definition_id, definition):
|
823
|
-
"""Update the definition of a spark job definition"""
|
824
|
-
ws = self.get_workspace_by_id(workspace_id)
|
825
|
-
return ws.update_spark_job_definition_definition(spark_job_definition_id, definition)
|
826
|
-
|
827
|
-
def run_on_demand_spark_job_definition(self, workspace_id, spark_job_definition_id, job_type = "sparkjob"):
|
828
|
-
"""Run an on demand spark job definition"""
|
829
|
-
ws = self.get_workspace_by_id(workspace_id)
|
830
|
-
return ws.run_on_demand_spark_job_definition(spark_job_definition_id, job_type)
|
831
|
-
|
832
|
-
# warehouses
|
833
|
-
|
834
|
-
def list_warehouses(self, workspace_id, with_properties = False):
|
835
|
-
"""List warehouses in a workspace"""
|
836
|
-
ws = self.get_workspace_by_id(workspace_id)
|
837
|
-
return ws.list_warehouses(with_properties = with_properties)
|
838
|
-
|
839
|
-
def create_warehouse(self, workspace_id, display_name, description = None):
|
840
|
-
"""Create a warehouse in a workspace"""
|
841
|
-
ws = self.get_workspace_by_id(workspace_id)
|
842
|
-
return ws.create_warehouse(display_name = display_name, description = description)
|
843
|
-
|
844
|
-
def get_warehouse(self, workspace_id, warehouse_id = None, warehouse_name = None):
|
845
|
-
"""Get a warehouse from a workspace"""
|
846
|
-
ws = self.get_workspace_by_id(workspace_id)
|
847
|
-
return ws.get_warehouse(warehouse_id = warehouse_id, warehouse_name = warehouse_name)
|
848
|
-
|
849
|
-
def delete_warehouse(self, workspace_id, warehouse_id):
|
850
|
-
"""Delete a warehouse from a workspace"""
|
851
|
-
ws = self.get_workspace_by_id(workspace_id)
|
852
|
-
return ws.delete_warehouse(warehouse_id)
|
853
|
-
|
854
|
-
def update_warehouse(self, workspace_id, warehouse_id, display_name = None, description = None):
|
855
|
-
"""Update a warehouse in a workspace"""
|
856
|
-
ws = self.get_workspace_by_id(workspace_id)
|
857
|
-
return ws.update_warehouse(warehouse_id, display_name = display_name, description = description)
|
858
|
-
|
2437
|
+
"""Update the definition of a semantic model
|
2438
|
+
Args:
|
2439
|
+
workspace_id (str): The ID of the workspace
|
2440
|
+
semantic_model_id (str): The ID of the semantic model
|
2441
|
+
definition (dict): The definition of the semantic model
|
2442
|
+
Returns:
|
2443
|
+
dict: The updated semantic model
|
2444
|
+
"""
|
2445
|
+
return self.update_item_definition(workspace_id, semantic_model_id, definition, type="semanticModels", wait_for_completion=False)
|
859
2446
|
# spark workspace custom pools
|
860
2447
|
|
861
|
-
def list_workspace_custom_pools(self, workspace_id):
|
862
|
-
"""List workspace custom pools"""
|
863
|
-
ws = self.get_workspace_by_id(workspace_id)
|
864
|
-
return ws.list_workspace_custom_pools()
|
865
|
-
|
866
2448
|
def create_workspace_custom_pool(self, workspace_id, name, node_family, node_size, auto_scale, dynamic_executor_allocation):
|
867
|
-
"""Create a workspace custom pool
|
868
|
-
ws = self.get_workspace_by_id(workspace_id)
|
869
|
-
return ws.create_workspace_custom_pool(name = name,
|
870
|
-
node_family = node_family,
|
871
|
-
node_size = node_size,
|
872
|
-
auto_scale = auto_scale,
|
873
|
-
dynamic_executor_allocation = dynamic_executor_allocation)
|
874
|
-
|
875
|
-
|
876
|
-
def get_workspace_custom_pool(self, workspace_id, pool_id):
|
877
|
-
"""Get a workspace custom pool"""
|
878
|
-
ws = self.get_workspace_by_id(workspace_id)
|
879
|
-
return ws.get_workspace_custom_pool(pool_id)
|
880
|
-
|
881
|
-
def delete_workspace_custom_pool(self, workspace_id, pool_id):
|
882
|
-
"""Delete a workspace custom pool"""
|
883
|
-
ws = self.get_workspace_by_id(workspace_id)
|
884
|
-
return ws.delete_workspace_custom_pool(pool_id)
|
885
|
-
|
886
|
-
def update_workspace_custom_pool(self, workspace_id, pool_id, name = None, node_family = None, node_size = None, auto_scale = None, dynamic_executor_allocation = None):
|
887
|
-
"""Update a workspace custom pool"""
|
888
|
-
ws = self.get_workspace_by_id(workspace_id)
|
889
|
-
return ws.update_workspace_custom_pool(pool_id, name = name, node_family = node_family, node_size = node_size, auto_scale = auto_scale, dynamic_executor_allocation = dynamic_executor_allocation)
|
890
|
-
|
891
|
-
# Deployment Pipelines
|
892
|
-
|
893
|
-
def deploy_stage_content(self, deployment_pipeline_id, source_stage_id, target_stage_id, created_workspace_details = None,
|
894
|
-
items = None, note = None, wait_for_completion = True):
|
895
|
-
"""Deploy stage content
|
2449
|
+
"""Create a workspace custom pool
|
896
2450
|
Args:
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
wait_for_completion (bool): Whether to wait for the deployment to complete
|
2451
|
+
workspace_id (str): The ID of the workspace
|
2452
|
+
name (str): The name of the pool
|
2453
|
+
node_family (str): The node family
|
2454
|
+
node_size (str): The node size
|
2455
|
+
auto_scale (bool): Whether to auto scale
|
2456
|
+
dynamic_executor_allocation (bool): Whether to use dynamic executor allocation
|
904
2457
|
Returns:
|
905
|
-
|
2458
|
+
SparkCustomPool: The created custom pool
|
2459
|
+
"""
|
2460
|
+
from msfabricpysdkcore.spark_custom_pool import SparkCustomPool
|
2461
|
+
|
2462
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/pools"
|
906
2463
|
|
907
|
-
|
2464
|
+
body = {
|
2465
|
+
"name": name,
|
2466
|
+
"nodeFamily": node_family,
|
2467
|
+
"nodeSize": node_size,
|
2468
|
+
"autoScale": auto_scale,
|
2469
|
+
"dynamicExecutorAllocation": dynamic_executor_allocation
|
2470
|
+
}
|
2471
|
+
response_dict = self.calling_routine(url, operation="POST", body=body, response_codes=[200, 201, 429],
|
2472
|
+
error_message="Error creating workspace custom pool", return_format="json")
|
908
2473
|
|
909
|
-
|
910
|
-
|
2474
|
+
response_dict["workspaceId"] = workspace_id
|
2475
|
+
return SparkCustomPool.from_dict(response_dict, core_client=self)
|
911
2476
|
|
912
|
-
def
|
913
|
-
"""
|
2477
|
+
def get_workspace_custom_pool(self, workspace_id, pool_id):
|
2478
|
+
"""Get a workspace custom pool
|
914
2479
|
Args:
|
915
|
-
|
2480
|
+
workspace_id (str): The ID of the workspace
|
2481
|
+
pool_id (str): The ID of the pool
|
916
2482
|
Returns:
|
917
|
-
|
2483
|
+
SparkCustomPool: The custom pool
|
918
2484
|
"""
|
919
|
-
|
920
|
-
|
921
|
-
url = "https://api.fabric.microsoft.com/v1/deploymentPipelines"
|
922
|
-
|
923
|
-
if continuationToken:
|
924
|
-
url = f"{url}?continuationToken={continuationToken}"
|
925
|
-
|
926
|
-
for _ in range(10):
|
927
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
928
|
-
if response.status_code == 429:
|
929
|
-
print("Too many requests, waiting 10 seconds")
|
930
|
-
sleep(10)
|
931
|
-
continue
|
932
|
-
if response.status_code not in (200, 429):
|
933
|
-
raise Exception(f"Error listing deployment pipelines: {response.status_code}, {response.text}")
|
934
|
-
break
|
935
|
-
|
936
|
-
resp_dict = json.loads(response.text)
|
937
|
-
items = resp_dict["value"]
|
938
|
-
|
939
|
-
dep_pipes = [DeploymentPipeline.from_dict(i, auth=self.auth) for i in items]
|
940
|
-
|
941
|
-
if "continuationToken" in resp_dict:
|
942
|
-
dep_pipes_next = self.list_deployment_pipelines(continuationToken=resp_dict["continuationToken"])
|
943
|
-
dep_pipes.extend(dep_pipes_next)
|
2485
|
+
from msfabricpysdkcore.spark_custom_pool import SparkCustomPool
|
944
2486
|
|
945
|
-
|
2487
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/pools/{pool_id}"
|
2488
|
+
response_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2489
|
+
error_message="Error getting workspace custom pool", return_format="json")
|
2490
|
+
response_dict["workspaceId"] = workspace_id
|
2491
|
+
return SparkCustomPool.from_dict(response_dict, core_client=self)
|
946
2492
|
|
947
|
-
def
|
948
|
-
"""
|
2493
|
+
def delete_workspace_custom_pool(self, workspace_id, pool_id):
|
2494
|
+
"""Delete a workspace custom pool
|
949
2495
|
Args:
|
950
|
-
|
2496
|
+
workspace_id (str): The ID of the workspace
|
2497
|
+
pool_id (str): The ID of the pool
|
951
2498
|
Returns:
|
952
|
-
|
2499
|
+
int: The status code of the response
|
953
2500
|
"""
|
954
|
-
|
2501
|
+
|
2502
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/pools/{pool_id}"
|
2503
|
+
|
2504
|
+
response = self.calling_routine(url, operation="DELETE", response_codes=[200, 429],
|
2505
|
+
error_message="Error deleting workspace custom pool", return_format="response")
|
2506
|
+
|
2507
|
+
return response.status_code
|
955
2508
|
|
956
|
-
def
|
957
|
-
"""
|
2509
|
+
def list_workspace_custom_pools(self, workspace_id):
|
2510
|
+
"""List workspace custom pools
|
958
2511
|
Args:
|
959
|
-
|
960
|
-
stage_id (str): The ID of the deployment stage
|
961
|
-
stage_name (str): The name of the deployment stage
|
2512
|
+
workspace_id (str): The ID of the workspace
|
962
2513
|
Returns:
|
963
|
-
list:
|
2514
|
+
list: The list of custom pools
|
964
2515
|
"""
|
965
|
-
|
966
|
-
return pipeline.get_deployment_pipeline_stages_items(stage_id, stage_name)
|
2516
|
+
from msfabricpysdkcore.spark_custom_pool import SparkCustomPool
|
967
2517
|
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
return
|
2518
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/pools"
|
2519
|
+
|
2520
|
+
items = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2521
|
+
error_message="Error listing workspace custom pools", return_format="json", paging=True)
|
2522
|
+
for item in items:
|
2523
|
+
item["workspaceId"] = workspace_id
|
2524
|
+
sppools = [SparkCustomPool.from_dict(item, core_client=self) for item in items]
|
2525
|
+
|
2526
|
+
return sppools
|
977
2527
|
|
978
|
-
def
|
979
|
-
|
2528
|
+
def update_workspace_custom_pool(self, workspace_id, pool_id, name = None, node_family = None, node_size = None, auto_scale = None, dynamic_executor_allocation = None,
|
2529
|
+
return_item = "Default"):
|
2530
|
+
"""Update a workspace custom pool
|
980
2531
|
Args:
|
981
|
-
|
2532
|
+
workspace_id (str): The ID of the workspace
|
2533
|
+
pool_id (str): The ID of the pool
|
2534
|
+
name (str): The name of the pool
|
2535
|
+
node_family (str): The node family
|
2536
|
+
node_size (str): The node size
|
2537
|
+
auto_scale (bool): Whether to auto scale
|
2538
|
+
dynamic_executor_allocation (bool): Whether to use dynamic executor allocation
|
982
2539
|
Returns:
|
983
|
-
|
2540
|
+
int: The status code of the response
|
984
2541
|
"""
|
985
|
-
|
986
|
-
|
2542
|
+
|
2543
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/pools/{pool_id}"
|
2544
|
+
body = {}
|
2545
|
+
|
2546
|
+
if name is not None:
|
2547
|
+
body['name'] = name
|
2548
|
+
if node_family is not None:
|
2549
|
+
body['nodeFamily'] = node_family
|
2550
|
+
if node_size is not None:
|
2551
|
+
body['nodeSize'] = node_size
|
2552
|
+
if auto_scale is not None:
|
2553
|
+
body['autoScale'] = auto_scale
|
2554
|
+
if dynamic_executor_allocation is not None:
|
2555
|
+
body['dynamicExecutorAllocation'] = dynamic_executor_allocation
|
2556
|
+
|
2557
|
+
if not body:
|
2558
|
+
return None
|
2559
|
+
|
2560
|
+
response_json = self.calling_routine(url, operation="PATCH", body=body, response_codes=[200, 429],
|
2561
|
+
error_message="Error updating workspace custom pool", return_format="json")
|
2562
|
+
|
2563
|
+
if return_item == "Default":
|
2564
|
+
print("""Warning: Updating an item currently will make invoke an additional API call to get the item object.
|
2565
|
+
This default behaviour will change in newer versions of the SDK.
|
2566
|
+
To keep this behaviour, set return_item=True in the function call.""")
|
2567
|
+
if return_item:
|
2568
|
+
return self.get_workspace_custom_pool(workspace_id, pool_id)
|
2569
|
+
return response_json
|
987
2570
|
|
988
2571
|
# Spark workspace settings
|
989
2572
|
|
@@ -992,9 +2575,14 @@ class FabricClientCore(FabricClient):
|
|
992
2575
|
Args:
|
993
2576
|
workspace_id (str): The ID of the workspace
|
994
2577
|
Returns:
|
995
|
-
dict: The spark settings
|
996
|
-
|
997
|
-
|
2578
|
+
dict: The spark settings
|
2579
|
+
"""
|
2580
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/settings"
|
2581
|
+
|
2582
|
+
response_json = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2583
|
+
error_message="Error getting spark settings", return_format="json")
|
2584
|
+
|
2585
|
+
return response_json
|
998
2586
|
|
999
2587
|
def update_spark_settings(self, workspace_id, automatic_log = None,
|
1000
2588
|
environment = None, high_concurrency = None, pool = None):
|
@@ -1006,54 +2594,214 @@ class FabricClientCore(FabricClient):
|
|
1006
2594
|
high_concurrency (bool): Whether to use high concurrency
|
1007
2595
|
pool (str): The pool
|
1008
2596
|
Returns:
|
1009
|
-
dict: The updated spark settings
|
1010
|
-
|
1011
|
-
return ws.update_spark_settings(automatic_log=automatic_log,
|
1012
|
-
environment=environment,
|
1013
|
-
high_concurrency=high_concurrency,
|
1014
|
-
pool=pool)
|
1015
|
-
|
2597
|
+
dict: The updated spark settings
|
2598
|
+
"""
|
1016
2599
|
|
1017
|
-
|
2600
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/spark/settings"
|
1018
2601
|
|
1019
|
-
|
2602
|
+
body = {}
|
1020
2603
|
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
2604
|
+
if automatic_log:
|
2605
|
+
body["automaticLog"] = automatic_log
|
2606
|
+
if environment:
|
2607
|
+
body["environment"] = environment
|
2608
|
+
if high_concurrency:
|
2609
|
+
body["highConcurrency"] = high_concurrency
|
2610
|
+
if pool:
|
2611
|
+
body["pool"] = pool
|
1024
2612
|
|
1025
|
-
|
2613
|
+
response_json = self.calling_routine(url, operation="PATCH", body=body, response_codes=[200, 429],
|
2614
|
+
error_message="Error updating spark settings", return_format="json")
|
1026
2615
|
|
1027
|
-
|
1028
|
-
ws = self.get_workspace_by_id(workspace_id)
|
1029
|
-
return ws.get_external_data_share(item_id=item_id, external_data_share_id=external_data_share_id)
|
2616
|
+
return response_json
|
1030
2617
|
|
1031
|
-
#
|
2618
|
+
# sparkJobDefinitions
|
1032
2619
|
|
1033
|
-
def
|
1034
|
-
|
1035
|
-
|
2620
|
+
def create_spark_job_definition(self, workspace_id, display_name, definition = None, description = None):
|
2621
|
+
"""Create a spark job definition in a workspace
|
2622
|
+
Args:
|
2623
|
+
workspace_id (str): The ID of the workspace
|
2624
|
+
display_name (str): The display name of the spark job definition
|
2625
|
+
definition (dict): The definition of the spark job definition
|
2626
|
+
description (str): The description of the spark job definition
|
2627
|
+
Returns:
|
2628
|
+
dict: The created spark job definition
|
2629
|
+
"""
|
2630
|
+
return self.create_item(workspace_id = workspace_id, display_name = display_name, type = "sparkJobDefinitions", definition = definition, description = description)
|
2631
|
+
|
2632
|
+
def delete_spark_job_definition(self, workspace_id, spark_job_definition_id):
|
2633
|
+
"""Delete a spark job definition from a workspace
|
2634
|
+
Args:
|
2635
|
+
workspace_id (str): The ID of the workspace
|
2636
|
+
spark_job_definition_id (str): The ID of the spark job definition
|
2637
|
+
Returns:
|
2638
|
+
int: The status code of the response
|
2639
|
+
"""
|
2640
|
+
return self.delete_item(workspace_id, spark_job_definition_id, type="sparkJobDefinitions")
|
1036
2641
|
|
1037
|
-
|
2642
|
+
def get_spark_job_definition(self, workspace_id, spark_job_definition_id = None, spark_job_definition_name = None):
|
2643
|
+
"""Get a spark job definition from a workspace
|
2644
|
+
Args:
|
2645
|
+
workspace_id (str): The ID of the workspace
|
2646
|
+
spark_job_definition_id (str): The ID of the spark job definition
|
2647
|
+
spark_job_definition_name (str): The name of the spark job definition
|
2648
|
+
Returns:
|
2649
|
+
SparkJobDefinition: The spark job definition object
|
2650
|
+
"""
|
2651
|
+
from msfabricpysdkcore.otheritems import SparkJobDefinition
|
2652
|
+
if spark_job_definition_id is None and spark_job_definition_name is not None:
|
2653
|
+
spark_job_definitions = self.list_spark_job_definitions(workspace_id)
|
2654
|
+
spark_job_definitions = [sjd for sjd in spark_job_definitions if sjd.display_name == spark_job_definition_name]
|
2655
|
+
if len(spark_job_definitions) == 0:
|
2656
|
+
raise Exception(f"Spark job definition with name {spark_job_definition_name} not found")
|
2657
|
+
spark_job_definition_id = spark_job_definitions[0].id
|
2658
|
+
elif spark_job_definition_id is None:
|
2659
|
+
raise Exception("spark_job_definition_id or the spark_job_definition_name is required")
|
2660
|
+
|
2661
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/sparkjobdefinitions/{spark_job_definition_id}"
|
1038
2662
|
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
2663
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2664
|
+
error_message="Error getting spark job definition", return_format="json")
|
2665
|
+
|
2666
|
+
sjd_obj = SparkJobDefinition.from_dict(item_dict, core_client=self)
|
2667
|
+
sjd_obj.get_definition()
|
2668
|
+
return sjd_obj
|
2669
|
+
|
2670
|
+
def list_spark_job_definitions(self, workspace_id, with_properties = False):
|
2671
|
+
"""List spark job definitions in a workspace
|
2672
|
+
Args:
|
2673
|
+
workspace_id (str): The ID of the workspace
|
2674
|
+
with_properties (bool): Whether to get the item object with properties
|
2675
|
+
Returns:
|
2676
|
+
list: The list of spark job definitions
|
2677
|
+
"""
|
2678
|
+
return self.list_items(workspace_id = workspace_id, type = "sparkJobDefinitions", with_properties = with_properties)
|
2679
|
+
|
2680
|
+
def update_spark_job_definition(self, workspace_id, spark_job_definition_id, display_name = None, description = None, return_item="Default"):
|
2681
|
+
"""Update a spark job definition in a workspace
|
2682
|
+
Args:
|
2683
|
+
workspace_id (str): The ID of the workspace
|
2684
|
+
spark_job_definition_id (str): The ID of the spark job definition
|
2685
|
+
display_name (str): The display name of the spark job definition
|
2686
|
+
description (str): The description of the spark job definition
|
2687
|
+
Returns:
|
2688
|
+
dict: The updated spark job definition
|
2689
|
+
"""
|
2690
|
+
return self.update_item(workspace_id, spark_job_definition_id, display_name = display_name, description = description,
|
2691
|
+
type="sparkJobDefinitions", return_item=return_item)
|
1042
2692
|
|
2693
|
+
def get_spark_job_definition_definition(self, workspace_id, spark_job_definition_id, format = None):
|
2694
|
+
"""Get the definition of a spark job definition
|
2695
|
+
Args:
|
2696
|
+
workspace_id (str): The ID of the workspace
|
2697
|
+
spark_job_definition_id (str): The ID of the spark job definition
|
2698
|
+
format (str): The format of the definition
|
2699
|
+
Returns:
|
2700
|
+
dict: The definition of the spark job definition
|
2701
|
+
"""
|
2702
|
+
return self.get_item_definition(workspace_id, spark_job_definition_id, type="sparkJobDefinitions", format=format)
|
1043
2703
|
|
1044
|
-
|
2704
|
+
def update_spark_job_definition_definition(self, workspace_id, spark_job_definition_id, definition):
|
2705
|
+
"""Update the definition of a spark job definition
|
2706
|
+
Args:
|
2707
|
+
workspace_id (str): The ID of the workspace
|
2708
|
+
spark_job_definition_id (str): The ID of the spark job definition
|
2709
|
+
definition (dict): The definition of the spark job definition
|
2710
|
+
Returns:
|
2711
|
+
dict: The updated spark job definition
|
2712
|
+
"""
|
2713
|
+
return self.update_item_definition(workspace_id, spark_job_definition_id, definition, type="sparkJobDefinitions")
|
2714
|
+
|
2715
|
+
def run_on_demand_spark_job_definition(self, workspace_id, spark_job_definition_id, job_type = "sparkjob"):
|
2716
|
+
"""Run an on demand spark job definition
|
2717
|
+
Args:
|
2718
|
+
workspace_id (str): The ID of the workspace
|
2719
|
+
spark_job_definition_id (str): The ID of the spark job definition
|
2720
|
+
job_type (str): The job type
|
2721
|
+
Returns:
|
2722
|
+
dict: The job instance
|
2723
|
+
"""
|
2724
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/sparkJobDefinitions/{spark_job_definition_id}/jobs/instances?jobType={job_type}"
|
1045
2725
|
|
1046
|
-
|
2726
|
+
response = self.calling_routine(url, operation="POST", response_codes=[202, 429], wait_for_completion = False,
|
2727
|
+
error_message="Error running on demand spark job definition", return_format="response")
|
2728
|
+
|
2729
|
+
location = response.headers['Location']
|
2730
|
+
job_instance_id = location.split('/')[-1]
|
2731
|
+
|
2732
|
+
return self.get_item_job_instance(workspace_id = workspace_id,
|
2733
|
+
item_id = spark_job_definition_id,
|
2734
|
+
job_instance_id = job_instance_id)
|
1047
2735
|
|
1048
|
-
def create_or_update_data_access_roles(self, workspace_id, item_id, data_access_roles, dryrun = False, etag_match = None):
|
1049
|
-
ws = self.get_workspace_by_id(workspace_id)
|
1050
|
-
item = ws.get_item(item_id=item_id).create_or_update_data_access_roles(data_access_roles = data_access_roles,
|
1051
|
-
dryrun = dryrun, etag_match = etag_match)
|
1052
|
-
return item
|
1053
2736
|
|
1054
|
-
#
|
2737
|
+
# warehouses
|
1055
2738
|
|
1056
|
-
def
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
2739
|
+
def create_warehouse(self, workspace_id, display_name, description = None):
|
2740
|
+
"""Create a warehouse in a workspace
|
2741
|
+
Args:
|
2742
|
+
workspace_id (str): The ID of the workspace
|
2743
|
+
display_name (str): The display name of the warehouse
|
2744
|
+
description (str): The description of the warehouse
|
2745
|
+
Returns:
|
2746
|
+
dict: The created warehouse
|
2747
|
+
"""
|
2748
|
+
return self.create_item(workspace_id = workspace_id, display_name = display_name, type = "warehouses", description = description)
|
2749
|
+
|
2750
|
+
def delete_warehouse(self, workspace_id, warehouse_id):
|
2751
|
+
"""Delete a warehouse from a workspace
|
2752
|
+
Args:
|
2753
|
+
workspace_id (str): The ID of the workspace
|
2754
|
+
warehouse_id (str): The ID of the warehouse
|
2755
|
+
Returns:
|
2756
|
+
int: The status code of the response
|
2757
|
+
"""
|
2758
|
+
return self.delete_item(workspace_id, warehouse_id, type="warehouses")
|
2759
|
+
|
2760
|
+
def get_warehouse(self, workspace_id, warehouse_id = None, warehouse_name = None):
|
2761
|
+
"""Get a warehouse from a workspace
|
2762
|
+
Args:
|
2763
|
+
workspace_id (str): The ID of the workspace
|
2764
|
+
warehouse_id (str): The ID of the warehouse
|
2765
|
+
warehouse_name (str): The name of the warehouse
|
2766
|
+
Returns:
|
2767
|
+
Warehouse: The warehouse object
|
2768
|
+
"""
|
2769
|
+
from msfabricpysdkcore.otheritems import Warehouse
|
2770
|
+
if warehouse_id is None and warehouse_name is not None:
|
2771
|
+
warehouses = self.list_warehouses(workspace_id)
|
2772
|
+
warehouses = [wh for wh in warehouses if wh.display_name == warehouse_name]
|
2773
|
+
if len(warehouses) == 0:
|
2774
|
+
raise Exception(f"Warehouse with name {warehouse_name} not found")
|
2775
|
+
warehouse_id = warehouses[0].id
|
2776
|
+
if warehouse_id is None:
|
2777
|
+
raise Exception("warehouse_id or the warehouse_name is required")
|
2778
|
+
|
2779
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/warehouses/{warehouse_id}"
|
2780
|
+
|
2781
|
+
item_dict = self.calling_routine(url, operation="GET", response_codes=[200, 429],
|
2782
|
+
error_message="Error getting warehouse", return_format="json")
|
2783
|
+
|
2784
|
+
return Warehouse.from_dict(item_dict, core_client=self)
|
2785
|
+
|
2786
|
+
def list_warehouses(self, workspace_id, with_properties = False):
|
2787
|
+
"""List warehouses in a workspace
|
2788
|
+
Args:
|
2789
|
+
workspace_id (str): The ID of the workspace
|
2790
|
+
with_properties (bool): Whether to get the item object with properties
|
2791
|
+
Returns:
|
2792
|
+
list: The list of warehouses
|
2793
|
+
"""
|
2794
|
+
return self.list_items(workspace_id = workspace_id, type = "warehouses", with_properties = with_properties)
|
2795
|
+
|
2796
|
+
def update_warehouse(self, workspace_id, warehouse_id, display_name = None, description = None, return_item="Default"):
|
2797
|
+
"""Update a warehouse in a workspace
|
2798
|
+
Args:
|
2799
|
+
workspace_id (str): The ID of the workspace
|
2800
|
+
warehouse_id (str): The ID of the warehouse
|
2801
|
+
display_name (str): The display name of the warehouse
|
2802
|
+
description (str): The description of the warehouse
|
2803
|
+
Returns:
|
2804
|
+
dict: The updated warehouse
|
2805
|
+
"""
|
2806
|
+
return self.update_item(workspace_id, warehouse_id, display_name = display_name, description = description,
|
2807
|
+
type="warehouses", return_item=return_item)
|