0
# Resource Management
1
2
Azure Resource Management provides comprehensive Azure resource management capabilities across all service categories. This includes the azure-mgmt meta-package that bundles 40+ management clients for compute, storage, networking, databases, AI services, and more.
3
4
## Overview
5
6
The azure-mgmt meta-package installs a comprehensive set of Azure Resource Manager clients, enabling programmatic management of Azure resources through the Azure Resource Manager APIs. Each service area provides dedicated management clients with full CRUD operations, configuration management, and monitoring capabilities.
7
8
## Core Resource Management
9
10
### Resource Manager Client
11
12
Central client for Azure Resource Manager operations including resource groups, deployments, and resource management.
13
14
```python { .api }
15
class ResourceManagementClient:
16
"""
17
Client for Azure Resource Manager operations.
18
19
Parameters:
20
- credentials: Authentication credentials (ServicePrincipalCredentials)
21
- subscription_id: str, Azure subscription ID
22
"""
23
def __init__(self, credentials, subscription_id: str, **kwargs): ...
24
25
@property
26
def resource_groups(self): ... # Resource group operations
27
28
@property
29
def resources(self): ... # Resource operations
30
31
@property
32
def providers(self): ... # Resource provider operations
33
34
@property
35
def features(self): ... # Feature operations
36
37
@property
38
def tags(self): ... # Tag operations
39
40
@property
41
def deployments(self): ... # Deployment operations
42
43
@property
44
def deployment_operations(self): ... # Deployment operation tracking
45
```
46
47
### Subscription Management
48
49
```python { .api }
50
class SubscriptionClient:
51
"""Client for Azure subscription management operations."""
52
def __init__(self, credentials, **kwargs): ...
53
54
@property
55
def subscriptions(self): ... # Subscription operations
56
57
@property
58
def tenants(self): ... # Tenant operations
59
```
60
61
## Compute Management
62
63
### Virtual Machine Management
64
65
```python { .api }
66
class ComputeManagementClient:
67
"""
68
Client for Azure Compute resource management.
69
70
Parameters:
71
- credentials: Authentication credentials
72
- subscription_id: str, Azure subscription ID
73
"""
74
def __init__(self, credentials, subscription_id: str, **kwargs): ...
75
76
@property
77
def virtual_machines(self): ... # VM operations
78
79
@property
80
def virtual_machine_scale_sets(self): ... # VM Scale Set operations
81
82
@property
83
def availability_sets(self): ... # Availability Set operations
84
85
@property
86
def virtual_machine_sizes(self): ... # VM Size operations
87
88
@property
89
def images(self): ... # Image operations
90
91
@property
92
def usage(self): ... # Usage operations
93
94
@property
95
def disks(self): ... # Managed Disk operations
96
97
@property
98
def snapshots(self): ... # Snapshot operations
99
100
@property
101
def galleries(self): ... # Shared Image Gallery operations
102
103
@property
104
def gallery_images(self): ... # Gallery Image operations
105
106
@property
107
def gallery_image_versions(self): ... # Gallery Image Version operations
108
```
109
110
### Container Services
111
112
```python { .api }
113
class ContainerServiceClient:
114
"""Client for Azure Container Service management."""
115
def __init__(self, credentials, subscription_id: str, **kwargs): ...
116
117
@property
118
def container_services(self): ... # Container service operations
119
120
class ContainerInstanceManagementClient:
121
"""Client for Azure Container Instances management."""
122
def __init__(self, credentials, subscription_id: str, **kwargs): ...
123
124
@property
125
def container_groups(self): ... # Container group operations
126
127
@property
128
def container_group_usage(self): ... # Usage operations
129
130
class ContainerRegistryManagementClient:
131
"""Client for Azure Container Registry management."""
132
def __init__(self, credentials, subscription_id: str, **kwargs): ...
133
134
@property
135
def registries(self): ... # Registry operations
136
137
@property
138
def operations(self): ... # Available operations
139
140
@property
141
def replications(self): ... # Registry replication operations
142
143
@property
144
def webhooks(self): ... # Webhook operations
145
```
146
147
## Storage Management
148
149
### Storage Account Management
150
151
```python { .api }
152
class StorageManagementClient:
153
"""
154
Client for Azure Storage account management.
155
156
Parameters:
157
- credentials: Authentication credentials
158
- subscription_id: str, Azure subscription ID
159
"""
160
def __init__(self, credentials, subscription_id: str, **kwargs): ...
161
162
@property
163
def storage_accounts(self): ... # Storage account operations
164
165
@property
166
def usage(self): ... # Storage usage operations
167
168
@property
169
def management_policies(self): ... # Lifecycle management policies
170
171
@property
172
def blob_inventory_policies(self): ... # Blob inventory policies
173
174
@property
175
def private_endpoint_connections(self): ... # Private endpoint operations
176
177
@property
178
def private_link_resources(self): ... # Private link resources
179
180
@property
181
def object_replication_policies(self): ... # Object replication policies
182
183
@property
184
def encryption_scopes(self): ... # Encryption scope operations
185
```
186
187
## Network Management
188
189
### Virtual Network Management
190
191
```python { .api }
192
class NetworkManagementClient:
193
"""
194
Client for Azure Virtual Network management.
195
196
Parameters:
197
- credentials: Authentication credentials
198
- subscription_id: str, Azure subscription ID
199
"""
200
def __init__(self, credentials, subscription_id: str, **kwargs): ...
201
202
@property
203
def virtual_networks(self): ... # Virtual network operations
204
205
@property
206
def subnets(self): ... # Subnet operations
207
208
@property
209
def network_interfaces(self): ... # Network interface operations
210
211
@property
212
def public_ip_addresses(self): ... # Public IP operations
213
214
@property
215
def network_security_groups(self): ... # NSG operations
216
217
@property
218
def security_rules(self): ... # Security rule operations
219
220
@property
221
def route_tables(self): ... # Route table operations
222
223
@property
224
def routes(self): ... # Route operations
225
226
@property
227
def load_balancers(self): ... # Load balancer operations
228
229
@property
230
def application_gateways(self): ... # Application gateway operations
231
232
@property
233
def virtual_network_gateways(self): ... # VPN gateway operations
234
235
@property
236
def local_network_gateways(self): ... # Local network gateway operations
237
238
@property
239
def virtual_network_gateway_connections(self): ... # VPN connections
240
241
@property
242
def express_route_circuits(self): ... # ExpressRoute circuit operations
243
244
@property
245
def express_route_circuit_authorizations(self): ... # ExpressRoute authorizations
246
247
@property
248
def express_route_circuit_peerings(self): ... # ExpressRoute peering operations
249
250
@property
251
def network_watchers(self): ... # Network Watcher operations
252
253
@property
254
def packet_captures(self): ... # Packet capture operations
255
256
@property
257
def connection_monitors(self): ... # Connection monitor operations
258
```
259
260
### Traffic Manager
261
262
```python { .api }
263
class TrafficManagerManagementClient:
264
"""Client for Azure Traffic Manager management."""
265
def __init__(self, credentials, subscription_id: str, **kwargs): ...
266
267
@property
268
def profiles(self): ... # Traffic Manager profile operations
269
270
@property
271
def endpoints(self): ... # Endpoint operations
272
273
@property
274
def geographic_hierarchies(self): ... # Geographic hierarchy operations
275
276
@property
277
def heat_map(self): ... # Traffic heat map operations
278
279
@property
280
def traffic_manager_user_metrics_keys(self): ... # User metrics operations
281
```
282
283
## Database Management
284
285
### SQL Database Management
286
287
```python { .api }
288
class SqlManagementClient:
289
"""
290
Client for Azure SQL Database management.
291
292
Parameters:
293
- credentials: Authentication credentials
294
- subscription_id: str, Azure subscription ID
295
"""
296
def __init__(self, credentials, subscription_id: str, **kwargs): ...
297
298
@property
299
def servers(self): ... # SQL Server operations
300
301
@property
302
def server_connection_policies(self): ... # Connection policy operations
303
304
@property
305
def database_threat_detection_policies(self): ... # Threat detection policies
306
307
@property
308
def backup_short_term_retention_policies(self): ... # Backup retention policies
309
310
@property
311
def restore_points(self): ... # Restore point operations
312
313
@property
314
def recoverable_databases(self): ... # Recoverable database operations
315
316
@property
317
def restorable_dropped_databases(self): ... # Dropped database operations
318
319
@property
320
def databases(self): ... # Database operations
321
322
@property
323
def elastic_pools(self): ... # Elastic pool operations
324
325
@property
326
def recommended_elastic_pools(self): ... # Recommended pool operations
327
328
@property
329
def replication_links(self): ... # Replication link operations
330
331
@property
332
def server_azure_ad_administrators(self): ... # Azure AD admin operations
333
334
@property
335
def server_communication_links(self): ... # Server communication operations
336
337
@property
338
def service_objectives(self): ... # Service objective operations
339
340
@property
341
def firewall_rules(self): ... # Firewall rule operations
342
343
@property
344
def elastic_pool_activities(self): ... # Pool activity operations
345
346
@property
347
def elastic_pool_database_activities(self): ... # Pool database activities
348
349
@property
350
def service_tier_advisors(self): ... # Service tier advisor operations
351
352
@property
353
def transparent_data_encryptions(self): ... # TDE operations
354
355
@property
356
def transparent_data_encryption_activities(self): ... # TDE activities
357
358
@property
359
def server_usage_metrics(self): ... # Server usage metrics
360
361
@property
362
def database_usage_metrics(self): ... # Database usage metrics
363
```
364
365
### Cosmos DB Management
366
367
```python { .api }
368
class CosmosDBManagementClient:
369
"""Client for Azure Cosmos DB management."""
370
def __init__(self, credentials, subscription_id: str, **kwargs): ...
371
372
@property
373
def database_accounts(self): ... # Database account operations
374
375
@property
376
def operations(self): ... # Available operations
377
378
@property
379
def database(self): ... # Database operations
380
381
@property
382
def collection(self): ... # Collection operations
383
384
@property
385
def collection_region(self): ... # Collection region operations
386
387
@property
388
def database_account_region(self): ... # Account region operations
389
390
@property
391
def percentile_source_target(self): ... # Percentile operations
392
393
@property
394
def percentile_target(self): ... # Target percentile operations
395
396
@property
397
def percentile(self): ... # Percentile metrics
398
399
@property
400
def collection_partition_region(self): ... # Partition region operations
401
402
@property
403
def collection_partition(self): ... # Partition operations
404
405
@property
406
def partition_key_range_id(self): ... # Partition key range operations
407
408
@property
409
def partition_key_range_id_region(self): ... # Partition key range region operations
410
411
@property
412
def sql_resources(self): ... # SQL API resources
413
414
@property
415
def mongo_db_resources(self): ... # MongoDB API resources
416
417
@property
418
def table_resources(self): ... # Table API resources
419
420
@property
421
def cassandra_resources(self): ... # Cassandra API resources
422
423
@property
424
def gremlin_resources(self): ... # Gremlin API resources
425
426
@property
427
def notebook_workspaces(self): ... # Notebook workspace operations
428
429
@property
430
def private_endpoint_connections(self): ... # Private endpoint operations
431
432
@property
433
def private_link_resources(self): ... # Private link resources
434
435
@property
436
def restorable_database_accounts(self): ... # Restorable account operations
437
438
@property
439
def restorable_sql_databases(self): ... # Restorable SQL database operations
440
441
@property
442
def restorable_sql_containers(self): ... # Restorable SQL container operations
443
444
@property
445
def restorable_sql_resources(self): ... # Restorable SQL resource operations
446
447
@property
448
def restorable_mongodb_databases(self): ... # Restorable MongoDB database operations
449
450
@property
451
def restorable_mongodb_collections(self): ... # Restorable MongoDB collection operations
452
453
@property
454
def restorable_mongodb_resources(self): ... # Restorable MongoDB resource operations
455
```
456
457
## Key Vault Management
458
459
```python { .api }
460
class KeyVaultManagementClient:
461
"""Client for Azure Key Vault management."""
462
def __init__(self, credentials, subscription_id: str, **kwargs): ...
463
464
@property
465
def vaults(self): ... # Key Vault operations
466
467
@property
468
def private_endpoint_connections(self): ... # Private endpoint operations
469
470
@property
471
def private_link_resources(self): ... # Private link resources
472
473
@property
474
def managed_hsms(self): ... # Managed HSM operations
475
476
@property
477
def mhsm_private_endpoint_connections(self): ... # HSM private endpoints
478
479
@property
480
def mhsm_private_link_resources(self): ... # HSM private link resources
481
482
@property
483
def keys(self): ... # Key operations
484
485
@property
486
def secrets(self): ... # Secret operations
487
```
488
489
## AI and Cognitive Services Management
490
491
```python { .api }
492
class CognitiveServicesManagementClient:
493
"""Client for Azure Cognitive Services management."""
494
def __init__(self, credentials, subscription_id: str, **kwargs): ...
495
496
@property
497
def accounts(self): ... # Cognitive Services account operations
498
499
@property
500
def resource_skus(self): ... # Available SKU operations
501
502
@property
503
def operations(self): ... # Available operations
504
505
@property
506
def check_domain_availability(self): ... # Domain availability operations
507
508
@property
509
def private_endpoint_connections(self): ... # Private endpoint operations
510
511
@property
512
def private_link_resources(self): ... # Private link resources
513
514
@property
515
def deployments(self): ... # Model deployment operations
516
```
517
518
## Monitoring and Management
519
520
### Monitor Management
521
522
```python { .api }
523
class MonitorManagementClient:
524
"""Client for Azure Monitor management."""
525
def __init__(self, credentials, subscription_id: str, **kwargs): ...
526
527
@property
528
def autoscale_settings(self): ... # Autoscale setting operations
529
530
@property
531
def operations(self): ... # Available operations
532
533
@property
534
def alert_rule_incidents(self): ... # Alert rule incident operations
535
536
@property
537
def alert_rules(self): ... # Alert rule operations
538
539
@property
540
def log_profiles(self): ... # Log profile operations
541
542
@property
543
def diagnostic_settings(self): ... # Diagnostic setting operations
544
545
@property
546
def diagnostic_settings_category(self): ... # Diagnostic category operations
547
548
@property
549
def action_groups(self): ... # Action group operations
550
551
@property
552
def activity_log_alerts(self): ... # Activity log alert operations
553
554
@property
555
def activity_logs(self): ... # Activity log operations
556
557
@property
558
def event_categories(self): ... # Event category operations
559
560
@property
561
def tenant_activity_logs(self): ... # Tenant activity log operations
562
563
@property
564
def metric_definitions(self): ... # Metric definition operations
565
566
@property
567
def metrics(self): ... # Metric operations
568
569
@property
570
def metric_alerts(self): ... # Metric alert operations
571
572
@property
573
def metric_alerts_status(self): ... # Metric alert status operations
574
575
@property
576
def scheduled_query_rules(self): ... # Scheduled query rule operations
577
578
@property
579
def metric_namespaces(self): ... # Metric namespace operations
580
581
@property
582
def vm_insights(self): ... # VM insights operations
583
```
584
585
## Usage Examples
586
587
### Creating Resource Groups and Resources
588
589
```python
590
from azure.mgmt.resource import ResourceManagementClient
591
from azure.mgmt.compute import ComputeManagementClient
592
from azure.mgmt.network import NetworkManagementClient
593
from azure.common.credentials import ServicePrincipalCredentials
594
595
# Set up authentication
596
credentials = ServicePrincipalCredentials(
597
client_id=client_id,
598
secret=client_secret,
599
tenant=tenant_id
600
)
601
602
# Create management clients
603
resource_client = ResourceManagementClient(credentials, subscription_id)
604
compute_client = ComputeManagementClient(credentials, subscription_id)
605
network_client = NetworkManagementClient(credentials, subscription_id)
606
607
# Create resource group
608
resource_group_params = {
609
'location': 'East US',
610
'tags': {
611
'environment': 'production',
612
'project': 'myproject'
613
}
614
}
615
616
resource_group = resource_client.resource_groups.create_or_update(
617
'myresourcegroup',
618
resource_group_params
619
)
620
621
print(f"Created resource group: {resource_group.name}")
622
623
# List resource groups
624
resource_groups = resource_client.resource_groups.list()
625
for rg in resource_groups:
626
print(f"Resource Group: {rg.name}, Location: {rg.location}")
627
```
628
629
### Managing Virtual Machines
630
631
```python
632
from azure.mgmt.compute.models import VirtualMachine, HardwareProfile, StorageProfile, OSProfile
633
634
# Create a virtual machine
635
vm_parameters = VirtualMachine(
636
location='East US',
637
hardware_profile=HardwareProfile(vm_size='Standard_B1s'),
638
storage_profile=StorageProfile(
639
image_reference={
640
'publisher': 'Canonical',
641
'offer': 'UbuntuServer',
642
'sku': '18.04-LTS',
643
'version': 'latest'
644
}
645
),
646
os_profile=OSProfile(
647
computer_name='myvm',
648
admin_username='azureuser',
649
admin_password='MyPassword123!'
650
),
651
network_profile={
652
'network_interfaces': [{
653
'id': network_interface_id
654
}]
655
}
656
)
657
658
# Create the VM
659
vm_operation = compute_client.virtual_machines.create_or_update(
660
'myresourcegroup',
661
'myvm',
662
vm_parameters
663
)
664
665
vm_result = vm_operation.result()
666
print(f"Created VM: {vm_result.name}")
667
668
# List VMs
669
vms = compute_client.virtual_machines.list('myresourcegroup')
670
for vm in vms:
671
print(f"VM: {vm.name}, Status: {vm.provisioning_state}")
672
673
# Start/Stop VM
674
print("Starting VM...")
675
start_operation = compute_client.virtual_machines.start('myresourcegroup', 'myvm')
676
start_operation.wait()
677
678
print("Stopping VM...")
679
stop_operation = compute_client.virtual_machines.power_off('myresourcegroup', 'myvm')
680
stop_operation.wait()
681
```
682
683
### Managing Storage Accounts
684
685
```python
686
from azure.mgmt.storage import StorageManagementClient
687
from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku, Kind
688
689
storage_client = StorageManagementClient(credentials, subscription_id)
690
691
# Create storage account
692
storage_account_params = StorageAccountCreateParameters(
693
sku=Sku(name='Standard_LRS'),
694
kind=Kind.storage_v2,
695
location='East US',
696
tags={
697
'environment': 'production'
698
}
699
)
700
701
storage_operation = storage_client.storage_accounts.create(
702
'myresourcegroup',
703
'mystorageaccount',
704
storage_account_params
705
)
706
707
storage_account = storage_operation.result()
708
print(f"Created storage account: {storage_account.name}")
709
710
# Get storage account keys
711
keys = storage_client.storage_accounts.list_keys('myresourcegroup', 'mystorageaccount')
712
primary_key = keys.keys[0].value
713
print(f"Primary key: {primary_key}")
714
715
# List storage accounts
716
storage_accounts = storage_client.storage_accounts.list_by_resource_group('myresourcegroup')
717
for account in storage_accounts:
718
print(f"Storage Account: {account.name}, SKU: {account.sku.name}")
719
```
720
721
### Managing SQL Database
722
723
```python
724
from azure.mgmt.sql import SqlManagementClient
725
from azure.mgmt.sql.models import Server, ServerForCreate, Database
726
727
sql_client = SqlManagementClient(credentials, subscription_id)
728
729
# Create SQL Server
730
server_params = Server(
731
location='East US',
732
administrator_login='sqladmin',
733
administrator_login_password='MyPassword123!',
734
version='12.0'
735
)
736
737
server_operation = sql_client.servers.create_or_update(
738
'myresourcegroup',
739
'mysqlserver',
740
server_params
741
)
742
743
server = server_operation.result()
744
print(f"Created SQL Server: {server.name}")
745
746
# Create database
747
database_params = Database(
748
location='East US',
749
requested_service_objective_name='S0'
750
)
751
752
database_operation = sql_client.databases.create_or_update(
753
'myresourcegroup',
754
'mysqlserver',
755
'mydatabase',
756
database_params
757
)
758
759
database = database_operation.result()
760
print(f"Created database: {database.name}")
761
762
# List databases
763
databases = sql_client.databases.list_by_server('myresourcegroup', 'mysqlserver')
764
for db in databases:
765
if db.name != 'master': # Skip system database
766
print(f"Database: {db.name}, Status: {db.status}")
767
```
768
769
### Monitoring and Metrics
770
771
```python
772
from azure.mgmt.monitor import MonitorManagementClient
773
from datetime import datetime, timedelta
774
775
monitor_client = MonitorManagementClient(credentials, subscription_id)
776
777
# Get metrics for a resource
778
resource_uri = f"/subscriptions/{subscription_id}/resourceGroups/myresourcegroup/providers/Microsoft.Compute/virtualMachines/myvm"
779
780
# Define time range
781
end_time = datetime.utcnow()
782
start_time = end_time - timedelta(hours=1)
783
784
# Get CPU percentage metrics
785
metrics = monitor_client.metrics.list(
786
resource_uri,
787
timespan=f"{start_time.isoformat()}/{end_time.isoformat()}",
788
interval='PT5M', # 5-minute intervals
789
metricnames='Percentage CPU',
790
aggregation='Average'
791
)
792
793
for metric in metrics.value:
794
print(f"Metric: {metric.name.value}")
795
for timeseries in metric.timeseries:
796
for data_point in timeseries.data:
797
print(f" {data_point.time_stamp}: {data_point.average}%")
798
799
# List available metrics for a resource
800
metric_definitions = monitor_client.metric_definitions.list(resource_uri)
801
print("Available metrics:")
802
for metric_def in metric_definitions:
803
print(f" {metric_def.name.value} ({metric_def.unit})")
804
```