Azure Virtual Machine Operators¶
Waiting Strategy¶
The VM action operators support two patterns:
wait_for_completion=True(default): operator blocks until Azure operation finishes.wait_for_completion=False: operator submits the operation and returns quickly.
When you want to reduce worker slot usage for long VM state transitions, use
wait_for_completion=False together with
AzureVirtualMachineStateSensor
in deferrable=True mode to move the waiting to the triggerer.
AzureVirtualMachineStartOperator¶
Use the
AzureVirtualMachineStartOperator
to start an Azure Virtual Machine.
Below is an example of using this operator to start a VM:
start_vm = AzureVirtualMachineStartOperator(
task_id="start_vm",
resource_group_name=RESOURCE_GROUP,
vm_name=VM_NAME,
wait_for_completion=False,
)
AzureVirtualMachineStopOperator¶
Use the
AzureVirtualMachineStopOperator
to stop (deallocate) an Azure Virtual Machine. This releases compute resources and stops billing.
Below is an example of using this operator to stop a VM:
stop_vm = AzureVirtualMachineStopOperator(
task_id="stop_vm",
resource_group_name=RESOURCE_GROUP,
vm_name=VM_NAME,
wait_for_completion=False,
)
AzureVirtualMachineRestartOperator¶
Use the
AzureVirtualMachineRestartOperator
to restart an Azure Virtual Machine.
Below is an example of using this operator to restart a VM:
restart_vm = AzureVirtualMachineRestartOperator(
task_id="restart_vm",
resource_group_name=RESOURCE_GROUP,
vm_name=VM_NAME,
wait_for_completion=True,
)
AzureVirtualMachineStateSensor¶
Use the
AzureVirtualMachineStateSensor
to poll a VM until it reaches a target power state (e.g., running, deallocated).
This sensor supports deferrable mode.
Below is an example of using this sensor:
sense_running = AzureVirtualMachineStateSensor(
task_id="sense_running",
resource_group_name=RESOURCE_GROUP,
vm_name=VM_NAME,
target_state="running",
deferrable=True,
poke_interval=10,
timeout=300,
)
Reference¶
For further information, look at: