msfabricpysdkcore 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msfabricpysdkcore/__init__.py +2 -1
- msfabricpysdkcore/admin_item.py +106 -0
- msfabricpysdkcore/admin_workspace.py +127 -0
- msfabricpysdkcore/adminapi.py +535 -0
- msfabricpysdkcore/capacity.py +3 -0
- msfabricpysdkcore/client.py +4 -318
- msfabricpysdkcore/coreapi.py +324 -0
- msfabricpysdkcore/domain.py +378 -0
- msfabricpysdkcore/item.py +3 -0
- msfabricpysdkcore/job_instance.py +3 -0
- msfabricpysdkcore/onelakeshortcut.py +3 -0
- msfabricpysdkcore/tests/test_admin_apis.py +69 -0
- msfabricpysdkcore/tests/test_domains.py +125 -0
- msfabricpysdkcore/tests/test_git.py +1 -1
- msfabricpysdkcore/tests/test_items_incl_lakehouse.py +1 -1
- msfabricpysdkcore/tests/test_jobs.py +1 -3
- msfabricpysdkcore/tests/test_shortcuts.py +1 -1
- msfabricpysdkcore/tests/test_workspaces_capacities.py +1 -1
- msfabricpysdkcore/workspace.py +3 -0
- {msfabricpysdkcore-0.0.3.dist-info → msfabricpysdkcore-0.0.4.dist-info}/METADATA +163 -15
- msfabricpysdkcore-0.0.4.dist-info/RECORD +28 -0
- msfabricpysdkcore-0.0.3.dist-info/RECORD +0 -21
- {msfabricpysdkcore-0.0.3.dist-info → msfabricpysdkcore-0.0.4.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.3.dist-info → msfabricpysdkcore-0.0.4.dist-info}/WHEEL +0 -0
- {msfabricpysdkcore-0.0.3.dist-info → msfabricpysdkcore-0.0.4.dist-info}/top_level.txt +0 -0
msfabricpysdkcore/client.py
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
import requests
|
2
|
-
import json
|
3
1
|
import os
|
4
2
|
from time import sleep
|
5
3
|
|
6
|
-
from msfabricpysdkcore.capacity import Capacity
|
7
|
-
from msfabricpysdkcore.workspace import Workspace
|
8
4
|
from msfabricpysdkcore.auth import FabricAuthClient, FabricServicePrincipal
|
9
5
|
|
10
|
-
class
|
11
|
-
"""
|
6
|
+
class FabricClient():
|
7
|
+
"""FabricClient class to interact with Fabric API"""
|
12
8
|
|
13
9
|
def __init__(self, tenant_id = None, client_id = None, client_secret = None) -> None:
|
14
|
-
"""Initialize
|
10
|
+
"""Initialize FabricClient object"""
|
15
11
|
self.tenant_id = tenant_id if tenant_id else os.getenv("FABRIC_TENANT_ID")
|
16
12
|
self.client_id = client_id if client_id else os.getenv("FABRIC_CLIENT_ID")
|
17
13
|
self.client_secret = client_secret if client_secret else os.getenv("FABRIC_CLIENT_SECRET")
|
@@ -23,314 +19,4 @@ class FabricClientCore():
|
|
23
19
|
client_id = self.client_id,
|
24
20
|
client_secret = self.client_secret)
|
25
21
|
|
26
|
-
self.scope = "https://api.fabric.microsoft.com/.default"
|
27
|
-
|
28
|
-
|
29
|
-
def list_workspaces(self, continuationToken = None):
|
30
|
-
"""List all workspaces in the tenant"""
|
31
|
-
|
32
|
-
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
33
|
-
if continuationToken:
|
34
|
-
url = f"{url}?continuationToken={continuationToken}"
|
35
|
-
|
36
|
-
for _ in range(10):
|
37
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
38
|
-
if response.status_code == 429:
|
39
|
-
print("Too many requests, waiting 10 seconds")
|
40
|
-
sleep(10)
|
41
|
-
continue
|
42
|
-
if response.status_code not in (200, 429):
|
43
|
-
print(response.status_code)
|
44
|
-
print(response.text)
|
45
|
-
raise Exception(f"Error listing workspaces: {response.status_code}, {response.text}")
|
46
|
-
break
|
47
|
-
resp_dict = json.loads(response.text)
|
48
|
-
ws_list = resp_dict["value"]
|
49
|
-
ws_list = [Workspace.from_dict(ws, auth=self.auth) for ws in ws_list]
|
50
|
-
|
51
|
-
if "continuationToken" in resp_dict:
|
52
|
-
ws_list_next = self.list_workspaces(continuationToken=resp_dict["continuationToken"])
|
53
|
-
ws_list.extend(ws_list_next)
|
54
|
-
|
55
|
-
return ws_list
|
56
|
-
|
57
|
-
def get_workspace_by_name(self, name):
|
58
|
-
"""Get workspace by name"""
|
59
|
-
ws_list = self.list_workspaces()
|
60
|
-
for ws in ws_list:
|
61
|
-
if ws.display_name == name:
|
62
|
-
return ws
|
63
|
-
|
64
|
-
def get_workspace_by_id(self, id):
|
65
|
-
"""Get workspace by id"""
|
66
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{id}"
|
67
|
-
|
68
|
-
|
69
|
-
for _ in range(10):
|
70
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
71
|
-
if response.status_code == 429:
|
72
|
-
print("Too many requests, waiting 10 seconds")
|
73
|
-
sleep(10)
|
74
|
-
continue
|
75
|
-
if response.status_code not in (200, 429):
|
76
|
-
print(response.status_code)
|
77
|
-
print(response.text)
|
78
|
-
raise Exception(f"Error getting workspace: {response.status_code} {response.text}")
|
79
|
-
break
|
80
|
-
ws_dict = json.loads(response.text)
|
81
|
-
ws = Workspace.from_dict(ws_dict, auth=self.auth)
|
82
|
-
|
83
|
-
return ws
|
84
|
-
|
85
|
-
|
86
|
-
def get_workspace(self, id = None, name = None):
|
87
|
-
"""Get workspace by id or name"""
|
88
|
-
if id:
|
89
|
-
return self.get_workspace_by_id(id)
|
90
|
-
if name:
|
91
|
-
return self.get_workspace_by_name(name)
|
92
|
-
raise ValueError("Either id or name must be provided")
|
93
|
-
|
94
|
-
def get_workspace_role_assignments(self, workspace_id):
|
95
|
-
"""Get role assignments for a workspace"""
|
96
|
-
ws = self.get_workspace_by_id(workspace_id)
|
97
|
-
return ws.get_role_assignments()
|
98
|
-
|
99
|
-
def create_workspace(self, display_name, capacity_id = None, description = None, exists_ok = True):
|
100
|
-
"""Create a workspace"""
|
101
|
-
body = dict()
|
102
|
-
body["displayName"] = display_name
|
103
|
-
if capacity_id:
|
104
|
-
body["capacityId"] = capacity_id
|
105
|
-
if description:
|
106
|
-
body["description"] = description
|
107
|
-
|
108
|
-
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
109
|
-
|
110
|
-
for _ in range(10):
|
111
|
-
response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
|
112
|
-
if response.status_code == 429:
|
113
|
-
print("Too many requests, waiting 10 seconds")
|
114
|
-
sleep(10)
|
115
|
-
continue
|
116
|
-
ws_dict = json.loads(response.text)
|
117
|
-
if response.status_code not in (201, 429):
|
118
|
-
if "errorCode" in ws_dict and ws_dict["errorCode"] == "WorkspaceNameAlreadyExists" and exists_ok:
|
119
|
-
return self.get_workspace_by_name(display_name)
|
120
|
-
else:
|
121
|
-
print(response.status_code)
|
122
|
-
print(response.text)
|
123
|
-
raise Exception(f"Error creating workspace: {response.text}")
|
124
|
-
break
|
125
|
-
|
126
|
-
ws = Workspace.from_dict(ws_dict, auth=self.auth)
|
127
|
-
return ws
|
128
|
-
|
129
|
-
def delete_workspace(self, workspace_id = None, display_name = None):
|
130
|
-
"""Delete a workspace"""
|
131
|
-
if workspace_id is None and display_name is None:
|
132
|
-
raise ValueError("Either workspace_id or display_name must be provided")
|
133
|
-
ws = self.get_workspace(id = workspace_id, name = display_name)
|
134
|
-
reponse = ws.delete()
|
135
|
-
return reponse
|
136
|
-
|
137
|
-
def add_workspace_role_assignment(self, workspace_id, role, principal):
|
138
|
-
"""Add a role assignment to a workspace"""
|
139
|
-
ws = self.get_workspace_by_id(workspace_id)
|
140
|
-
return ws.add_role_assignment(role, principal)
|
141
|
-
|
142
|
-
def delete_workspace_role_assignment(self, workspace_id, principal_id):
|
143
|
-
"""Delete a role assignment from a workspace"""
|
144
|
-
ws = self.get_workspace_by_id(workspace_id)
|
145
|
-
return ws.delete_role_assignment(principal_id)
|
146
|
-
|
147
|
-
def update_workspace(self, workspace_id, display_name = None, description = None):
|
148
|
-
"""Update a workspace"""
|
149
|
-
ws = self.get_workspace_by_id(workspace_id)
|
150
|
-
return ws.update(display_name, description)
|
151
|
-
|
152
|
-
def update_workspace_role_assignment(self, workspace_id, role, principal_id):
|
153
|
-
"""Update a role assignment for a workspace"""
|
154
|
-
ws = self.get_workspace_by_id(workspace_id)
|
155
|
-
return ws.update_role_assignment(role, principal_id)
|
156
|
-
|
157
|
-
def assign_to_capacity(self, workspace_id, capacity_id):
|
158
|
-
"""Assign a workspace to a capacity"""
|
159
|
-
ws = self.get_workspace_by_id(workspace_id)
|
160
|
-
return ws.assign_to_capacity(capacity_id)
|
161
|
-
|
162
|
-
def unassign_from_capacity(self, workspace_id):
|
163
|
-
"""Unassign a workspace from a capacity"""
|
164
|
-
ws = self.get_workspace_by_id(workspace_id)
|
165
|
-
return ws.unassign_from_capacity()
|
166
|
-
|
167
|
-
def list_capacities(self, continuationToken = None):
|
168
|
-
"""List all capacities in the tenant"""
|
169
|
-
url = "https://api.fabric.microsoft.com/v1/capacities"
|
170
|
-
|
171
|
-
if continuationToken:
|
172
|
-
url = f"{url}?continuationToken={continuationToken}"
|
173
|
-
|
174
|
-
for _ in range(10):
|
175
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
176
|
-
if response.status_code == 429:
|
177
|
-
print("Too many requests, waiting 10 seconds")
|
178
|
-
sleep(10)
|
179
|
-
continue
|
180
|
-
if response.status_code not in (200, 429):
|
181
|
-
print(response.status_code)
|
182
|
-
print(response.text)
|
183
|
-
raise Exception(f"Error listing capacities: {response.text}")
|
184
|
-
break
|
185
|
-
|
186
|
-
resp_dict = json.loads(response.text)
|
187
|
-
items = resp_dict["value"]
|
188
|
-
|
189
|
-
if "continuationToken" in resp_dict:
|
190
|
-
cap_list_next = self.list_capacities(continuationToken=resp_dict["continuationToken"])
|
191
|
-
items.extend(cap_list_next)
|
192
|
-
|
193
|
-
items = json.loads(response.text)["value"]
|
194
|
-
items = [Capacity.from_dict(i) for i in items]
|
195
|
-
return items
|
196
|
-
|
197
|
-
|
198
|
-
def create_item(self, workspace_id, display_name, type, definition = None, description = None):
|
199
|
-
"""Create an item in a workspace"""
|
200
|
-
ws = self.get_workspace_by_id(workspace_id)
|
201
|
-
|
202
|
-
return ws.create_item(display_name = display_name,
|
203
|
-
type = type,
|
204
|
-
definition = definition,
|
205
|
-
description = description)
|
206
|
-
|
207
|
-
def get_item(self, workspace_id = None,
|
208
|
-
item_id = None, workspace_name = None, item_name = None, item_type = None):
|
209
|
-
"""Get an item from a workspace"""
|
210
|
-
ws = self.get_workspace(id = workspace_id, name = workspace_name)
|
211
|
-
return ws.get_item(item_id = item_id, item_name = item_name, item_type = item_type)
|
212
|
-
|
213
|
-
def delete_item(self, workspace_id, item_id):
|
214
|
-
"""Delete an item from a workspace"""
|
215
|
-
ws = self.get_workspace_by_id(workspace_id)
|
216
|
-
return ws.delete_item(item_id)
|
217
|
-
|
218
|
-
def list_items(self, workspace_id):
|
219
|
-
"""List items in a workspace"""
|
220
|
-
ws = self.get_workspace_by_id(workspace_id)
|
221
|
-
return ws.list_items()
|
222
|
-
|
223
|
-
def get_item_definition(self, workspace_id, item_id):
|
224
|
-
"""Get the definition of an item"""
|
225
|
-
ws = self.get_workspace_by_id(workspace_id)
|
226
|
-
return ws.get_item_definition(item_id)
|
227
|
-
|
228
|
-
def update_item(self, workspace_id, item_id, display_name = None, description = None):
|
229
|
-
"""Update an item in a workspace"""
|
230
|
-
ws = self.get_workspace_by_id(workspace_id)
|
231
|
-
return ws.get_item(item_id).update(display_name, description)
|
232
|
-
|
233
|
-
def update_item_definition(self, workspace_id, item_id, definition):
|
234
|
-
"""Update the definition of an item"""
|
235
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
236
|
-
return ws.get_item(item_id=item_id).update_definition(definition=definition)
|
237
|
-
|
238
|
-
def create_shortcut(self, workspace_id, item_id, path, name, target):
|
239
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
240
|
-
return ws.get_item(item_id=item_id).create_shortcut(path=path, name=name, target=target)
|
241
|
-
|
242
|
-
def get_shortcut(self, workspace_id, item_id, path, name):
|
243
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
244
|
-
return ws.get_item(item_id=item_id).get_shortcut(path=path, name=name)
|
245
|
-
|
246
|
-
def delete_shortcut(self, workspace_id, item_id, path, name):
|
247
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
248
|
-
return ws.get_item(item_id=item_id).delete_shortcut(path=path, name=name)
|
249
|
-
|
250
|
-
def get_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
251
|
-
"""Get a job instance for an item"""
|
252
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
253
|
-
return ws.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id)
|
254
|
-
|
255
|
-
def run_on_demand_item_job(self, workspace_id, item_id, job_type, execution_data = None):
|
256
|
-
"""Run an on demand job for an item"""
|
257
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
258
|
-
return ws.get_item(item_id=item_id).run_on_demand_item_job(job_type=job_type, execution_data=execution_data)
|
259
|
-
|
260
|
-
def cancel_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
261
|
-
"""Cancel a job instance for an item"""
|
262
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
263
|
-
return ws.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id).cancel()
|
264
|
-
|
265
|
-
def commit_to_git(self, workspace_id,mode, comment=None, items=None, workspace_head=None):
|
266
|
-
"""Commit changes to git"""
|
267
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
268
|
-
return ws.commit_to_git(mode=mode, comment=comment, items=items, workspace_head=workspace_head)
|
269
|
-
|
270
|
-
def git_connect(self, workspace_id, git_provider_details):
|
271
|
-
"""Connect to git"""
|
272
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
273
|
-
return ws.git_connect(git_provider_details=git_provider_details)
|
274
|
-
|
275
|
-
def git_disconnect(self, workspace_id):
|
276
|
-
"""Disconnect from git"""
|
277
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
278
|
-
return ws.git_disconnect()
|
279
|
-
|
280
|
-
def git_get_connection(self, workspace_id):
|
281
|
-
"""Get git connection details"""
|
282
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
283
|
-
return ws.git_get_connection()
|
284
|
-
|
285
|
-
def git_get_status(self, workspace_id):
|
286
|
-
"""Get git status"""
|
287
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
288
|
-
return ws.git_get_status()
|
289
|
-
|
290
|
-
def git_initialize_connection(self, workspace_id, initialization_strategy):
|
291
|
-
"""Initialize git"""
|
292
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
293
|
-
return ws.git_initialize_connection(initialization_strategy=initialization_strategy)
|
294
|
-
|
295
|
-
def update_from_git(self, workspace_id, remote_commit_hash, conflict_resolution = None, options = None, workspace_head = None):
|
296
|
-
"""Update workspace from git"""
|
297
|
-
ws = self.get_workspace_by_id(id=workspace_id)
|
298
|
-
return ws.update_from_git(remote_commit_hash=remote_commit_hash,
|
299
|
-
conflict_resolution=conflict_resolution,
|
300
|
-
options=options,
|
301
|
-
workspace_head=workspace_head)
|
302
|
-
|
303
|
-
def get_capacity(self, capacity_id = None, capacity_name = None):
|
304
|
-
"""Get a capacity
|
305
|
-
|
306
|
-
Args:
|
307
|
-
capacity_id (str): The ID of the capacity
|
308
|
-
capacity_name (str): The name of the capacity
|
309
|
-
|
310
|
-
Returns:
|
311
|
-
Capacity: The capacity object
|
312
|
-
|
313
|
-
Raises:
|
314
|
-
ValueError: If no capacity is found
|
315
|
-
"""
|
316
|
-
if capacity_id is None and capacity_name is None:
|
317
|
-
raise ValueError("Either capacity_id or capacity_name must be provided")
|
318
|
-
caps = self.list_capacities()
|
319
|
-
for cap in caps:
|
320
|
-
if capacity_id and cap.id == capacity_id:
|
321
|
-
return cap
|
322
|
-
if capacity_name and cap.display_name == capacity_name:
|
323
|
-
return cap
|
324
|
-
raise ValueError("No capacity found")
|
325
|
-
|
326
|
-
def list_tables(self, workspace_id, item_id):
|
327
|
-
ws = self.get_workspace_by_id(workspace_id)
|
328
|
-
return ws.list_tables(item_id=item_id)
|
329
|
-
|
330
|
-
def load_table(self, workspace_id, item_id, table_name, path_type, relative_path,
|
331
|
-
file_extension = None, format_options = None,
|
332
|
-
mode = None, recursive = None, wait_for_completion = True):
|
333
|
-
ws = self.get_workspace_by_id(workspace_id)
|
334
|
-
return ws.load_table(item_id, table_name, path_type, relative_path,
|
335
|
-
file_extension, format_options,
|
336
|
-
mode, recursive, wait_for_completion)
|
22
|
+
self.scope = "https://api.fabric.microsoft.com/.default"
|
@@ -0,0 +1,324 @@
|
|
1
|
+
import requests
|
2
|
+
import json
|
3
|
+
from time import sleep
|
4
|
+
|
5
|
+
from msfabricpysdkcore.capacity import Capacity
|
6
|
+
from msfabricpysdkcore.client import FabricClient
|
7
|
+
from msfabricpysdkcore.workspace import Workspace
|
8
|
+
|
9
|
+
class FabricClientCore(FabricClient):
|
10
|
+
"""FabricClientCore class to interact with Fabric Core APIs"""
|
11
|
+
|
12
|
+
def __init__(self, tenant_id = None, client_id = None, client_secret = None) -> None:
|
13
|
+
"""Initialize FabricClientCore object"""
|
14
|
+
super().__init__(tenant_id, client_id, client_secret)
|
15
|
+
|
16
|
+
|
17
|
+
def list_workspaces(self, continuationToken = None):
|
18
|
+
"""List all workspaces in the tenant"""
|
19
|
+
|
20
|
+
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
21
|
+
if continuationToken:
|
22
|
+
url = f"{url}?continuationToken={continuationToken}"
|
23
|
+
|
24
|
+
for _ in range(10):
|
25
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
26
|
+
if response.status_code == 429:
|
27
|
+
print("Too many requests, waiting 10 seconds")
|
28
|
+
sleep(10)
|
29
|
+
continue
|
30
|
+
if response.status_code not in (200, 429):
|
31
|
+
print(response.status_code)
|
32
|
+
print(response.text)
|
33
|
+
raise Exception(f"Error listing workspaces: {response.status_code}, {response.text}")
|
34
|
+
break
|
35
|
+
resp_dict = json.loads(response.text)
|
36
|
+
ws_list = resp_dict["value"]
|
37
|
+
ws_list = [Workspace.from_dict(ws, auth=self.auth) for ws in ws_list]
|
38
|
+
|
39
|
+
if "continuationToken" in resp_dict:
|
40
|
+
ws_list_next = self.list_workspaces(continuationToken=resp_dict["continuationToken"])
|
41
|
+
ws_list.extend(ws_list_next)
|
42
|
+
|
43
|
+
return ws_list
|
44
|
+
|
45
|
+
def get_workspace_by_name(self, name):
|
46
|
+
"""Get workspace by name"""
|
47
|
+
ws_list = self.list_workspaces()
|
48
|
+
for ws in ws_list:
|
49
|
+
if ws.display_name == name:
|
50
|
+
return ws
|
51
|
+
|
52
|
+
def get_workspace_by_id(self, id):
|
53
|
+
"""Get workspace by id"""
|
54
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{id}"
|
55
|
+
|
56
|
+
|
57
|
+
for _ in range(10):
|
58
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
59
|
+
if response.status_code == 429:
|
60
|
+
print("Too many requests, waiting 10 seconds")
|
61
|
+
sleep(10)
|
62
|
+
continue
|
63
|
+
if response.status_code not in (200, 429):
|
64
|
+
print(response.status_code)
|
65
|
+
print(response.text)
|
66
|
+
raise Exception(f"Error getting workspace: {response.status_code} {response.text}")
|
67
|
+
break
|
68
|
+
ws_dict = json.loads(response.text)
|
69
|
+
ws = Workspace.from_dict(ws_dict, auth=self.auth)
|
70
|
+
|
71
|
+
return ws
|
72
|
+
|
73
|
+
|
74
|
+
def get_workspace(self, id = None, name = None):
|
75
|
+
"""Get workspace by id or name"""
|
76
|
+
if id:
|
77
|
+
return self.get_workspace_by_id(id)
|
78
|
+
if name:
|
79
|
+
return self.get_workspace_by_name(name)
|
80
|
+
raise ValueError("Either id or name must be provided")
|
81
|
+
|
82
|
+
def get_workspace_role_assignments(self, workspace_id):
|
83
|
+
"""Get role assignments for a workspace"""
|
84
|
+
ws = self.get_workspace_by_id(workspace_id)
|
85
|
+
return ws.get_role_assignments()
|
86
|
+
|
87
|
+
def create_workspace(self, display_name, capacity_id = None, description = None, exists_ok = True):
|
88
|
+
"""Create a workspace"""
|
89
|
+
body = dict()
|
90
|
+
body["displayName"] = display_name
|
91
|
+
if capacity_id:
|
92
|
+
body["capacityId"] = capacity_id
|
93
|
+
if description:
|
94
|
+
body["description"] = description
|
95
|
+
|
96
|
+
url = "https://api.fabric.microsoft.com/v1/workspaces"
|
97
|
+
|
98
|
+
for _ in range(10):
|
99
|
+
response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
|
100
|
+
if response.status_code == 429:
|
101
|
+
print("Too many requests, waiting 10 seconds")
|
102
|
+
sleep(10)
|
103
|
+
continue
|
104
|
+
ws_dict = json.loads(response.text)
|
105
|
+
if response.status_code not in (201, 429):
|
106
|
+
if "errorCode" in ws_dict and ws_dict["errorCode"] == "WorkspaceNameAlreadyExists" and exists_ok:
|
107
|
+
return self.get_workspace_by_name(display_name)
|
108
|
+
else:
|
109
|
+
print(response.status_code)
|
110
|
+
print(response.text)
|
111
|
+
raise Exception(f"Error creating workspace: {response.text}")
|
112
|
+
break
|
113
|
+
|
114
|
+
ws = Workspace.from_dict(ws_dict, auth=self.auth)
|
115
|
+
return ws
|
116
|
+
|
117
|
+
def delete_workspace(self, workspace_id = None, display_name = None):
|
118
|
+
"""Delete a workspace"""
|
119
|
+
if workspace_id is None and display_name is None:
|
120
|
+
raise ValueError("Either workspace_id or display_name must be provided")
|
121
|
+
ws = self.get_workspace(id = workspace_id, name = display_name)
|
122
|
+
reponse = ws.delete()
|
123
|
+
return reponse
|
124
|
+
|
125
|
+
def add_workspace_role_assignment(self, workspace_id, role, principal):
|
126
|
+
"""Add a role assignment to a workspace"""
|
127
|
+
ws = self.get_workspace_by_id(workspace_id)
|
128
|
+
return ws.add_role_assignment(role, principal)
|
129
|
+
|
130
|
+
def delete_workspace_role_assignment(self, workspace_id, principal_id):
|
131
|
+
"""Delete a role assignment from a workspace"""
|
132
|
+
ws = self.get_workspace_by_id(workspace_id)
|
133
|
+
return ws.delete_role_assignment(principal_id)
|
134
|
+
|
135
|
+
def update_workspace(self, workspace_id, display_name = None, description = None):
|
136
|
+
"""Update a workspace"""
|
137
|
+
ws = self.get_workspace_by_id(workspace_id)
|
138
|
+
return ws.update(display_name, description)
|
139
|
+
|
140
|
+
def update_workspace_role_assignment(self, workspace_id, role, principal_id):
|
141
|
+
"""Update a role assignment for a workspace"""
|
142
|
+
ws = self.get_workspace_by_id(workspace_id)
|
143
|
+
return ws.update_role_assignment(role, principal_id)
|
144
|
+
|
145
|
+
def assign_to_capacity(self, workspace_id, capacity_id):
|
146
|
+
"""Assign a workspace to a capacity"""
|
147
|
+
ws = self.get_workspace_by_id(workspace_id)
|
148
|
+
return ws.assign_to_capacity(capacity_id)
|
149
|
+
|
150
|
+
def unassign_from_capacity(self, workspace_id):
|
151
|
+
"""Unassign a workspace from a capacity"""
|
152
|
+
ws = self.get_workspace_by_id(workspace_id)
|
153
|
+
return ws.unassign_from_capacity()
|
154
|
+
|
155
|
+
def list_capacities(self, continuationToken = None):
|
156
|
+
"""List all capacities in the tenant"""
|
157
|
+
url = "https://api.fabric.microsoft.com/v1/capacities"
|
158
|
+
|
159
|
+
if continuationToken:
|
160
|
+
url = f"{url}?continuationToken={continuationToken}"
|
161
|
+
|
162
|
+
for _ in range(10):
|
163
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
164
|
+
if response.status_code == 429:
|
165
|
+
print("Too many requests, waiting 10 seconds")
|
166
|
+
sleep(10)
|
167
|
+
continue
|
168
|
+
if response.status_code not in (200, 429):
|
169
|
+
print(response.status_code)
|
170
|
+
print(response.text)
|
171
|
+
raise Exception(f"Error listing capacities: {response.text}")
|
172
|
+
break
|
173
|
+
|
174
|
+
resp_dict = json.loads(response.text)
|
175
|
+
items = resp_dict["value"]
|
176
|
+
|
177
|
+
if "continuationToken" in resp_dict:
|
178
|
+
cap_list_next = self.list_capacities(continuationToken=resp_dict["continuationToken"])
|
179
|
+
items.extend(cap_list_next)
|
180
|
+
|
181
|
+
items = json.loads(response.text)["value"]
|
182
|
+
items = [Capacity.from_dict(i) for i in items]
|
183
|
+
return items
|
184
|
+
|
185
|
+
|
186
|
+
def create_item(self, workspace_id, display_name, type, definition = None, description = None):
|
187
|
+
"""Create an item in a workspace"""
|
188
|
+
ws = self.get_workspace_by_id(workspace_id)
|
189
|
+
|
190
|
+
return ws.create_item(display_name = display_name,
|
191
|
+
type = type,
|
192
|
+
definition = definition,
|
193
|
+
description = description)
|
194
|
+
|
195
|
+
def get_item(self, workspace_id = None,
|
196
|
+
item_id = None, workspace_name = None, item_name = None, item_type = None):
|
197
|
+
"""Get an item from a workspace"""
|
198
|
+
ws = self.get_workspace(id = workspace_id, name = workspace_name)
|
199
|
+
return ws.get_item(item_id = item_id, item_name = item_name, item_type = item_type)
|
200
|
+
|
201
|
+
def delete_item(self, workspace_id, item_id):
|
202
|
+
"""Delete an item from a workspace"""
|
203
|
+
ws = self.get_workspace_by_id(workspace_id)
|
204
|
+
return ws.delete_item(item_id)
|
205
|
+
|
206
|
+
def list_items(self, workspace_id):
|
207
|
+
"""List items in a workspace"""
|
208
|
+
ws = self.get_workspace_by_id(workspace_id)
|
209
|
+
return ws.list_items()
|
210
|
+
|
211
|
+
def get_item_definition(self, workspace_id, item_id):
|
212
|
+
"""Get the definition of an item"""
|
213
|
+
ws = self.get_workspace_by_id(workspace_id)
|
214
|
+
return ws.get_item_definition(item_id)
|
215
|
+
|
216
|
+
def update_item(self, workspace_id, item_id, display_name = None, description = None):
|
217
|
+
"""Update an item in a workspace"""
|
218
|
+
ws = self.get_workspace_by_id(workspace_id)
|
219
|
+
return ws.get_item(item_id).update(display_name, description)
|
220
|
+
|
221
|
+
def update_item_definition(self, workspace_id, item_id, definition):
|
222
|
+
"""Update the definition of an item"""
|
223
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
224
|
+
return ws.get_item(item_id=item_id).update_definition(definition=definition)
|
225
|
+
|
226
|
+
def create_shortcut(self, workspace_id, item_id, path, name, target):
|
227
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
228
|
+
return ws.get_item(item_id=item_id).create_shortcut(path=path, name=name, target=target)
|
229
|
+
|
230
|
+
def get_shortcut(self, workspace_id, item_id, path, name):
|
231
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
232
|
+
return ws.get_item(item_id=item_id).get_shortcut(path=path, name=name)
|
233
|
+
|
234
|
+
def delete_shortcut(self, workspace_id, item_id, path, name):
|
235
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
236
|
+
return ws.get_item(item_id=item_id).delete_shortcut(path=path, name=name)
|
237
|
+
|
238
|
+
def get_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
239
|
+
"""Get a job instance for an item"""
|
240
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
241
|
+
return ws.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id)
|
242
|
+
|
243
|
+
def run_on_demand_item_job(self, workspace_id, item_id, job_type, execution_data = None):
|
244
|
+
"""Run an on demand job for an item"""
|
245
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
246
|
+
return ws.get_item(item_id=item_id).run_on_demand_item_job(job_type=job_type, execution_data=execution_data)
|
247
|
+
|
248
|
+
def cancel_item_job_instance(self, workspace_id, item_id, job_instance_id):
|
249
|
+
"""Cancel a job instance for an item"""
|
250
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
251
|
+
return ws.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id).cancel()
|
252
|
+
|
253
|
+
def commit_to_git(self, workspace_id,mode, comment=None, items=None, workspace_head=None):
|
254
|
+
"""Commit changes to git"""
|
255
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
256
|
+
return ws.commit_to_git(mode=mode, comment=comment, items=items, workspace_head=workspace_head)
|
257
|
+
|
258
|
+
def git_connect(self, workspace_id, git_provider_details):
|
259
|
+
"""Connect to git"""
|
260
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
261
|
+
return ws.git_connect(git_provider_details=git_provider_details)
|
262
|
+
|
263
|
+
def git_disconnect(self, workspace_id):
|
264
|
+
"""Disconnect from git"""
|
265
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
266
|
+
return ws.git_disconnect()
|
267
|
+
|
268
|
+
def git_get_connection(self, workspace_id):
|
269
|
+
"""Get git connection details"""
|
270
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
271
|
+
return ws.git_get_connection()
|
272
|
+
|
273
|
+
def git_get_status(self, workspace_id):
|
274
|
+
"""Get git status"""
|
275
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
276
|
+
return ws.git_get_status()
|
277
|
+
|
278
|
+
def git_initialize_connection(self, workspace_id, initialization_strategy):
|
279
|
+
"""Initialize git"""
|
280
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
281
|
+
return ws.git_initialize_connection(initialization_strategy=initialization_strategy)
|
282
|
+
|
283
|
+
def update_from_git(self, workspace_id, remote_commit_hash, conflict_resolution = None, options = None, workspace_head = None):
|
284
|
+
"""Update workspace from git"""
|
285
|
+
ws = self.get_workspace_by_id(id=workspace_id)
|
286
|
+
return ws.update_from_git(remote_commit_hash=remote_commit_hash,
|
287
|
+
conflict_resolution=conflict_resolution,
|
288
|
+
options=options,
|
289
|
+
workspace_head=workspace_head)
|
290
|
+
|
291
|
+
def get_capacity(self, capacity_id = None, capacity_name = None):
|
292
|
+
"""Get a capacity
|
293
|
+
|
294
|
+
Args:
|
295
|
+
capacity_id (str): The ID of the capacity
|
296
|
+
capacity_name (str): The name of the capacity
|
297
|
+
|
298
|
+
Returns:
|
299
|
+
Capacity: The capacity object
|
300
|
+
|
301
|
+
Raises:
|
302
|
+
ValueError: If no capacity is found
|
303
|
+
"""
|
304
|
+
if capacity_id is None and capacity_name is None:
|
305
|
+
raise ValueError("Either capacity_id or capacity_name must be provided")
|
306
|
+
caps = self.list_capacities()
|
307
|
+
for cap in caps:
|
308
|
+
if capacity_id and cap.id == capacity_id:
|
309
|
+
return cap
|
310
|
+
if capacity_name and cap.display_name == capacity_name:
|
311
|
+
return cap
|
312
|
+
raise ValueError("No capacity found")
|
313
|
+
|
314
|
+
def list_tables(self, workspace_id, item_id):
|
315
|
+
ws = self.get_workspace_by_id(workspace_id)
|
316
|
+
return ws.list_tables(item_id=item_id)
|
317
|
+
|
318
|
+
def load_table(self, workspace_id, item_id, table_name, path_type, relative_path,
|
319
|
+
file_extension = None, format_options = None,
|
320
|
+
mode = None, recursive = None, wait_for_completion = True):
|
321
|
+
ws = self.get_workspace_by_id(workspace_id)
|
322
|
+
return ws.load_table(item_id, table_name, path_type, relative_path,
|
323
|
+
file_extension, format_options,
|
324
|
+
mode, recursive, wait_for_completion)
|