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