0
# Virtual Machine Scale Sets
1
2
Comprehensive management of Virtual Machine Scale Sets for auto-scaling applications, including orchestration modes, scaling policies, rolling upgrades, and individual VM management within scale sets. Scale sets enable deployment of highly available applications that can automatically scale based on demand.
3
4
## Capabilities
5
6
### Scale Set Lifecycle Operations
7
8
Core operations for managing Virtual Machine Scale Set lifecycle.
9
10
```python { .api }
11
def begin_create_or_update(
12
resource_group_name: str,
13
vm_scale_set_name: str,
14
parameters: VirtualMachineScaleSet
15
) -> LROPoller[VirtualMachineScaleSet]:
16
"""
17
Create or update a virtual machine scale set.
18
19
Args:
20
resource_group_name: Name of the resource group
21
vm_scale_set_name: Name of the scale set
22
parameters: Scale set configuration
23
24
Returns:
25
Long-running operation poller for VirtualMachineScaleSet
26
"""
27
28
def begin_delete(resource_group_name: str, vm_scale_set_name: str) -> LROPoller[None]:
29
"""
30
Delete a virtual machine scale set.
31
32
Args:
33
resource_group_name: Name of the resource group
34
vm_scale_set_name: Name of the scale set
35
36
Returns:
37
Long-running operation poller
38
"""
39
40
def get(resource_group_name: str, vm_scale_set_name: str) -> VirtualMachineScaleSet:
41
"""
42
Get scale set details.
43
44
Args:
45
resource_group_name: Name of the resource group
46
vm_scale_set_name: Name of the scale set
47
48
Returns:
49
Virtual machine scale set details
50
"""
51
52
def list(resource_group_name: str) -> Iterable[VirtualMachineScaleSet]:
53
"""
54
List scale sets in a resource group.
55
56
Args:
57
resource_group_name: Name of the resource group
58
59
Returns:
60
Iterable of virtual machine scale sets
61
"""
62
63
def list_all() -> Iterable[VirtualMachineScaleSet]:
64
"""
65
List all scale sets in the subscription.
66
67
Returns:
68
Iterable of scale sets across all resource groups
69
"""
70
```
71
72
### Scale Set Scaling Operations
73
74
Operations for managing scale set capacity and scaling behavior.
75
76
```python { .api }
77
def begin_update(
78
resource_group_name: str,
79
vm_scale_set_name: str,
80
parameters: VirtualMachineScaleSetUpdate
81
) -> LROPoller[VirtualMachineScaleSet]:
82
"""
83
Update scale set configuration including capacity.
84
85
Args:
86
resource_group_name: Name of the resource group
87
vm_scale_set_name: Name of the scale set
88
parameters: Update parameters including new capacity
89
90
Returns:
91
Long-running operation poller for updated scale set
92
"""
93
94
def begin_update_instances(
95
resource_group_name: str,
96
vm_scale_set_name: str,
97
vm_instance_i_ds: VirtualMachineScaleSetVMInstanceRequiredIDs
98
) -> LROPoller[None]:
99
"""
100
Update specific instances in the scale set.
101
102
Args:
103
resource_group_name: Name of the resource group
104
vm_scale_set_name: Name of the scale set
105
vm_instance_i_ds: Instance IDs to update
106
107
Returns:
108
Long-running operation poller
109
"""
110
111
def begin_reimage_all(resource_group_name: str, vm_scale_set_name: str) -> LROPoller[None]:
112
"""
113
Reimage all instances in the scale set.
114
115
Args:
116
resource_group_name: Name of the resource group
117
vm_scale_set_name: Name of the scale set
118
119
Returns:
120
Long-running operation poller
121
"""
122
```
123
124
### Scale Set Power Management
125
126
Operations for controlling power state of scale set instances.
127
128
```python { .api }
129
def begin_start(resource_group_name: str, vm_scale_set_name: str) -> LROPoller[None]:
130
"""
131
Start all instances in the scale set.
132
133
Args:
134
resource_group_name: Name of the resource group
135
vm_scale_set_name: Name of the scale set
136
137
Returns:
138
Long-running operation poller
139
"""
140
141
def begin_restart(resource_group_name: str, vm_scale_set_name: str) -> LROPoller[None]:
142
"""
143
Restart all instances in the scale set.
144
145
Args:
146
resource_group_name: Name of the resource group
147
vm_scale_set_name: Name of the scale set
148
149
Returns:
150
Long-running operation poller
151
"""
152
153
def begin_power_off(resource_group_name: str, vm_scale_set_name: str) -> LROPoller[None]:
154
"""
155
Power off all instances in the scale set.
156
157
Args:
158
resource_group_name: Name of the resource group
159
vm_scale_set_name: Name of the scale set
160
161
Returns:
162
Long-running operation poller
163
"""
164
165
def begin_deallocate(resource_group_name: str, vm_scale_set_name: str) -> LROPoller[None]:
166
"""
167
Deallocate all instances in the scale set.
168
169
Args:
170
resource_group_name: Name of the resource group
171
vm_scale_set_name: Name of the scale set
172
173
Returns:
174
Long-running operation poller
175
"""
176
```
177
178
### Individual VM Management in Scale Sets
179
180
Operations for managing individual VMs within a scale set.
181
182
```python { .api }
183
class VirtualMachineScaleSetVMsOperations:
184
def list(
185
resource_group_name: str,
186
virtual_machine_scale_set_name: str
187
) -> Iterable[VirtualMachineScaleSetVM]:
188
"""
189
List VMs in a scale set.
190
191
Args:
192
resource_group_name: Name of the resource group
193
virtual_machine_scale_set_name: Name of the scale set
194
195
Returns:
196
Iterable of scale set VMs
197
"""
198
199
def get(
200
resource_group_name: str,
201
vm_scale_set_name: str,
202
instance_id: str
203
) -> VirtualMachineScaleSetVM:
204
"""
205
Get details of a specific VM in the scale set.
206
207
Args:
208
resource_group_name: Name of the resource group
209
vm_scale_set_name: Name of the scale set
210
instance_id: Instance ID of the VM
211
212
Returns:
213
Scale set VM details
214
"""
215
216
def begin_delete(
217
resource_group_name: str,
218
vm_scale_set_name: str,
219
instance_id: str
220
) -> LROPoller[None]:
221
"""
222
Delete a specific VM from the scale set.
223
224
Args:
225
resource_group_name: Name of the resource group
226
vm_scale_set_name: Name of the scale set
227
instance_id: Instance ID of the VM to delete
228
229
Returns:
230
Long-running operation poller
231
"""
232
```
233
234
### Rolling Upgrades
235
236
Management of rolling upgrades for scale sets.
237
238
```python { .api }
239
class VirtualMachineScaleSetRollingUpgradesOperations:
240
def begin_cancel(
241
resource_group_name: str,
242
vm_scale_set_name: str
243
) -> LROPoller[None]:
244
"""
245
Cancel a rolling upgrade.
246
247
Args:
248
resource_group_name: Name of the resource group
249
vm_scale_set_name: Name of the scale set
250
251
Returns:
252
Long-running operation poller
253
"""
254
255
def begin_start_os_upgrade(
256
resource_group_name: str,
257
vm_scale_set_name: str
258
) -> LROPoller[None]:
259
"""
260
Start OS upgrade on the scale set.
261
262
Args:
263
resource_group_name: Name of the resource group
264
vm_scale_set_name: Name of the scale set
265
266
Returns:
267
Long-running operation poller
268
"""
269
270
def get_latest(
271
resource_group_name: str,
272
vm_scale_set_name: str
273
) -> RollingUpgradeStatusInfo:
274
"""
275
Get the status of the latest rolling upgrade.
276
277
Args:
278
resource_group_name: Name of the resource group
279
vm_scale_set_name: Name of the scale set
280
281
Returns:
282
Rolling upgrade status information
283
"""
284
```
285
286
## Data Types
287
288
```python { .api }
289
class VirtualMachineScaleSet:
290
"""Describes a Virtual Machine Scale Set."""
291
id: Optional[str]
292
name: Optional[str]
293
type: Optional[str]
294
location: str
295
tags: Optional[Dict[str, str]]
296
sku: Optional[Sku]
297
plan: Optional[Plan]
298
upgrade_policy: Optional[UpgradePolicy]
299
automatic_repairs_policy: Optional[AutomaticRepairsPolicy]
300
virtual_machine_profile: Optional[VirtualMachineScaleSetVMProfile]
301
provisioning_state: Optional[str]
302
overprovision: Optional[bool]
303
do_not_run_extensions_on_overprovisioned_v_ms: Optional[bool]
304
unique_id: Optional[str]
305
single_placement_group: Optional[bool]
306
zone_balance: Optional[bool]
307
platform_fault_domain_count: Optional[int]
308
proximity_placement_group: Optional[SubResource]
309
host_group: Optional[SubResource]
310
additional_capabilities: Optional[AdditionalCapabilities]
311
scale_in_policy: Optional[ScaleInPolicy]
312
orchestration_mode: Optional[OrchestrationMode]
313
spot_restore_policy: Optional[SpotRestorePolicy]
314
priority_mix_policy: Optional[PriorityMixPolicy]
315
316
class VirtualMachineScaleSetVMProfile:
317
"""Describes a virtual machine scale set virtual machine profile."""
318
os_profile: Optional[VirtualMachineScaleSetOSProfile]
319
storage_profile: Optional[VirtualMachineScaleSetStorageProfile]
320
network_profile: Optional[VirtualMachineScaleSetNetworkProfile]
321
security_profile: Optional[SecurityProfile]
322
diagnostics_profile: Optional[DiagnosticsProfile]
323
extension_profile: Optional[VirtualMachineScaleSetExtensionProfile]
324
license_type: Optional[str]
325
priority: Optional[VirtualMachinePriorityTypes]
326
eviction_policy: Optional[VirtualMachineEvictionPolicyTypes]
327
billing_profile: Optional[BillingProfile]
328
scheduled_events_profile: Optional[ScheduledEventsProfile]
329
user_data: Optional[str]
330
capacity_reservation: Optional[CapacityReservationProfile]
331
application_profile: Optional[ApplicationProfile]
332
hardware_profile: Optional[VirtualMachineScaleSetHardwareProfile]
333
service_artifact_reference: Optional[ServiceArtifactReference]
334
security_posture_reference: Optional[SecurityPostureReference]
335
336
class UpgradePolicy:
337
"""Describes an upgrade policy - automatic, manual, or rolling."""
338
mode: Optional[UpgradeMode]
339
rolling_upgrade_policy: Optional[RollingUpgradePolicy]
340
automatic_os_upgrade_policy: Optional[AutomaticOSUpgradePolicy]
341
342
class Sku:
343
"""Describes a virtual machine scale set sku."""
344
name: Optional[str]
345
tier: Optional[str]
346
capacity: Optional[int]
347
348
class VirtualMachineScaleSetVM:
349
"""Describes a virtual machine scale set virtual machine."""
350
id: Optional[str]
351
name: Optional[str]
352
type: Optional[str]
353
location: str
354
tags: Optional[Dict[str, str]]
355
instance_id: Optional[str]
356
sku: Optional[Sku]
357
plan: Optional[Plan]
358
resources: Optional[List[VirtualMachineExtension]]
359
zones: Optional[List[str]]
360
latest_model_applied: Optional[bool]
361
vm_id: Optional[str]
362
instance_view: Optional[VirtualMachineScaleSetVMInstanceView]
363
hardware_profile: Optional[HardwareProfile]
364
storage_profile: Optional[StorageProfile]
365
additional_capabilities: Optional[AdditionalCapabilities]
366
os_profile: Optional[OSProfile]
367
security_profile: Optional[SecurityProfile]
368
network_profile: Optional[NetworkProfile]
369
network_profile_configuration: Optional[VirtualMachineScaleSetVMNetworkProfileConfiguration]
370
diagnostics_profile: Optional[DiagnosticsProfile]
371
availability_set: Optional[SubResource]
372
provisioning_state: Optional[str]
373
license_type: Optional[str]
374
model_definition_applied: Optional[str]
375
protection_policy: Optional[VirtualMachineScaleSetVMProtectionPolicy]
376
377
class VirtualMachineScaleSetUpdate:
378
"""Describes a Virtual Machine Scale Set Update."""
379
tags: Optional[Dict[str, str]]
380
sku: Optional[Sku]
381
plan: Optional[Plan]
382
upgrade_policy: Optional[UpgradePolicy]
383
automatic_repairs_policy: Optional[AutomaticRepairsPolicy]
384
virtual_machine_profile: Optional[VirtualMachineScaleSetUpdateVMProfile]
385
overprovision: Optional[bool]
386
do_not_run_extensions_on_overprovisioned_v_ms: Optional[bool]
387
single_placement_group: Optional[bool]
388
additional_capabilities: Optional[AdditionalCapabilities]
389
scale_in_policy: Optional[ScaleInPolicy]
390
proximity_placement_group: Optional[SubResource]
391
priority_mix_policy: Optional[PriorityMixPolicy]
392
spot_restore_policy: Optional[SpotRestorePolicy]
393
394
class RollingUpgradeStatusInfo:
395
"""The status of the latest virtual machine scale set rolling upgrade."""
396
id: Optional[str]
397
name: Optional[str]
398
type: Optional[str]
399
location: Optional[str]
400
tags: Optional[Dict[str, str]]
401
policy: Optional[RollingUpgradePolicy]
402
running_status: Optional[RollingUpgradeRunningStatus]
403
progress: Optional[RollingUpgradeProgressInfo]
404
error: Optional[ApiError]
405
```
406
407
## Usage Examples
408
409
### Create a Virtual Machine Scale Set
410
411
```python
412
from azure.identity import DefaultAzureCredential
413
from azure.mgmt.compute import ComputeManagementClient
414
415
credential = DefaultAzureCredential()
416
compute_client = ComputeManagementClient(credential, "subscription-id")
417
418
scale_set_parameters = {
419
'location': 'East US',
420
'sku': {
421
'name': 'Standard_B1ms',
422
'capacity': 3
423
},
424
'upgrade_policy': {
425
'mode': 'Manual'
426
},
427
'virtual_machine_profile': {
428
'os_profile': {
429
'computer_name_prefix': 'myss',
430
'admin_username': 'azureuser',
431
'admin_password': 'Password123!'
432
},
433
'storage_profile': {
434
'image_reference': {
435
'publisher': 'Canonical',
436
'offer': '0001-com-ubuntu-server-focal',
437
'sku': '20_04-lts-gen2',
438
'version': 'latest'
439
},
440
'os_disk': {
441
'create_option': 'FromImage',
442
'managed_disk': {
443
'storage_account_type': 'Standard_LRS'
444
}
445
}
446
},
447
'network_profile': {
448
'network_interface_configurations': [{
449
'name': 'myss-nic',
450
'properties': {
451
'primary': True,
452
'ip_configurations': [{
453
'name': 'myss-ipconfig',
454
'properties': {
455
'subnet': {
456
'id': '/subscriptions/.../subnets/mysubnet'
457
}
458
}
459
}]
460
}
461
}]
462
}
463
}
464
}
465
466
operation = compute_client.virtual_machine_scale_sets.begin_create_or_update(
467
'myResourceGroup',
468
'myScaleSet',
469
scale_set_parameters
470
)
471
scale_set = operation.result()
472
print(f"Scale set {scale_set.name} created with capacity {scale_set.sku.capacity}")
473
```
474
475
### Scale Out Scale Set
476
477
```python
478
# Get current scale set
479
scale_set = compute_client.virtual_machine_scale_sets.get(
480
'myResourceGroup',
481
'myScaleSet'
482
)
483
484
# Update capacity
485
update_parameters = {
486
'sku': {
487
'name': scale_set.sku.name,
488
'capacity': 5 # Scale out to 5 instances
489
}
490
}
491
492
operation = compute_client.virtual_machine_scale_sets.begin_update(
493
'myResourceGroup',
494
'myScaleSet',
495
update_parameters
496
)
497
updated_scale_set = operation.result()
498
print(f"Scale set updated to capacity: {updated_scale_set.sku.capacity}")
499
```
500
501
### Manage Individual VMs in Scale Set
502
503
```python
504
# List all VMs in the scale set
505
vms = compute_client.virtual_machine_scale_set_vms.list(
506
'myResourceGroup',
507
'myScaleSet'
508
)
509
510
for vm in vms:
511
print(f"VM Instance ID: {vm.instance_id}, Status: {vm.provisioning_state}")
512
513
# Get specific VM details
514
vm = compute_client.virtual_machine_scale_set_vms.get(
515
'myResourceGroup',
516
'myScaleSet',
517
'0' # Instance ID
518
)
519
print(f"VM {vm.instance_id} is in zone: {vm.zones}")
520
521
# Delete a specific VM instance
522
operation = compute_client.virtual_machine_scale_set_vms.begin_delete(
523
'myResourceGroup',
524
'myScaleSet',
525
'0' # Instance ID to delete
526
)
527
operation.result()
528
print("VM instance deleted")
529
```
530
531
### Monitor Rolling Upgrade
532
533
```python
534
# Start OS upgrade
535
operation = compute_client.virtual_machine_scale_set_rolling_upgrades.begin_start_os_upgrade(
536
'myResourceGroup',
537
'myScaleSet'
538
)
539
540
# Monitor progress
541
status = compute_client.virtual_machine_scale_set_rolling_upgrades.get_latest(
542
'myResourceGroup',
543
'myScaleSet'
544
)
545
546
print(f"Upgrade Status: {status.running_status.code}")
547
if status.progress:
548
print(f"Successful: {status.progress.successful_instance_count}")
549
print(f"Failed: {status.progress.failed_instance_count}")
550
print(f"In Progress: {status.progress.in_progress_instance_count}")
551
```
552
553
## Scale Set Extensions Management
554
555
Management of extensions on Virtual Machine Scale Sets for software deployment, configuration, and monitoring across all scale set instances.
556
557
```python { .api }
558
class VirtualMachineScaleSetExtensionsOperations:
559
def list(resource_group_name: str, vm_scale_set_name: str) -> Iterable[VirtualMachineScaleSetExtension]: ...
560
def get(resource_group_name: str, vm_scale_set_name: str, vmss_extension_name: str, *, expand: Optional[str] = None) -> VirtualMachineScaleSetExtension: ...
561
def begin_create_or_update(resource_group_name: str, vm_scale_set_name: str, vmss_extension_name: str, extension_parameters: VirtualMachineScaleSetExtension) -> LROPoller[VirtualMachineScaleSetExtension]: ...
562
def begin_update(resource_group_name: str, vm_scale_set_name: str, vmss_extension_name: str, extension_parameters: VirtualMachineScaleSetExtensionUpdate) -> LROPoller[VirtualMachineScaleSetExtension]: ...
563
def begin_delete(resource_group_name: str, vm_scale_set_name: str, vmss_extension_name: str) -> LROPoller[None]: ...
564
565
class VirtualMachineScaleSetVMExtensionsOperations:
566
def list(resource_group_name: str, vm_scale_set_name: str, instance_id: str, *, expand: Optional[str] = None) -> Iterable[VirtualMachineExtension]: ...
567
def get(resource_group_name: str, vm_scale_set_name: str, instance_id: str, vm_extension_name: str, *, expand: Optional[str] = None) -> VirtualMachineExtension: ...
568
def begin_create_or_update(resource_group_name: str, vm_scale_set_name: str, instance_id: str, vm_extension_name: str, extension_parameters: VirtualMachineExtension) -> LROPoller[VirtualMachineExtension]: ...
569
def begin_update(resource_group_name: str, vm_scale_set_name: str, instance_id: str, vm_extension_name: str, extension_parameters: VirtualMachineExtensionUpdate) -> LROPoller[VirtualMachineExtension]: ...
570
def begin_delete(resource_group_name: str, vm_scale_set_name: str, instance_id: str, vm_extension_name: str) -> LROPoller[None]: ...
571
572
class VirtualMachineScaleSetVMRunCommandsOperations:
573
def list(resource_group_name: str, vm_scale_set_name: str, instance_id: str, *, expand: Optional[str] = None) -> Iterable[VirtualMachineRunCommand]: ...
574
def get(resource_group_name: str, vm_scale_set_name: str, instance_id: str, run_command_name: str, *, expand: Optional[str] = None) -> VirtualMachineRunCommand: ...
575
def begin_create_or_update(resource_group_name: str, vm_scale_set_name: str, instance_id: str, run_command_name: str, run_command: VirtualMachineRunCommand) -> LROPoller[VirtualMachineRunCommand]: ...
576
def begin_update(resource_group_name: str, vm_scale_set_name: str, instance_id: str, run_command_name: str, run_command: VirtualMachineRunCommandUpdate) -> LROPoller[VirtualMachineRunCommand]: ...
577
def begin_delete(resource_group_name: str, vm_scale_set_name: str, instance_id: str, run_command_name: str) -> LROPoller[None]: ...
578
```