airflow.providers.microsoft.azure.hooks.compute

Classes

AzureComputeHook

A hook to interact with Azure Compute to manage Virtual Machines.

Module Contents

class airflow.providers.microsoft.azure.hooks.compute.AzureComputeHook(azure_conn_id=default_conn_name)[source]

Bases: airflow.providers.microsoft.azure.hooks.base_azure.AzureBaseHook

A hook to interact with Azure Compute to manage Virtual Machines.

Parameters:

azure_conn_id (str) – Azure connection id of a service principal which will be used to manage virtual machines.

conn_name_attr = 'azure_conn_id'[source]
default_conn_name = 'azure_default'[source]
conn_type = 'azure_compute'[source]
hook_name = 'Azure Compute'[source]
property connection: azure.mgmt.compute.ComputeManagementClient[source]
get_conn()[source]

Authenticate the resource using the connection id passed during init.

Returns:

the authenticated ComputeManagementClient.

Return type:

azure.mgmt.compute.ComputeManagementClient

start_instance(resource_group_name, vm_name, wait_for_completion=True)[source]

Start a virtual machine instance.

Parameters:
  • resource_group_name (str) – Name of the resource group.

  • vm_name (str) – Name of the virtual machine.

  • wait_for_completion (bool) – Wait for the operation to complete.

stop_instance(resource_group_name, vm_name, wait_for_completion=True)[source]

Stop (deallocate) a virtual machine instance.

Uses begin_deallocate to release compute resources and stop billing.

Parameters:
  • resource_group_name (str) – Name of the resource group.

  • vm_name (str) – Name of the virtual machine.

  • wait_for_completion (bool) – Wait for the operation to complete.

restart_instance(resource_group_name, vm_name, wait_for_completion=True)[source]

Restart a virtual machine instance.

Parameters:
  • resource_group_name (str) – Name of the resource group.

  • vm_name (str) – Name of the virtual machine.

  • wait_for_completion (bool) – Wait for the operation to complete.

get_power_state(resource_group_name, vm_name)[source]

Get the power state of a virtual machine.

Parameters:
  • resource_group_name (str) – Name of the resource group.

  • vm_name (str) – Name of the virtual machine.

Returns:

Power state string, e.g. running, deallocated, stopped.

Return type:

str

test_connection()[source]

Test the Azure Compute connection.

async get_async_conn()[source]

Return an authenticated async ComputeManagementClient.

Supports service-principal (login/password + tenantId) and DefaultAzureCredential auth. Legacy key_path / key_json auth files are not supported in the async path.

async async_get_power_state(resource_group_name, vm_name)[source]

Get the power state of a virtual machine using the native async client.

Parameters:
  • resource_group_name (str) – Name of the resource group.

  • vm_name (str) – Name of the virtual machine.

Returns:

Power state string, e.g. running, deallocated, stopped.

Return type:

str

async close()[source]

Close the async connection.

async __aenter__()[source]
async __aexit__(exc_type, exc_val, exc_tb)[source]

Was this entry helpful?