msfabricpysdkcore 0.1.1__tar.gz → 0.1.2__tar.gz
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-0.1.1 → msfabricpysdkcore-0.1.2}/PKG-INFO +64 -3
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/README.md +63 -2
- msfabricpysdkcore-0.1.2/msfabricpysdkcore/__init__.py +3 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/admin_item.py +1 -1
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/adminapi.py +3 -1
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/auth.py +10 -6
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/client.py +10 -7
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/coreapi.py +4 -1
- msfabricpysdkcore-0.1.2/msfabricpysdkcore/fabric_azure_capacity.py +77 -0
- msfabricpysdkcore-0.1.2/msfabricpysdkcore/fabric_azure_client.py +228 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_admin_apis.py +8 -9
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_datapipelines.py +1 -1
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_domains.py +2 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_environments.py +6 -6
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_evenhouses.py +1 -2
- msfabricpysdkcore-0.1.2/msfabricpysdkcore/tests/test_evenstreams.py +44 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_external_data_shares.py +3 -3
- msfabricpysdkcore-0.1.2/msfabricpysdkcore/tests/test_fabric_azure_client.py +78 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_git.py +8 -9
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_items.py +3 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_jobs.py +2 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_kql_queryset.py +1 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_kqldatabases.py +2 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_lakehouse.py +5 -7
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_ml_experiments.py +1 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_ml_models.py +1 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_notebooks.py +1 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_one_lake_data_access_security.py +2 -4
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_other_items.py +6 -7
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_reports.py +1 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_semantic_model.py +3 -4
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_shortcuts.py +4 -4
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_spark.py +2 -4
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_sparkjobdefinition.py +1 -1
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_warehouses.py +1 -2
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_workspaces_capacities.py +9 -9
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore.egg-info/PKG-INFO +64 -3
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore.egg-info/SOURCES.txt +3 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/pyproject.toml +1 -1
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/setup.py +1 -1
- msfabricpysdkcore-0.1.1/msfabricpysdkcore/__init__.py +0 -2
- msfabricpysdkcore-0.1.1/msfabricpysdkcore/tests/test_evenstreams.py +0 -44
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/LICENSE +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/admin_workspace.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/capacity.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/deployment_pipeline.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/domain.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/environment.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/item.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/job_instance.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/lakehouse.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/long_running_operation.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/onelakeshortcut.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/otheritems.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/spark_custom_pool.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/__init__.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_deployment_pipeline.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/tests/test_items_incl_lakehouse.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore/workspace.py +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore.egg-info/dependency_links.txt +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore.egg-info/requires.txt +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/msfabricpysdkcore.egg-info/top_level.txt +0 -0
- {msfabricpysdkcore-0.1.1 → msfabricpysdkcore-0.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: msfabricpysdkcore
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.2
|
4
4
|
Summary: A Python SDK for Microsoft Fabric
|
5
5
|
Author: Andreas Rederer
|
6
6
|
Project-URL: Homepage, https://github.com/DaSenf1860/ms-fabric-sdk-core
|
@@ -15,11 +15,12 @@ Requires-Dist: azure-identity>=1.15.0
|
|
15
15
|
|
16
16
|
# Python SDK for Microsoft Fabric
|
17
17
|
|
18
|
-
This is a Python SDK for Microsoft Fabric. It is a wrapper around the REST APIs (v1) of Fabric*.
|
18
|
+
This is a Python SDK for Microsoft Fabric. It is a wrapper around the REST APIs (v1) of Fabric*. It supports all Fabric REST APIs as well as Azure Resource Management APIs for Fabric (as of July 23, 2024).
|
19
19
|
|
20
20
|

|
21
21
|
|
22
22
|
The Microsoft Fabric REST APIs are documented [here](https://docs.microsoft.com/en-us/rest/api/fabric/).
|
23
|
+
The Azure Resoure Management APIs for Fabric are documented [here](https://learn.microsoft.com/en-us/rest/api/microsoftfabric/fabric-capacities?view=rest-microsoftfabric-2023-11-01).
|
23
24
|
They are designed to automate your Fabric processes.
|
24
25
|
|
25
26
|
This SDK helps to interact with the Fabric APIs in a more Pythonic way.
|
@@ -34,7 +35,7 @@ Additionally it brings some extra features like:
|
|
34
35
|
|
35
36
|
See the latest release notes [here](releasenotes/release_notes.md).
|
36
37
|
|
37
|
-
Currently it supports all Core APIs, Admin APIs,
|
38
|
+
Currently it supports all Core APIs, Admin APIs, all item specific CRUD APIs and Azure Resource Management APIs for Fabric capacities, i.e.:
|
38
39
|
- Core APIs
|
39
40
|
- [Capacities](#working-with-capacities)
|
40
41
|
- [Deployment Pipelines](#deployment-pipelines)
|
@@ -58,6 +59,7 @@ Currently it supports all Core APIs, Admin APIs, Lakehouse APIs and all other it
|
|
58
59
|
- List, create, update, delete warehouses, notebooks, semantic models, kql databases,.....
|
59
60
|
- Lakehouse operations (Load table, list tables, run table maintenance)
|
60
61
|
- Spark Pool operations
|
62
|
+
- [Azure Resource Management APIs for Fabric capacities](#azure-resource-management-apis-for-fabric-capacities)
|
61
63
|
|
62
64
|
It is planned to support also new APIs which are not released yet.
|
63
65
|
Also we have plans to support APIs to interact with Fabric capacities on the Azure Side.
|
@@ -100,7 +102,12 @@ fc = FabricClientCore(tenant_id = "tenant_id",
|
|
100
102
|
|
101
103
|
|
102
104
|
```
|
105
|
+
### Getting a token
|
106
|
+
```python
|
107
|
+
# Getting a token
|
103
108
|
|
109
|
+
token = fc.get_token()
|
110
|
+
```
|
104
111
|
### Working with workspaces
|
105
112
|
|
106
113
|
```python
|
@@ -716,3 +723,57 @@ fca.revoke_external_data_share(external_data_share_id = data_shares[0]['id'],
|
|
716
723
|
|
717
724
|
Note: This SDK is not an official SDK from Microsoft. It is a community project and not supported by Microsoft. Use it at your own risk.
|
718
725
|
Also the API is still in preview and might change. This SDK is not yet feature complete and might not cover all APIs yet. Feel free to contribute to this project to make it better.
|
726
|
+
|
727
|
+
|
728
|
+
### Azure Resource Management APIs for Fabric capacities
|
729
|
+
|
730
|
+
```python
|
731
|
+
from msfabricpysdkcore import FabricAzureClient
|
732
|
+
|
733
|
+
fac = FabricAzureClient()
|
734
|
+
|
735
|
+
subscription_id = "fsdgdfgds"
|
736
|
+
resource_group_name = "fabricdemo"
|
737
|
+
capacity_name = "rgsdfgsdfgsd"
|
738
|
+
capacity_name_new = "dsfgsdfgsdfg" + datetime.now().strftime("%Y%m%d%H%M%S")
|
739
|
+
|
740
|
+
# Check name availability
|
741
|
+
|
742
|
+
resp = fac.check_name_availability(subscription_id, "westeurope", capacity_name_new)
|
743
|
+
|
744
|
+
# Create or update capacity
|
745
|
+
resp = fac.create_or_update_capacity(subscription_id, resource_group_name, capacity_name_new,
|
746
|
+
location="westeurope",
|
747
|
+
properties_administration={"members": ['admin@MngEnvMCAP065039.onmicrosoft.com']},
|
748
|
+
sku = "F2")
|
749
|
+
|
750
|
+
# Get capacity
|
751
|
+
resp = fac.get_capacity(subscription_id, resource_group_name, capacity_name_new)
|
752
|
+
sku = resp.sku['name']
|
753
|
+
|
754
|
+
# Delete capacity
|
755
|
+
resp = fac.delete_capacity(subscription_id, resource_group_name, capacity_name_new)
|
756
|
+
|
757
|
+
# List capacities by resource group
|
758
|
+
resp = fac.list_by_resource_group(subscription_id, resource_group_name)
|
759
|
+
cap_names = [cap["name"] for cap in resp]
|
760
|
+
|
761
|
+
# List capacities by subscription
|
762
|
+
resp = fac.list_by_subscription(subscription_id)
|
763
|
+
cap_names = [cap["name"] for cap in resp]
|
764
|
+
|
765
|
+
# List SKUs
|
766
|
+
resp = fac.list_skus(subscription_id)
|
767
|
+
|
768
|
+
# List SKUs for capacity
|
769
|
+
resp = fac.list_skus_for_capacity(subscription_id, resource_group_name, capacity_name)
|
770
|
+
|
771
|
+
# Resume capacity
|
772
|
+
resp = fac.resume_capacity(subscription_id, resource_group_name, capacity_name)
|
773
|
+
|
774
|
+
# Suspend capacity
|
775
|
+
resp = fac.suspend_capacity(subscription_id, resource_group_name, capacity_name)
|
776
|
+
|
777
|
+
# Update capacity
|
778
|
+
resp = fac.update_capacity(subscription_id, resource_group_name, capacity_name, sku="F4")
|
779
|
+
```
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# Python SDK for Microsoft Fabric
|
2
2
|
|
3
|
-
This is a Python SDK for Microsoft Fabric. It is a wrapper around the REST APIs (v1) of Fabric*.
|
3
|
+
This is a Python SDK for Microsoft Fabric. It is a wrapper around the REST APIs (v1) of Fabric*. It supports all Fabric REST APIs as well as Azure Resource Management APIs for Fabric (as of July 23, 2024).
|
4
4
|
|
5
5
|

|
6
6
|
|
7
7
|
The Microsoft Fabric REST APIs are documented [here](https://docs.microsoft.com/en-us/rest/api/fabric/).
|
8
|
+
The Azure Resoure Management APIs for Fabric are documented [here](https://learn.microsoft.com/en-us/rest/api/microsoftfabric/fabric-capacities?view=rest-microsoftfabric-2023-11-01).
|
8
9
|
They are designed to automate your Fabric processes.
|
9
10
|
|
10
11
|
This SDK helps to interact with the Fabric APIs in a more Pythonic way.
|
@@ -19,7 +20,7 @@ Additionally it brings some extra features like:
|
|
19
20
|
|
20
21
|
See the latest release notes [here](releasenotes/release_notes.md).
|
21
22
|
|
22
|
-
Currently it supports all Core APIs, Admin APIs,
|
23
|
+
Currently it supports all Core APIs, Admin APIs, all item specific CRUD APIs and Azure Resource Management APIs for Fabric capacities, i.e.:
|
23
24
|
- Core APIs
|
24
25
|
- [Capacities](#working-with-capacities)
|
25
26
|
- [Deployment Pipelines](#deployment-pipelines)
|
@@ -43,6 +44,7 @@ Currently it supports all Core APIs, Admin APIs, Lakehouse APIs and all other it
|
|
43
44
|
- List, create, update, delete warehouses, notebooks, semantic models, kql databases,.....
|
44
45
|
- Lakehouse operations (Load table, list tables, run table maintenance)
|
45
46
|
- Spark Pool operations
|
47
|
+
- [Azure Resource Management APIs for Fabric capacities](#azure-resource-management-apis-for-fabric-capacities)
|
46
48
|
|
47
49
|
It is planned to support also new APIs which are not released yet.
|
48
50
|
Also we have plans to support APIs to interact with Fabric capacities on the Azure Side.
|
@@ -85,7 +87,12 @@ fc = FabricClientCore(tenant_id = "tenant_id",
|
|
85
87
|
|
86
88
|
|
87
89
|
```
|
90
|
+
### Getting a token
|
91
|
+
```python
|
92
|
+
# Getting a token
|
88
93
|
|
94
|
+
token = fc.get_token()
|
95
|
+
```
|
89
96
|
### Working with workspaces
|
90
97
|
|
91
98
|
```python
|
@@ -701,3 +708,57 @@ fca.revoke_external_data_share(external_data_share_id = data_shares[0]['id'],
|
|
701
708
|
|
702
709
|
Note: This SDK is not an official SDK from Microsoft. It is a community project and not supported by Microsoft. Use it at your own risk.
|
703
710
|
Also the API is still in preview and might change. This SDK is not yet feature complete and might not cover all APIs yet. Feel free to contribute to this project to make it better.
|
711
|
+
|
712
|
+
|
713
|
+
### Azure Resource Management APIs for Fabric capacities
|
714
|
+
|
715
|
+
```python
|
716
|
+
from msfabricpysdkcore import FabricAzureClient
|
717
|
+
|
718
|
+
fac = FabricAzureClient()
|
719
|
+
|
720
|
+
subscription_id = "fsdgdfgds"
|
721
|
+
resource_group_name = "fabricdemo"
|
722
|
+
capacity_name = "rgsdfgsdfgsd"
|
723
|
+
capacity_name_new = "dsfgsdfgsdfg" + datetime.now().strftime("%Y%m%d%H%M%S")
|
724
|
+
|
725
|
+
# Check name availability
|
726
|
+
|
727
|
+
resp = fac.check_name_availability(subscription_id, "westeurope", capacity_name_new)
|
728
|
+
|
729
|
+
# Create or update capacity
|
730
|
+
resp = fac.create_or_update_capacity(subscription_id, resource_group_name, capacity_name_new,
|
731
|
+
location="westeurope",
|
732
|
+
properties_administration={"members": ['admin@MngEnvMCAP065039.onmicrosoft.com']},
|
733
|
+
sku = "F2")
|
734
|
+
|
735
|
+
# Get capacity
|
736
|
+
resp = fac.get_capacity(subscription_id, resource_group_name, capacity_name_new)
|
737
|
+
sku = resp.sku['name']
|
738
|
+
|
739
|
+
# Delete capacity
|
740
|
+
resp = fac.delete_capacity(subscription_id, resource_group_name, capacity_name_new)
|
741
|
+
|
742
|
+
# List capacities by resource group
|
743
|
+
resp = fac.list_by_resource_group(subscription_id, resource_group_name)
|
744
|
+
cap_names = [cap["name"] for cap in resp]
|
745
|
+
|
746
|
+
# List capacities by subscription
|
747
|
+
resp = fac.list_by_subscription(subscription_id)
|
748
|
+
cap_names = [cap["name"] for cap in resp]
|
749
|
+
|
750
|
+
# List SKUs
|
751
|
+
resp = fac.list_skus(subscription_id)
|
752
|
+
|
753
|
+
# List SKUs for capacity
|
754
|
+
resp = fac.list_skus_for_capacity(subscription_id, resource_group_name, capacity_name)
|
755
|
+
|
756
|
+
# Resume capacity
|
757
|
+
resp = fac.resume_capacity(subscription_id, resource_group_name, capacity_name)
|
758
|
+
|
759
|
+
# Suspend capacity
|
760
|
+
resp = fac.suspend_capacity(subscription_id, resource_group_name, capacity_name)
|
761
|
+
|
762
|
+
# Update capacity
|
763
|
+
resp = fac.update_capacity(subscription_id, resource_group_name, capacity_name, sku="F4")
|
764
|
+
```
|
@@ -74,7 +74,7 @@ class AdminItem:
|
|
74
74
|
description = item_dict.get('description', None),
|
75
75
|
last_updated_date = item_dict['lastUpdatedDate'],
|
76
76
|
capacity_id = item_dict['capacityId'],
|
77
|
-
creator_principal = item_dict
|
77
|
+
creator_principal = item_dict.get('creatorPrincipal', None),
|
78
78
|
admin_client = admin_client
|
79
79
|
)
|
80
80
|
|
@@ -10,7 +10,9 @@ class FabricClientAdmin(FabricClient):
|
|
10
10
|
|
11
11
|
def __init__(self, tenant_id = None, client_id = None, client_secret = None) -> None:
|
12
12
|
"""Initialize FabricClientAdmin object"""
|
13
|
-
super().__init__(
|
13
|
+
super().__init__(scope="https://api.fabric.microsoft.com/.default",
|
14
|
+
tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
|
15
|
+
|
14
16
|
|
15
17
|
def long_running_operation(self, response_headers):
|
16
18
|
"""Check the status of a long running operation"""
|
@@ -8,6 +8,9 @@ except ImportError:
|
|
8
8
|
class FabricAuth():
|
9
9
|
"""FabricAuth class to interact with Entra ID"""
|
10
10
|
|
11
|
+
def __init__(self, scope):
|
12
|
+
self.scope = scope
|
13
|
+
|
11
14
|
@abstractmethod
|
12
15
|
def get_token(self):
|
13
16
|
"""Get token from Azure AD"""
|
@@ -26,20 +29,23 @@ class FabricAuth():
|
|
26
29
|
class FabricAuthClient(FabricAuth):
|
27
30
|
"""FabricAuthClient class to interact with Entra ID"""
|
28
31
|
|
29
|
-
def __init__(self, silent = False):
|
32
|
+
def __init__(self, scope, silent = False):
|
33
|
+
super().__init__(scope)
|
30
34
|
if not silent:
|
31
35
|
print("Using Azure CLI for authentication")
|
32
36
|
self.auth = AzureCliCredential()
|
33
37
|
|
34
38
|
def get_token(self):
|
35
39
|
"""Get token from Azure AD"""
|
36
|
-
token = self.auth.get_token(
|
40
|
+
token = self.auth.get_token(self.scope)
|
37
41
|
return token.token
|
38
42
|
|
39
43
|
class FabricServicePrincipal(FabricAuth):
|
40
44
|
"""FabricServicePrincipal class to interact with Entra ID"""
|
41
45
|
|
42
|
-
def __init__(self, tenant_id, client_id, client_secret, silent = False):
|
46
|
+
def __init__(self, tenant_id, client_id, client_secret, scope, silent = False):
|
47
|
+
super().__init__(scope)
|
48
|
+
|
43
49
|
if not silent:
|
44
50
|
print("Using Service Principal for authentication")
|
45
51
|
|
@@ -47,8 +53,6 @@ class FabricServicePrincipal(FabricAuth):
|
|
47
53
|
self.client_id = client_id
|
48
54
|
self.client_secret = client_secret
|
49
55
|
|
50
|
-
self.scope = "https://api.fabric.microsoft.com/.default"
|
51
|
-
|
52
56
|
|
53
57
|
def get_token(self):
|
54
58
|
"""Get token from Azure AD"""
|
@@ -67,7 +71,7 @@ class FabricServicePrincipal(FabricAuth):
|
|
67
71
|
class FabricSparkUtilsAuthentication(FabricAuth):
|
68
72
|
"""FabricSparkUtilsAuthentication class to interact with Entra ID"""
|
69
73
|
|
70
|
-
def __init__(self, silent = False):
|
74
|
+
def __init__(self, scope, silent = False):
|
71
75
|
mssparkutils.credentials.getToken("pbi")
|
72
76
|
if not silent:
|
73
77
|
print("Using Synapse Spark Utils for authentication")
|
@@ -9,26 +9,29 @@ from msfabricpysdkcore.auth import FabricAuthClient, FabricServicePrincipal, Fab
|
|
9
9
|
class FabricClient():
|
10
10
|
"""FabricClient class to interact with Fabric API"""
|
11
11
|
|
12
|
-
def __init__(self, tenant_id = None, client_id = None, client_secret = None, silent=False) -> None:
|
12
|
+
def __init__(self, scope, tenant_id = None, client_id = None, client_secret = None, silent=False) -> None:
|
13
13
|
"""Initialize FabricClient object"""
|
14
14
|
self.tenant_id = tenant_id if tenant_id else os.getenv("FABRIC_TENANT_ID")
|
15
15
|
self.client_id = client_id if client_id else os.getenv("FABRIC_CLIENT_ID")
|
16
16
|
self.client_secret = client_secret if client_secret else os.getenv("FABRIC_CLIENT_SECRET")
|
17
|
-
|
18
|
-
self.scope = "https://api.fabric.microsoft.com/.default"
|
17
|
+
self.scope = scope
|
18
|
+
#self.scope = "https://api.fabric.microsoft.com/.default"
|
19
19
|
|
20
20
|
if self.client_id is None or self.client_secret is None or self.tenant_id is None:
|
21
21
|
try:
|
22
|
-
self.auth = FabricSparkUtilsAuthentication(silent=silent)
|
22
|
+
self.auth = FabricSparkUtilsAuthentication(self.scope, silent=silent)
|
23
23
|
except:
|
24
|
-
self.auth = FabricAuthClient(silent=silent)
|
24
|
+
self.auth = FabricAuthClient(self.scope, silent=silent)
|
25
25
|
else:
|
26
|
-
self.auth = FabricServicePrincipal(
|
26
|
+
self.auth = FabricServicePrincipal(scope= self.scope,
|
27
|
+
tenant_id = self.tenant_id,
|
27
28
|
client_id = self.client_id,
|
28
29
|
client_secret = self.client_secret,
|
29
30
|
silent=silent)
|
30
31
|
|
31
|
-
|
32
|
+
def get_token(self):
|
33
|
+
"""Get token from Entra"""
|
34
|
+
return self.auth.get_token()
|
32
35
|
|
33
36
|
def calling_routine(self, url, operation, body = None, headers=None, file_path = None, response_codes = [200], error_message = "Error",
|
34
37
|
continue_on_error_code = False, return_format = "value_json", paging = False,
|
@@ -8,7 +8,10 @@ class FabricClientCore(FabricClient):
|
|
8
8
|
|
9
9
|
def __init__(self, tenant_id = None, client_id = None, client_secret = None, silent=False) -> None:
|
10
10
|
"""Initialize FabricClientCore object"""
|
11
|
-
super().__init__(
|
11
|
+
super().__init__(scope="https://api.fabric.microsoft.com/.default",
|
12
|
+
tenant_id=tenant_id,
|
13
|
+
client_id=client_id,
|
14
|
+
client_secret=client_secret, silent=silent)
|
12
15
|
|
13
16
|
def long_running_operation(self, response_headers):
|
14
17
|
"""Check the status of a long running operation"""
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
from msfabricpysdkcore.fabric_azure_client import FabricAzureClient
|
4
|
+
|
5
|
+
class FabricAzureCapacity:
|
6
|
+
"""Class to represent a item in Microsoft Fabric"""
|
7
|
+
|
8
|
+
def __init__(self, id, name, subscription_id, resource_group_name, type, location, properties, sku, azure_client: FabricAzureClient, tags=None) -> None:
|
9
|
+
|
10
|
+
self.id = id
|
11
|
+
self.name = name
|
12
|
+
self.subscription_id = subscription_id
|
13
|
+
self.resource_group_name = resource_group_name
|
14
|
+
self.type = type
|
15
|
+
self.location = location
|
16
|
+
self.properties = properties
|
17
|
+
self.sku = sku
|
18
|
+
self.tags = tags
|
19
|
+
|
20
|
+
self.azure_client = azure_client
|
21
|
+
|
22
|
+
def __str__(self) -> str:
|
23
|
+
"""Return a string representation of the fabric azure capacity object"""
|
24
|
+
dict_ = {
|
25
|
+
'id': self.id,
|
26
|
+
'name': self.name,
|
27
|
+
'subscription_id': self.subscription_id,
|
28
|
+
'resource_group_name': self.resource_group_name,
|
29
|
+
'type': self.type,
|
30
|
+
'location': self.location,
|
31
|
+
'properties': self.properties,
|
32
|
+
'sku': self.sku,
|
33
|
+
'tags': self.tags
|
34
|
+
}
|
35
|
+
return json.dumps(dict_, indent=2)
|
36
|
+
|
37
|
+
def __repr__(self) -> str:
|
38
|
+
return self.__str__()
|
39
|
+
|
40
|
+
def from_dict(dict, azure_client):
|
41
|
+
"""Create FabricAzureCapacity object from dictionary"""
|
42
|
+
|
43
|
+
return FabricAzureCapacity(id=dict['id'], name=dict['name'], subscription_id=dict['subscription_id'],
|
44
|
+
resource_group_name=dict['resource_group_name'],
|
45
|
+
type=dict['type'],
|
46
|
+
location=dict['location'],
|
47
|
+
properties=dict['properties'], sku=dict['sku'],
|
48
|
+
tags=dict.get('tags', None), azure_client=azure_client)
|
49
|
+
|
50
|
+
# Delete
|
51
|
+
|
52
|
+
def delete(self):
|
53
|
+
"""Delete the capacity"""
|
54
|
+
|
55
|
+
return self.azure_client.delete_capacity(self.subscription_id, self.resource_group_name, self.name)
|
56
|
+
|
57
|
+
# Resume
|
58
|
+
|
59
|
+
def resume(self):
|
60
|
+
"""Resume the capacity"""
|
61
|
+
|
62
|
+
return self.azure_client.resume_capacity(self.subscription_id, self.resource_group_name, self.name)
|
63
|
+
|
64
|
+
# Suspend
|
65
|
+
|
66
|
+
def suspend(self):
|
67
|
+
"""Suspend the capacity"""
|
68
|
+
|
69
|
+
return self.azure_client.suspend_capacity(self.subscription_id, self.resource_group_name, self.name)
|
70
|
+
|
71
|
+
# Update
|
72
|
+
|
73
|
+
def update(self, properties_administration=None, sku=None, tags=None):
|
74
|
+
"""Update the capacity"""
|
75
|
+
|
76
|
+
return self.azure_client.update_capacity(self.subscription_id, self.resource_group_name, self.name, properties_administration=properties_administration, sku=sku, tags=tags)
|
77
|
+
|
@@ -0,0 +1,228 @@
|
|
1
|
+
from msfabricpysdkcore.client import FabricClient
|
2
|
+
|
3
|
+
|
4
|
+
class FabricAzureClient(FabricClient):
|
5
|
+
|
6
|
+
def __init__(self, tenant_id=None, client_id=None, client_secret=None, silent=False) -> None:
|
7
|
+
super().__init__(scope = "https://management.azure.com/",
|
8
|
+
tenant_id = tenant_id,
|
9
|
+
client_id = client_id,
|
10
|
+
client_secret = client_secret,
|
11
|
+
silent = silent)
|
12
|
+
|
13
|
+
|
14
|
+
def check_name_availability(self, subscription_id, location, name, type = "Microsoft.Fabric/capacities"):
|
15
|
+
"""Check name availability
|
16
|
+
Args:
|
17
|
+
subscription_id (str): The subscription ID
|
18
|
+
location (str): The location
|
19
|
+
name (str): The name
|
20
|
+
type (str): The type
|
21
|
+
Returns:
|
22
|
+
dict: The response
|
23
|
+
"""
|
24
|
+
|
25
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/providers/Microsoft.Fabric/locations/{location}/checkNameAvailability?api-version=2023-11-01"
|
26
|
+
|
27
|
+
body = {
|
28
|
+
"name": name,
|
29
|
+
"type": type
|
30
|
+
}
|
31
|
+
|
32
|
+
response = self.calling_routine(url=url, operation="POST", body=body, response_codes=[200], return_format="json", error_message="Failed to check name availability")
|
33
|
+
return response
|
34
|
+
|
35
|
+
def create_or_update_capacity(self, subscription_id, resource_group_name, capacity_name, location, properties_administration, sku, tags = None):
|
36
|
+
"""Create or update capacity
|
37
|
+
Args:
|
38
|
+
subscription_id (str): The subscription ID
|
39
|
+
resource_group_name (str): The resource group name
|
40
|
+
capacity_name (str): The capacity name
|
41
|
+
location (str): The location
|
42
|
+
properties_administration (dict): The administration properties
|
43
|
+
sku (dict): The sku
|
44
|
+
tags (dict): The tags
|
45
|
+
Returns:
|
46
|
+
FabricAzureCapacity: The capacity
|
47
|
+
"""
|
48
|
+
from msfabricpysdkcore.fabric_azure_capacity import FabricAzureCapacity
|
49
|
+
|
50
|
+
if sku and "name" in sku:
|
51
|
+
sku = sku["name"]
|
52
|
+
|
53
|
+
body = {
|
54
|
+
"location": location,
|
55
|
+
"properties": {
|
56
|
+
"administration": properties_administration
|
57
|
+
},
|
58
|
+
"sku": {"name": sku,
|
59
|
+
"tier": "Fabric"}
|
60
|
+
}
|
61
|
+
|
62
|
+
if tags is not None:
|
63
|
+
body["tags"] = tags
|
64
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}?api-version=2023-11-01"
|
65
|
+
|
66
|
+
response = self.calling_routine(url=url, operation="PUT", body=body, response_codes=[200, 201], return_format="json", error_message="Failed to create or update capacity")
|
67
|
+
response["subscription_id"] = subscription_id
|
68
|
+
response["resource_group_name"] = resource_group_name
|
69
|
+
|
70
|
+
return FabricAzureCapacity.from_dict(response, self)
|
71
|
+
|
72
|
+
|
73
|
+
def delete_capacity(self, subscription_id, resource_group_name, capacity_name):
|
74
|
+
"""Delete capacity
|
75
|
+
Args:
|
76
|
+
subscription_id (str): The subscription ID
|
77
|
+
resource_group_name (str): The resource group name
|
78
|
+
capacity_name (str): The capacity name
|
79
|
+
Returns:
|
80
|
+
dict: The response
|
81
|
+
"""
|
82
|
+
|
83
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}?api-version=2023-11-01"
|
84
|
+
|
85
|
+
response = self.calling_routine(url=url, operation="DELETE", response_codes=[202], return_format="response", error_message="Failed to delete capacity")
|
86
|
+
return response
|
87
|
+
|
88
|
+
|
89
|
+
def get_capacity(self, subscription_id, resource_group_name, capacity_name):
|
90
|
+
"""Get capacity
|
91
|
+
Args:
|
92
|
+
subscription_id (str): The subscription ID
|
93
|
+
resource_group_name (str): The resource group name
|
94
|
+
capacity_name (str): The capacity name
|
95
|
+
Returns:
|
96
|
+
FabricAzureCapacity: The capacity
|
97
|
+
"""
|
98
|
+
from msfabricpysdkcore.fabric_azure_capacity import FabricAzureCapacity
|
99
|
+
|
100
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}?api-version=2023-11-01"
|
101
|
+
|
102
|
+
response = self.calling_routine(url=url, operation="GET", response_codes=[200], return_format="json", error_message="Failed to get capacity")
|
103
|
+
response["subscription_id"] = subscription_id
|
104
|
+
response["resource_group_name"] = resource_group_name
|
105
|
+
|
106
|
+
return FabricAzureCapacity.from_dict(response, self)
|
107
|
+
|
108
|
+
def list_by_resource_group(self, subscription_id, resource_group_name):
|
109
|
+
"""List capacities by resource group
|
110
|
+
Args:
|
111
|
+
subscription_id (str): The subscription ID
|
112
|
+
resource_group_name (str): The resource group name
|
113
|
+
Returns:
|
114
|
+
dict: The response
|
115
|
+
"""
|
116
|
+
|
117
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities?api-version=2023-11-01"
|
118
|
+
|
119
|
+
response = self.calling_routine(url=url, operation="GET", response_codes=[200], return_format="value_json", error_message="Failed to list capacities by resource group")
|
120
|
+
return response
|
121
|
+
|
122
|
+
|
123
|
+
def list_by_subscription(self, subscription_id):
|
124
|
+
"""List capacities by subscription
|
125
|
+
Args:
|
126
|
+
subscription_id (str): The subscription ID
|
127
|
+
Returns:
|
128
|
+
dict: The response
|
129
|
+
"""
|
130
|
+
|
131
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/providers/Microsoft.Fabric/capacities?api-version=2023-11-01"
|
132
|
+
|
133
|
+
response = self.calling_routine(url=url, operation="GET", response_codes=[200], return_format="value_json", error_message="Failed to list capacities by subscription")
|
134
|
+
return response
|
135
|
+
|
136
|
+
def list_skus(self, subscription_id):
|
137
|
+
"""List skus
|
138
|
+
Args:
|
139
|
+
subscription_id (str): The subscription ID
|
140
|
+
Returns:
|
141
|
+
dict: The response
|
142
|
+
"""
|
143
|
+
|
144
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/providers/Microsoft.Fabric/skus?api-version=2023-11-01"
|
145
|
+
|
146
|
+
response = self.calling_routine(url=url, operation="GET", response_codes=[200], return_format="value_json", error_message="Failed to list skus")
|
147
|
+
return response
|
148
|
+
|
149
|
+
def list_skus_for_capacity(self, subscription_id, resource_group_name, capacity_name):
|
150
|
+
"""List skus for capacity
|
151
|
+
Args:
|
152
|
+
subscription_id (str): The subscription ID
|
153
|
+
resource_group_name (str): The resource group name
|
154
|
+
capacity_name (str): The capacity name
|
155
|
+
Returns:
|
156
|
+
dict: The response
|
157
|
+
"""
|
158
|
+
|
159
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}/skus?api-version=2023-11-01"
|
160
|
+
|
161
|
+
response = self.calling_routine(url=url, operation="GET", response_codes=[200], return_format="value_json", error_message="Failed to list skus for capacity")
|
162
|
+
return response
|
163
|
+
|
164
|
+
def resume_capacity(self, subscription_id, resource_group_name, capacity_name):
|
165
|
+
"""Resume capacity
|
166
|
+
Args:
|
167
|
+
subscription_id (str): The subscription ID
|
168
|
+
resource_group_name (str): The resource group name
|
169
|
+
capacity_name (str): The capacity name
|
170
|
+
Returns:
|
171
|
+
dict: The response
|
172
|
+
"""
|
173
|
+
|
174
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}/resume?api-version=2023-11-01"
|
175
|
+
|
176
|
+
response = self.calling_routine(url=url, operation="POST", response_codes=[202], return_format="response", error_message="Failed to resume capacity")
|
177
|
+
return response
|
178
|
+
|
179
|
+
def suspend_capacity(self, subscription_id, resource_group_name, capacity_name):
|
180
|
+
"""Suspend capacity
|
181
|
+
Args:
|
182
|
+
subscription_id (str): The subscription ID
|
183
|
+
resource_group_name (str): The resource group name
|
184
|
+
capacity_name (str): The capacity name
|
185
|
+
Returns:
|
186
|
+
dict: The response
|
187
|
+
"""
|
188
|
+
|
189
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}/suspend?api-version=2023-11-01"
|
190
|
+
|
191
|
+
response = self.calling_routine(url=url, operation="POST", response_codes=[202], return_format="response", error_message="Failed to suspend capacity")
|
192
|
+
return response
|
193
|
+
|
194
|
+
def update_capacity(self, subscription_id, resource_group_name, capacity_name, properties_administration = None, sku = None, tags = None):
|
195
|
+
"""Update capacity
|
196
|
+
Args:
|
197
|
+
subscription_id (str): The subscription ID
|
198
|
+
resource_group_name (str): The resource group name
|
199
|
+
capacity_name (str): The capacity name
|
200
|
+
body (dict): The body of the request
|
201
|
+
Returns:
|
202
|
+
FabricAzureCapacity: The capacity
|
203
|
+
"""
|
204
|
+
from msfabricpysdkcore.fabric_azure_capacity import FabricAzureCapacity
|
205
|
+
|
206
|
+
body = {}
|
207
|
+
if sku and "name" in sku:
|
208
|
+
sku = sku["name"]
|
209
|
+
|
210
|
+
if properties_administration is not None:
|
211
|
+
body["properties"] = {}
|
212
|
+
body["properties"]["administration"] = properties_administration
|
213
|
+
|
214
|
+
if sku is not None:
|
215
|
+
body["sku"] = {"name": sku,
|
216
|
+
"tier": "Fabric"}
|
217
|
+
|
218
|
+
if tags is not None:
|
219
|
+
body["tags"] = tags
|
220
|
+
|
221
|
+
url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Fabric/capacities/{capacity_name}?api-version=2023-11-01"
|
222
|
+
|
223
|
+
response = self.calling_routine(url=url, operation="PATCH", body=body, response_codes=[200, 202],
|
224
|
+
return_format="json", error_message="Failed to update capacity")
|
225
|
+
response["subscription_id"] = subscription_id
|
226
|
+
response["resource_group_name"] = resource_group_name
|
227
|
+
|
228
|
+
return FabricAzureCapacity.from_dict(response, self)
|