Skip to content

Commit 2dd3f08

Browse files
authored
Merge pull request #97062 from docohe/follower-add-python-example
Follower add python example
2 parents 73a75f4 + 32140e8 commit 2dd3f08

File tree

1 file changed

+123
-2
lines changed

1 file changed

+123
-2
lines changed

articles/data-explorer/follower.md

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ There are various methods you can use to attach a database. In this article, we
3333

3434
### Attach a database using C#
3535

36-
**Needed NuGets**
36+
#### Needed NuGets
3737

3838
* Install [Microsoft.Azure.Management.kusto](https://www.nuget.org/packages/Microsoft.Azure.Management.Kusto/).
3939
* Install [Microsoft.Rest.ClientRuntime.Azure.Authentication for authentication](https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime.Azure.Authentication).
4040

41+
#### Code Example
4142

4243
```Csharp
4344
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";//Directory (tenant) ID
@@ -71,6 +72,54 @@ AttachedDatabaseConfiguration attachedDatabaseConfigurationProperties = new Atta
7172
var attachedDatabaseConfigurations = resourceManagementClient.AttachedDatabaseConfigurations.CreateOrUpdate(followerResourceGroupName, followerClusterName, attachedDatabaseConfigurationName, attachedDatabaseConfigurationProperties);
7273
```
7374

75+
### Attach a database using Python
76+
77+
#### Needed Modules
78+
79+
```
80+
pip install azure-common
81+
pip install azure-mgmt-kusto
82+
```
83+
84+
#### Code Example
85+
86+
```python
87+
from azure.mgmt.kusto import KustoManagementClient
88+
from azure.mgmt.kusto.models import AttachedDatabaseConfiguration
89+
from azure.common.credentials import ServicePrincipalCredentials
90+
import datetime
91+
92+
#Directory (tenant) ID
93+
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
94+
#Application ID
95+
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
96+
#Client Secret
97+
client_secret = "xxxxxxxxxxxxxx"
98+
follower_subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
99+
leader_subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
100+
credentials = ServicePrincipalCredentials(
101+
client_id=client_id,
102+
secret=client_secret,
103+
tenant=tenant_id
104+
)
105+
kusto_management_client = KustoManagementClient(credentials, follower_subscription_id)
106+
107+
follower_resource_group_name = "followerResouceGroup"
108+
leader_resouce_group_name = "leaderResouceGroup"
109+
follower_cluster_name = "follower"
110+
leader_cluster_name = "leader"
111+
attached_database_Configuration_name = "adc"
112+
database_name = "db" # Can be specific database name or * for all databases
113+
default_principals_modification_kind = "Union"
114+
location = "North Central US"
115+
cluster_resource_id = "/subscriptions/" + leader_subscription_id + "/resourceGroups/" + leader_resouce_group_name + "/providers/Microsoft.Kusto/Clusters/" + leader_cluster_name
116+
117+
attached_database_configuration_properties = AttachedDatabaseConfiguration(cluster_resource_id = cluster_resource_id, database_name = database_name, default_principals_modification_kind = default_principals_modification_kind, location = location)
118+
119+
#Returns an instance of LROPoller, see https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
120+
poller = kusto_management_client.attached_database_configurations.create_or_update(follower_resource_group_name, follower_cluster_name, attached_database_Configuration_name, attached_database_configuration_properties)
121+
```
122+
74123
### Attach a database using an Azure Resource Manager template
75124

76125
In this section, you learn how to attach a database by using an [Azure Resource Manager template](../azure-resource-manager/resource-group-overview.md).
@@ -190,7 +239,7 @@ Alternatively:
190239

191240
### Detach the attached follower database from the follower cluster
192241

193-
Follower cluster can detach any attached database as follows:
242+
The follower cluster can detach any attached database as follows:
194243

195244
```csharp
196245
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";//Directory (tenant) ID
@@ -242,6 +291,78 @@ var followerDatabaseDefinition = new FollowerDatabaseDefinition()
242291
resourceManagementClient.Clusters.DetachFollowerDatabases(leaderResourceGroupName, leaderClusterName, followerDatabaseDefinition);
243292
```
244293

294+
## Detach the follower database using Python
295+
296+
### Detach the attached follower database from the follower cluster
297+
298+
The follower cluster can detach any attached database as follows:
299+
300+
```python
301+
from azure.mgmt.kusto import KustoManagementClient
302+
from azure.common.credentials import ServicePrincipalCredentials
303+
import datetime
304+
305+
#Directory (tenant) ID
306+
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
307+
#Application ID
308+
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
309+
#Client Secret
310+
client_secret = "xxxxxxxxxxxxxx"
311+
follower_subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
312+
credentials = ServicePrincipalCredentials(
313+
client_id=client_id,
314+
secret=client_secret,
315+
tenant=tenant_id
316+
)
317+
kusto_management_client = KustoManagementClient(credentials, follower_subscription_id)
318+
319+
follower_resource_group_name = "followerResouceGroup"
320+
follower_cluster_name = "follower"
321+
attached_database_configurationName = "adc"
322+
323+
#Returns an instance of LROPoller, see https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
324+
poller = kusto_management_client.attached_database_configurations.delete(follower_resource_group_name, follower_cluster_name, attached_database_configurationName)
325+
```
326+
327+
### Detach the attached follower database from the leader cluster
328+
329+
The leader cluster can detach any attached database as follows:
330+
331+
```python
332+
333+
from azure.mgmt.kusto import KustoManagementClient
334+
from azure.mgmt.kusto.models import FollowerDatabaseDefinition
335+
from azure.common.credentials import ServicePrincipalCredentials
336+
import datetime
337+
338+
#Directory (tenant) ID
339+
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
340+
#Application ID
341+
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
342+
#Client Secret
343+
client_secret = "xxxxxxxxxxxxxx"
344+
follower_subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
345+
leader_subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
346+
credentials = ServicePrincipalCredentials(
347+
client_id=client_id,
348+
secret=client_secret,
349+
tenant=tenant_id
350+
)
351+
kusto_management_client = KustoManagementClient(credentials, follower_subscription_id)
352+
353+
follower_resource_group_name = "followerResourceGroup"
354+
leader_resource_group_name = "leaderResourceGroup"
355+
follower_cluster_name = "follower"
356+
leader_cluster_name = "leader"
357+
attached_database_configuration_name = "adc"
358+
location = "North Central US"
359+
cluster_resource_id = "/subscriptions/" + follower_subscription_id + "/resourceGroups/" + follower_resource_group_name + "/providers/Microsoft.Kusto/Clusters/" + follower_cluster_name
360+
361+
362+
#Returns an instance of LROPoller, see https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
363+
poller = kusto_management_client.clusters.detach_follower_databases(resource_group_name = leader_resource_group_name, cluster_name = leader_cluster_name, cluster_resource_id = cluster_resource_id, attached_database_configuration_name = attached_database_configuration_name)
364+
```
365+
245366
## Manage principals, permissions, and caching policy
246367

247368
### Manage principals

0 commit comments

Comments
 (0)