|
1 | | -import requests |
2 | 1 | import pandas as pd |
3 | 2 | from uuid import UUID |
4 | 3 | from sempy_labs._helper_functions import ( |
5 | | - get_pbi_token_headers, |
6 | | - _get_url_prefix, |
7 | 4 | resolve_capacity_id, |
8 | 5 | _create_dataframe, |
9 | 6 | _update_dataframe_datatypes, |
| 7 | + _base_api, |
10 | 8 | ) |
11 | 9 | import sempy_labs._icons as icons |
12 | 10 | from sempy._utils._log import log |
13 | | -from sempy.fabric.exceptions import FabricHTTPException |
14 | 11 |
|
15 | 12 |
|
16 | 13 | def _surge_api( |
17 | | - capacity, request, payload, method="get", status_code=200, return_json=True |
| 14 | + capacity, url, payload, method="get", status_code=200, return_json=True |
18 | 15 | ): |
19 | 16 |
|
20 | | - headers = get_pbi_token_headers() |
21 | | - prefix = _get_url_prefix() |
22 | 17 | capacity_id = resolve_capacity_id(capacity) |
23 | 18 |
|
24 | | - response = requests.request( |
25 | | - method=method, |
26 | | - url=f"{prefix}/capacities/{capacity_id}/{request}", |
27 | | - headers=headers, |
28 | | - json=payload, |
29 | | - ) |
| 19 | + response = _base_api(request=f"capacities/{capacity_id}/{url}", client="internal", method=method, payload=payload, status_codes=status_code) |
30 | 20 |
|
31 | | - if response.status_code != status_code: |
32 | | - raise FabricHTTPException(response) |
33 | 21 | if return_json: |
34 | 22 | return response.json() |
35 | 23 | else: |
@@ -61,7 +49,7 @@ def get_workspace_consumption_rules( |
61 | 49 | """ |
62 | 50 |
|
63 | 51 | response_json = _surge_api( |
64 | | - capacity=capacity, request="detectionRules", payload=None |
| 52 | + capacity=capacity, url="detectionRules", payload=None |
65 | 53 | ) |
66 | 54 |
|
67 | 55 | if not return_dataframe: |
@@ -121,7 +109,7 @@ def get_background_operation_rules( |
121 | 109 | """ |
122 | 110 |
|
123 | 111 | response_json = _surge_api( |
124 | | - capacity=capacity, request="surgeProtectionRules", payload=None |
| 112 | + capacity=capacity, url="surgeProtectionRules", payload=None |
125 | 113 | ) |
126 | 114 |
|
127 | 115 | if not return_dataframe: |
@@ -223,7 +211,7 @@ def set_workspace_consumption_rules( |
223 | 211 | } |
224 | 212 |
|
225 | 213 | return _surge_api( |
226 | | - capacity=capacity, request="detectionRules", payload=payload, method="post" |
| 214 | + capacity=capacity, url="detectionRules", payload=payload, method="post" |
227 | 215 | ) |
228 | 216 |
|
229 | 217 |
|
@@ -288,7 +276,7 @@ def set_background_operation_rules( |
288 | 276 |
|
289 | 277 | _surge_api( |
290 | 278 | capacity=capacity, |
291 | | - request="surgeProtectionRules", |
| 279 | + url="surgeProtectionRules", |
292 | 280 | payload=payload, |
293 | 281 | method="put", |
294 | 282 | return_json=False, |
@@ -324,7 +312,7 @@ def delete_workspace_consumption_rules(capacity: str | UUID = None): |
324 | 312 |
|
325 | 313 | _surge_api( |
326 | 314 | capacity=capacity, |
327 | | - request=f"detectionRules/{rule_id}", |
| 315 | + url=f"detectionRules/{rule_id}", |
328 | 316 | payload=None, |
329 | 317 | method="delete", |
330 | 318 | status_code=204, |
@@ -352,11 +340,11 @@ def delete_background_operation_rules(capacity: str | UUID = None): |
352 | 340 |
|
353 | 341 | _surge_api( |
354 | 342 | capacity=capacity, |
355 | | - request="surgeProtectionRules", |
| 343 | + url="surgeProtectionRules", |
356 | 344 | payload=None, |
357 | 345 | method="delete", |
358 | 346 | status_code=200, |
359 | 347 | return_json=False, |
360 | 348 | ) |
361 | 349 |
|
362 | | - print(f"{icons.green_dot} The background operation rules deleted successfully.") |
| 350 | + print(f"{icons.green_dot} The background operation rules have been deleted successfully.") |
0 commit comments