0
# Infrastructure Management
1
2
Management of supporting infrastructure including availability sets, proximity placement groups, dedicated hosts, capacity reservations, and SSH public keys. These components provide high availability, performance optimization, and resource management capabilities for Azure compute deployments.
3
4
## Capabilities
5
6
### Availability Set Management
7
8
Operations for managing availability sets to ensure high availability across fault and update domains.
9
10
```python { .api }
11
class AvailabilitySetsOperations:
12
def create_or_update(
13
resource_group_name: str,
14
availability_set_name: str,
15
parameters: AvailabilitySet
16
) -> AvailabilitySet:
17
"""
18
Create or update an availability set.
19
20
Args:
21
resource_group_name: Name of the resource group
22
availability_set_name: Name of the availability set
23
parameters: Availability set configuration
24
25
Returns:
26
Availability set details
27
"""
28
29
def delete(resource_group_name: str, availability_set_name: str) -> None:
30
"""
31
Delete an availability set.
32
33
Args:
34
resource_group_name: Name of the resource group
35
availability_set_name: Name of the availability set
36
"""
37
38
def get(resource_group_name: str, availability_set_name: str) -> AvailabilitySet:
39
"""
40
Get availability set details.
41
42
Args:
43
resource_group_name: Name of the resource group
44
availability_set_name: Name of the availability set
45
46
Returns:
47
Availability set details
48
"""
49
50
def list(resource_group_name: str) -> Iterable[AvailabilitySet]:
51
"""
52
List availability sets in a resource group.
53
54
Args:
55
resource_group_name: Name of the resource group
56
57
Returns:
58
Iterable of availability sets
59
"""
60
61
def list_available_sizes(
62
resource_group_name: str,
63
availability_set_name: str
64
) -> Iterable[VirtualMachineSize]:
65
"""
66
List available VM sizes for an availability set.
67
68
Args:
69
resource_group_name: Name of the resource group
70
availability_set_name: Name of the availability set
71
72
Returns:
73
Iterable of available VM sizes
74
"""
75
```
76
77
### Proximity Placement Group Management
78
79
Operations for managing proximity placement groups to optimize network latency.
80
81
```python { .api }
82
class ProximityPlacementGroupsOperations:
83
def create_or_update(
84
resource_group_name: str,
85
proximity_placement_group_name: str,
86
parameters: ProximityPlacementGroup
87
) -> ProximityPlacementGroup:
88
"""
89
Create or update a proximity placement group.
90
91
Args:
92
resource_group_name: Name of the resource group
93
proximity_placement_group_name: Name of the proximity placement group
94
parameters: Proximity placement group configuration
95
96
Returns:
97
Proximity placement group details
98
"""
99
100
def delete(resource_group_name: str, proximity_placement_group_name: str) -> None:
101
"""
102
Delete a proximity placement group.
103
104
Args:
105
resource_group_name: Name of the resource group
106
proximity_placement_group_name: Name of the proximity placement group
107
"""
108
109
def get(
110
resource_group_name: str,
111
proximity_placement_group_name: str
112
) -> ProximityPlacementGroup:
113
"""
114
Get proximity placement group details.
115
116
Args:
117
resource_group_name: Name of the resource group
118
proximity_placement_group_name: Name of the proximity placement group
119
120
Returns:
121
Proximity placement group details
122
"""
123
124
def list_by_resource_group(resource_group_name: str) -> Iterable[ProximityPlacementGroup]:
125
"""
126
List proximity placement groups in a resource group.
127
128
Args:
129
resource_group_name: Name of the resource group
130
131
Returns:
132
Iterable of proximity placement groups
133
"""
134
135
def list_by_subscription() -> Iterable[ProximityPlacementGroup]:
136
"""
137
List all proximity placement groups in the subscription.
138
139
Returns:
140
Iterable of all proximity placement groups
141
"""
142
```
143
144
### Dedicated Host Management
145
146
Operations for managing dedicated hosts for single-tenant deployments.
147
148
```python { .api }
149
class DedicatedHostsOperations:
150
def begin_create_or_update(
151
resource_group_name: str,
152
host_group_name: str,
153
host_name: str,
154
parameters: DedicatedHost
155
) -> LROPoller[DedicatedHost]:
156
"""
157
Create or update a dedicated host.
158
159
Args:
160
resource_group_name: Name of the resource group
161
host_group_name: Name of the dedicated host group
162
host_name: Name of the dedicated host
163
parameters: Dedicated host configuration
164
165
Returns:
166
Long-running operation poller for DedicatedHost
167
"""
168
169
def begin_delete(
170
resource_group_name: str,
171
host_group_name: str,
172
host_name: str
173
) -> LROPoller[None]:
174
"""
175
Delete a dedicated host.
176
177
Args:
178
resource_group_name: Name of the resource group
179
host_group_name: Name of the dedicated host group
180
host_name: Name of the dedicated host
181
182
Returns:
183
Long-running operation poller
184
"""
185
186
def get(
187
resource_group_name: str,
188
host_group_name: str,
189
host_name: str
190
) -> DedicatedHost:
191
"""
192
Get dedicated host details.
193
194
Args:
195
resource_group_name: Name of the resource group
196
host_group_name: Name of the dedicated host group
197
host_name: Name of the dedicated host
198
199
Returns:
200
Dedicated host details
201
"""
202
203
def list_by_host_group(
204
resource_group_name: str,
205
host_group_name: str
206
) -> Iterable[DedicatedHost]:
207
"""
208
List dedicated hosts in a host group.
209
210
Args:
211
resource_group_name: Name of the resource group
212
host_group_name: Name of the dedicated host group
213
214
Returns:
215
Iterable of dedicated hosts
216
"""
217
```
218
219
### Dedicated Host Group Management
220
221
Operations for managing dedicated host groups.
222
223
```python { .api }
224
class DedicatedHostGroupsOperations:
225
def create_or_update(
226
resource_group_name: str,
227
host_group_name: str,
228
parameters: DedicatedHostGroup
229
) -> DedicatedHostGroup:
230
"""
231
Create or update a dedicated host group.
232
233
Args:
234
resource_group_name: Name of the resource group
235
host_group_name: Name of the dedicated host group
236
parameters: Host group configuration
237
238
Returns:
239
Dedicated host group details
240
"""
241
242
def delete(resource_group_name: str, host_group_name: str) -> None:
243
"""
244
Delete a dedicated host group.
245
246
Args:
247
resource_group_name: Name of the resource group
248
host_group_name: Name of the dedicated host group
249
"""
250
251
def get(resource_group_name: str, host_group_name: str) -> DedicatedHostGroup:
252
"""
253
Get dedicated host group details.
254
255
Args:
256
resource_group_name: Name of the resource group
257
host_group_name: Name of the dedicated host group
258
259
Returns:
260
Dedicated host group details
261
"""
262
263
def list_by_resource_group(resource_group_name: str) -> Iterable[DedicatedHostGroup]:
264
"""
265
List dedicated host groups in a resource group.
266
267
Args:
268
resource_group_name: Name of the resource group
269
270
Returns:
271
Iterable of dedicated host groups
272
"""
273
274
def list_by_subscription() -> Iterable[DedicatedHostGroup]:
275
"""
276
List all dedicated host groups in the subscription.
277
278
Returns:
279
Iterable of all dedicated host groups
280
"""
281
```
282
283
### Capacity Reservation Management
284
285
Operations for managing capacity reservations to guarantee compute capacity.
286
287
```python { .api }
288
class CapacityReservationsOperations:
289
def begin_create_or_update(
290
resource_group_name: str,
291
capacity_reservation_group_name: str,
292
capacity_reservation_name: str,
293
parameters: CapacityReservation
294
) -> LROPoller[CapacityReservation]:
295
"""
296
Create or update a capacity reservation.
297
298
Args:
299
resource_group_name: Name of the resource group
300
capacity_reservation_group_name: Name of the capacity reservation group
301
capacity_reservation_name: Name of the capacity reservation
302
parameters: Capacity reservation configuration
303
304
Returns:
305
Long-running operation poller for CapacityReservation
306
"""
307
308
def begin_delete(
309
resource_group_name: str,
310
capacity_reservation_group_name: str,
311
capacity_reservation_name: str
312
) -> LROPoller[None]:
313
"""
314
Delete a capacity reservation.
315
316
Args:
317
resource_group_name: Name of the resource group
318
capacity_reservation_group_name: Name of the capacity reservation group
319
capacity_reservation_name: Name of the capacity reservation
320
321
Returns:
322
Long-running operation poller
323
"""
324
325
def get(
326
resource_group_name: str,
327
capacity_reservation_group_name: str,
328
capacity_reservation_name: str
329
) -> CapacityReservation:
330
"""
331
Get capacity reservation details.
332
333
Args:
334
resource_group_name: Name of the resource group
335
capacity_reservation_group_name: Name of the capacity reservation group
336
capacity_reservation_name: Name of the capacity reservation
337
338
Returns:
339
Capacity reservation details
340
"""
341
342
def list_by_capacity_reservation_group(
343
resource_group_name: str,
344
capacity_reservation_group_name: str
345
) -> Iterable[CapacityReservation]:
346
"""
347
List capacity reservations in a group.
348
349
Args:
350
resource_group_name: Name of the resource group
351
capacity_reservation_group_name: Name of the capacity reservation group
352
353
Returns:
354
Iterable of capacity reservations
355
"""
356
```
357
358
### SSH Public Key Management
359
360
Operations for managing SSH public keys for Linux VM authentication.
361
362
```python { .api }
363
class SshPublicKeysOperations:
364
def create(
365
resource_group_name: str,
366
ssh_public_key_name: str,
367
parameters: SshPublicKeyResource
368
) -> SshPublicKeyResource:
369
"""
370
Create an SSH public key resource.
371
372
Args:
373
resource_group_name: Name of the resource group
374
ssh_public_key_name: Name of the SSH public key resource
375
parameters: SSH public key configuration
376
377
Returns:
378
SSH public key resource details
379
"""
380
381
def delete(resource_group_name: str, ssh_public_key_name: str) -> None:
382
"""
383
Delete an SSH public key resource.
384
385
Args:
386
resource_group_name: Name of the resource group
387
ssh_public_key_name: Name of the SSH public key resource
388
"""
389
390
def get(resource_group_name: str, ssh_public_key_name: str) -> SshPublicKeyResource:
391
"""
392
Get SSH public key resource details.
393
394
Args:
395
resource_group_name: Name of the resource group
396
ssh_public_key_name: Name of the SSH public key resource
397
398
Returns:
399
SSH public key resource details
400
"""
401
402
def list_by_resource_group(resource_group_name: str) -> Iterable[SshPublicKeyResource]:
403
"""
404
List SSH public keys in a resource group.
405
406
Args:
407
resource_group_name: Name of the resource group
408
409
Returns:
410
Iterable of SSH public key resources
411
"""
412
413
def list_by_subscription() -> Iterable[SshPublicKeyResource]:
414
"""
415
List all SSH public keys in the subscription.
416
417
Returns:
418
Iterable of all SSH public key resources
419
"""
420
421
def generate_key_pair(
422
resource_group_name: str,
423
ssh_public_key_name: str
424
) -> SshPublicKeyGenerateKeyPairResult:
425
"""
426
Generate a new SSH key pair.
427
428
Args:
429
resource_group_name: Name of the resource group
430
ssh_public_key_name: Name of the SSH public key resource
431
432
Returns:
433
Generated SSH key pair with public and private keys
434
"""
435
```
436
437
## Data Types
438
439
```python { .api }
440
class AvailabilitySet:
441
"""Specifies information about the availability set."""
442
id: Optional[str]
443
name: Optional[str]
444
type: Optional[str]
445
location: str
446
tags: Optional[Dict[str, str]]
447
platform_update_domain_count: Optional[int]
448
platform_fault_domain_count: Optional[int]
449
virtual_machines: Optional[List[SubResource]]
450
proximity_placement_group: Optional[SubResource]
451
statuses: Optional[List[InstanceViewStatus]]
452
sku: Optional[Sku]
453
454
class ProximityPlacementGroup:
455
"""Specifies information about the proximity placement group."""
456
id: Optional[str]
457
name: Optional[str]
458
type: Optional[str]
459
location: str
460
tags: Optional[Dict[str, str]]
461
proximity_placement_group_type: Optional[ProximityPlacementGroupType]
462
virtual_machines: Optional[List[SubResource]]
463
virtual_machine_scale_sets: Optional[List[SubResource]]
464
availability_sets: Optional[List[SubResource]]
465
colocation_status: Optional[InstanceViewStatus]
466
intent: Optional[ProximityPlacementGroupPropertiesIntent]
467
zones: Optional[List[str]]
468
469
class DedicatedHost:
470
"""Specifies information about the Dedicated host."""
471
id: Optional[str]
472
name: Optional[str]
473
type: Optional[str]
474
location: str
475
tags: Optional[Dict[str, str]]
476
sku: Sku
477
platform_fault_domain: Optional[int]
478
auto_replace_on_failure: Optional[bool]
479
host_id: Optional[str]
480
virtual_machines: Optional[List[SubResource]]
481
license_type: Optional[DedicatedHostLicenseTypes]
482
provisioning_time: Optional[datetime]
483
provisioning_state: Optional[str]
484
instance_view: Optional[DedicatedHostInstanceView]
485
time_created: Optional[datetime]
486
487
class DedicatedHostGroup:
488
"""Specifies information about the dedicated host group."""
489
id: Optional[str]
490
name: Optional[str]
491
type: Optional[str]
492
location: str
493
tags: Optional[Dict[str, str]]
494
zones: Optional[List[str]]
495
platform_fault_domain_count: int
496
hosts: Optional[List[SubResource]]
497
instance_view: Optional[DedicatedHostGroupInstanceView]
498
support_automatic_placement: Optional[bool]
499
additional_capabilities: Optional[DedicatedHostGroupPropertiesAdditionalCapabilities]
500
501
class CapacityReservation:
502
"""Specifies information about the capacity reservation."""
503
id: Optional[str]
504
name: Optional[str]
505
type: Optional[str]
506
location: str
507
tags: Optional[Dict[str, str]]
508
sku: Sku
509
zones: Optional[List[str]]
510
time_created: Optional[datetime]
511
provisioning_time: Optional[datetime]
512
provisioning_state: Optional[str]
513
instance_view: Optional[CapacityReservationInstanceView]
514
platform_fault_domain_count: Optional[int]
515
516
class CapacityReservationGroup:
517
"""Specifies information about the capacity reservation group."""
518
id: Optional[str]
519
name: Optional[str]
520
type: Optional[str]
521
location: str
522
tags: Optional[Dict[str, str]]
523
zones: Optional[List[str]]
524
capacity_reservations: Optional[List[SubResource]]
525
virtual_machines_associated: Optional[List[SubResource]]
526
instance_view: Optional[CapacityReservationGroupInstanceView]
527
sharing_profile: Optional[ResourceSharingProfile]
528
529
class SshPublicKeyResource:
530
"""Specifies information about the SSH public key."""
531
id: Optional[str]
532
name: Optional[str]
533
type: Optional[str]
534
location: str
535
tags: Optional[Dict[str, str]]
536
public_key: Optional[str]
537
538
class SshPublicKeyGenerateKeyPairResult:
539
"""Response from generation of an SSH key pair."""
540
private_key: str
541
public_key: str
542
id: str
543
```
544
545
## Usage Examples
546
547
### Create High Availability Setup
548
549
```python
550
from azure.identity import DefaultAzureCredential
551
from azure.mgmt.compute import ComputeManagementClient
552
553
credential = DefaultAzureCredential()
554
compute_client = ComputeManagementClient(credential, "subscription-id")
555
556
# Create availability set for high availability
557
availability_set_parameters = {
558
'location': 'East US',
559
'platform_fault_domain_count': 2,
560
'platform_update_domain_count': 5,
561
'sku': {
562
'name': 'Aligned' # For managed disks
563
},
564
'tags': {
565
'purpose': 'high-availability',
566
'application': 'web-tier'
567
}
568
}
569
570
availability_set = compute_client.availability_sets.create_or_update(
571
'myResourceGroup',
572
'myAvailabilitySet',
573
availability_set_parameters
574
)
575
print(f"Availability set created: {availability_set.name}")
576
577
# Create proximity placement group for low latency
578
ppg_parameters = {
579
'location': 'East US',
580
'proximity_placement_group_type': 'Standard',
581
'tags': {
582
'purpose': 'low-latency',
583
'tier': 'database'
584
}
585
}
586
587
ppg = compute_client.proximity_placement_groups.create_or_update(
588
'myResourceGroup',
589
'myProximityGroup',
590
ppg_parameters
591
)
592
print(f"Proximity placement group created: {ppg.name}")
593
```
594
595
### Setup Dedicated Hosting
596
597
```python
598
# Create dedicated host group
599
host_group_parameters = {
600
'location': 'East US',
601
'platform_fault_domain_count': 2,
602
'support_automatic_placement': True,
603
'tags': {
604
'purpose': 'dedicated-hosting',
605
'compliance': 'required'
606
}
607
}
608
609
host_group = compute_client.dedicated_host_groups.create_or_update(
610
'myResourceGroup',
611
'myHostGroup',
612
host_group_parameters
613
)
614
615
# Create dedicated host
616
host_parameters = {
617
'location': 'East US',
618
'sku': {
619
'name': 'DSv3-Type1'
620
},
621
'platform_fault_domain': 0,
622
'auto_replace_on_failure': True,
623
'license_type': 'Windows_Server_Hybrid'
624
}
625
626
operation = compute_client.dedicated_hosts.begin_create_or_update(
627
'myResourceGroup',
628
'myHostGroup',
629
'myDedicatedHost',
630
host_parameters
631
)
632
dedicated_host = operation.result()
633
print(f"Dedicated host created: {dedicated_host.name}")
634
635
# Check host capacity
636
instance_view = dedicated_host.instance_view
637
if instance_view and instance_view.available_capacity:
638
for capacity in instance_view.available_capacity.allocatable_v_ms:
639
print(f"VM Size: {capacity.vm_size}, Count: {capacity.count}")
640
```
641
642
### Reserve Compute Capacity
643
644
```python
645
# Create capacity reservation group
646
crg_parameters = {
647
'location': 'East US',
648
'zones': ['1', '2'],
649
'tags': {
650
'purpose': 'guaranteed-capacity',
651
'workload': 'critical'
652
}
653
}
654
655
crg = compute_client.capacity_reservation_groups.create_or_update(
656
'myResourceGroup',
657
'myCapacityGroup',
658
crg_parameters
659
)
660
661
# Create capacity reservation
662
reservation_parameters = {
663
'location': 'East US',
664
'sku': {
665
'name': 'Standard_D2s_v3',
666
'capacity': 10 # Reserve 10 instances
667
},
668
'zones': ['1'],
669
'tags': {
670
'reservation_for': 'peak_hours'
671
}
672
}
673
674
operation = compute_client.capacity_reservations.begin_create_or_update(
675
'myResourceGroup',
676
'myCapacityGroup',
677
'myCapacityReservation',
678
reservation_parameters
679
)
680
reservation = operation.result()
681
print(f"Capacity reservation created: {reservation.name}")
682
683
# Monitor reservation utilization
684
instance_view = reservation.instance_view
685
if instance_view:
686
utilization = instance_view.utilization_info
687
print(f"Reserved: {utilization.virtual_machines_allocated}")
688
print(f"Available: {reservation.sku.capacity - len(utilization.virtual_machines_allocated)}")
689
```
690
691
### Manage SSH Keys
692
693
```python
694
# Create SSH public key resource
695
ssh_key_parameters = {
696
'location': 'East US',
697
'tags': {
698
'owner': 'admin',
699
'purpose': 'linux-vms'
700
}
701
}
702
703
ssh_key = compute_client.ssh_public_keys.create(
704
'myResourceGroup',
705
'mySSHKey',
706
ssh_key_parameters
707
)
708
709
# Generate new SSH key pair
710
key_pair = compute_client.ssh_public_keys.generate_key_pair(
711
'myResourceGroup',
712
'mySSHKey'
713
)
714
715
print(f"Public key generated: {key_pair.public_key[:50]}...")
716
print("Store the private key securely!")
717
718
# Use the SSH key in VM creation
719
vm_parameters = {
720
'location': 'East US',
721
'hardware_profile': {'vm_size': 'Standard_B1s'},
722
'storage_profile': {
723
'image_reference': {
724
'publisher': 'Canonical',
725
'offer': '0001-com-ubuntu-server-focal',
726
'sku': '20_04-lts-gen2',
727
'version': 'latest'
728
}
729
},
730
'os_profile': {
731
'computer_name': 'myvm',
732
'admin_username': 'azureuser',
733
'disable_password_authentication': True,
734
'linux_configuration': {
735
'ssh': {
736
'public_keys': [{
737
'path': '/home/azureuser/.ssh/authorized_keys',
738
'key_data': key_pair.public_key
739
}]
740
}
741
}
742
},
743
'network_profile': {
744
'network_interfaces': [{
745
'id': '/subscriptions/.../networkInterfaces/mynic'
746
}]
747
},
748
# Use the availability set and proximity placement group
749
'availability_set': {
750
'id': availability_set.id
751
},
752
'proximity_placement_group': {
753
'id': ppg.id
754
}
755
}
756
757
operation = compute_client.virtual_machines.begin_create_or_update(
758
'myResourceGroup',
759
'myHighAvailabilityVM',
760
vm_parameters
761
)
762
vm = operation.result()
763
print(f"High availability VM created: {vm.name}")
764
```