Microsoft Azure Compute Management Client Library for programmatic management of Azure compute resources including virtual machines, scale sets, disks, and related infrastructure.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
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.
Operations for managing availability sets to ensure high availability across fault and update domains.
class AvailabilitySetsOperations:
def create_or_update(
resource_group_name: str,
availability_set_name: str,
parameters: AvailabilitySet
) -> AvailabilitySet:
"""
Create or update an availability set.
Args:
resource_group_name: Name of the resource group
availability_set_name: Name of the availability set
parameters: Availability set configuration
Returns:
Availability set details
"""
def delete(resource_group_name: str, availability_set_name: str) -> None:
"""
Delete an availability set.
Args:
resource_group_name: Name of the resource group
availability_set_name: Name of the availability set
"""
def get(resource_group_name: str, availability_set_name: str) -> AvailabilitySet:
"""
Get availability set details.
Args:
resource_group_name: Name of the resource group
availability_set_name: Name of the availability set
Returns:
Availability set details
"""
def list(resource_group_name: str) -> Iterable[AvailabilitySet]:
"""
List availability sets in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of availability sets
"""
def list_available_sizes(
resource_group_name: str,
availability_set_name: str
) -> Iterable[VirtualMachineSize]:
"""
List available VM sizes for an availability set.
Args:
resource_group_name: Name of the resource group
availability_set_name: Name of the availability set
Returns:
Iterable of available VM sizes
"""Operations for managing proximity placement groups to optimize network latency.
class ProximityPlacementGroupsOperations:
def create_or_update(
resource_group_name: str,
proximity_placement_group_name: str,
parameters: ProximityPlacementGroup
) -> ProximityPlacementGroup:
"""
Create or update a proximity placement group.
Args:
resource_group_name: Name of the resource group
proximity_placement_group_name: Name of the proximity placement group
parameters: Proximity placement group configuration
Returns:
Proximity placement group details
"""
def delete(resource_group_name: str, proximity_placement_group_name: str) -> None:
"""
Delete a proximity placement group.
Args:
resource_group_name: Name of the resource group
proximity_placement_group_name: Name of the proximity placement group
"""
def get(
resource_group_name: str,
proximity_placement_group_name: str
) -> ProximityPlacementGroup:
"""
Get proximity placement group details.
Args:
resource_group_name: Name of the resource group
proximity_placement_group_name: Name of the proximity placement group
Returns:
Proximity placement group details
"""
def list_by_resource_group(resource_group_name: str) -> Iterable[ProximityPlacementGroup]:
"""
List proximity placement groups in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of proximity placement groups
"""
def list_by_subscription() -> Iterable[ProximityPlacementGroup]:
"""
List all proximity placement groups in the subscription.
Returns:
Iterable of all proximity placement groups
"""Operations for managing dedicated hosts for single-tenant deployments.
class DedicatedHostsOperations:
def begin_create_or_update(
resource_group_name: str,
host_group_name: str,
host_name: str,
parameters: DedicatedHost
) -> LROPoller[DedicatedHost]:
"""
Create or update a dedicated host.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
host_name: Name of the dedicated host
parameters: Dedicated host configuration
Returns:
Long-running operation poller for DedicatedHost
"""
def begin_delete(
resource_group_name: str,
host_group_name: str,
host_name: str
) -> LROPoller[None]:
"""
Delete a dedicated host.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
host_name: Name of the dedicated host
Returns:
Long-running operation poller
"""
def get(
resource_group_name: str,
host_group_name: str,
host_name: str
) -> DedicatedHost:
"""
Get dedicated host details.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
host_name: Name of the dedicated host
Returns:
Dedicated host details
"""
def list_by_host_group(
resource_group_name: str,
host_group_name: str
) -> Iterable[DedicatedHost]:
"""
List dedicated hosts in a host group.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
Returns:
Iterable of dedicated hosts
"""Operations for managing dedicated host groups.
class DedicatedHostGroupsOperations:
def create_or_update(
resource_group_name: str,
host_group_name: str,
parameters: DedicatedHostGroup
) -> DedicatedHostGroup:
"""
Create or update a dedicated host group.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
parameters: Host group configuration
Returns:
Dedicated host group details
"""
def delete(resource_group_name: str, host_group_name: str) -> None:
"""
Delete a dedicated host group.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
"""
def get(resource_group_name: str, host_group_name: str) -> DedicatedHostGroup:
"""
Get dedicated host group details.
Args:
resource_group_name: Name of the resource group
host_group_name: Name of the dedicated host group
Returns:
Dedicated host group details
"""
def list_by_resource_group(resource_group_name: str) -> Iterable[DedicatedHostGroup]:
"""
List dedicated host groups in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of dedicated host groups
"""
def list_by_subscription() -> Iterable[DedicatedHostGroup]:
"""
List all dedicated host groups in the subscription.
Returns:
Iterable of all dedicated host groups
"""Operations for managing capacity reservations to guarantee compute capacity.
class CapacityReservationsOperations:
def begin_create_or_update(
resource_group_name: str,
capacity_reservation_group_name: str,
capacity_reservation_name: str,
parameters: CapacityReservation
) -> LROPoller[CapacityReservation]:
"""
Create or update a capacity reservation.
Args:
resource_group_name: Name of the resource group
capacity_reservation_group_name: Name of the capacity reservation group
capacity_reservation_name: Name of the capacity reservation
parameters: Capacity reservation configuration
Returns:
Long-running operation poller for CapacityReservation
"""
def begin_delete(
resource_group_name: str,
capacity_reservation_group_name: str,
capacity_reservation_name: str
) -> LROPoller[None]:
"""
Delete a capacity reservation.
Args:
resource_group_name: Name of the resource group
capacity_reservation_group_name: Name of the capacity reservation group
capacity_reservation_name: Name of the capacity reservation
Returns:
Long-running operation poller
"""
def get(
resource_group_name: str,
capacity_reservation_group_name: str,
capacity_reservation_name: str
) -> CapacityReservation:
"""
Get capacity reservation details.
Args:
resource_group_name: Name of the resource group
capacity_reservation_group_name: Name of the capacity reservation group
capacity_reservation_name: Name of the capacity reservation
Returns:
Capacity reservation details
"""
def list_by_capacity_reservation_group(
resource_group_name: str,
capacity_reservation_group_name: str
) -> Iterable[CapacityReservation]:
"""
List capacity reservations in a group.
Args:
resource_group_name: Name of the resource group
capacity_reservation_group_name: Name of the capacity reservation group
Returns:
Iterable of capacity reservations
"""Operations for managing SSH public keys for Linux VM authentication.
class SshPublicKeysOperations:
def create(
resource_group_name: str,
ssh_public_key_name: str,
parameters: SshPublicKeyResource
) -> SshPublicKeyResource:
"""
Create an SSH public key resource.
Args:
resource_group_name: Name of the resource group
ssh_public_key_name: Name of the SSH public key resource
parameters: SSH public key configuration
Returns:
SSH public key resource details
"""
def delete(resource_group_name: str, ssh_public_key_name: str) -> None:
"""
Delete an SSH public key resource.
Args:
resource_group_name: Name of the resource group
ssh_public_key_name: Name of the SSH public key resource
"""
def get(resource_group_name: str, ssh_public_key_name: str) -> SshPublicKeyResource:
"""
Get SSH public key resource details.
Args:
resource_group_name: Name of the resource group
ssh_public_key_name: Name of the SSH public key resource
Returns:
SSH public key resource details
"""
def list_by_resource_group(resource_group_name: str) -> Iterable[SshPublicKeyResource]:
"""
List SSH public keys in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
Iterable of SSH public key resources
"""
def list_by_subscription() -> Iterable[SshPublicKeyResource]:
"""
List all SSH public keys in the subscription.
Returns:
Iterable of all SSH public key resources
"""
def generate_key_pair(
resource_group_name: str,
ssh_public_key_name: str
) -> SshPublicKeyGenerateKeyPairResult:
"""
Generate a new SSH key pair.
Args:
resource_group_name: Name of the resource group
ssh_public_key_name: Name of the SSH public key resource
Returns:
Generated SSH key pair with public and private keys
"""class AvailabilitySet:
"""Specifies information about the availability set."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
platform_update_domain_count: Optional[int]
platform_fault_domain_count: Optional[int]
virtual_machines: Optional[List[SubResource]]
proximity_placement_group: Optional[SubResource]
statuses: Optional[List[InstanceViewStatus]]
sku: Optional[Sku]
class ProximityPlacementGroup:
"""Specifies information about the proximity placement group."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
proximity_placement_group_type: Optional[ProximityPlacementGroupType]
virtual_machines: Optional[List[SubResource]]
virtual_machine_scale_sets: Optional[List[SubResource]]
availability_sets: Optional[List[SubResource]]
colocation_status: Optional[InstanceViewStatus]
intent: Optional[ProximityPlacementGroupPropertiesIntent]
zones: Optional[List[str]]
class DedicatedHost:
"""Specifies information about the Dedicated host."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
sku: Sku
platform_fault_domain: Optional[int]
auto_replace_on_failure: Optional[bool]
host_id: Optional[str]
virtual_machines: Optional[List[SubResource]]
license_type: Optional[DedicatedHostLicenseTypes]
provisioning_time: Optional[datetime]
provisioning_state: Optional[str]
instance_view: Optional[DedicatedHostInstanceView]
time_created: Optional[datetime]
class DedicatedHostGroup:
"""Specifies information about the dedicated host group."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
zones: Optional[List[str]]
platform_fault_domain_count: int
hosts: Optional[List[SubResource]]
instance_view: Optional[DedicatedHostGroupInstanceView]
support_automatic_placement: Optional[bool]
additional_capabilities: Optional[DedicatedHostGroupPropertiesAdditionalCapabilities]
class CapacityReservation:
"""Specifies information about the capacity reservation."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
sku: Sku
zones: Optional[List[str]]
time_created: Optional[datetime]
provisioning_time: Optional[datetime]
provisioning_state: Optional[str]
instance_view: Optional[CapacityReservationInstanceView]
platform_fault_domain_count: Optional[int]
class CapacityReservationGroup:
"""Specifies information about the capacity reservation group."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
zones: Optional[List[str]]
capacity_reservations: Optional[List[SubResource]]
virtual_machines_associated: Optional[List[SubResource]]
instance_view: Optional[CapacityReservationGroupInstanceView]
sharing_profile: Optional[ResourceSharingProfile]
class SshPublicKeyResource:
"""Specifies information about the SSH public key."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
public_key: Optional[str]
class SshPublicKeyGenerateKeyPairResult:
"""Response from generation of an SSH key pair."""
private_key: str
public_key: str
id: strfrom azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
credential = DefaultAzureCredential()
compute_client = ComputeManagementClient(credential, "subscription-id")
# Create availability set for high availability
availability_set_parameters = {
'location': 'East US',
'platform_fault_domain_count': 2,
'platform_update_domain_count': 5,
'sku': {
'name': 'Aligned' # For managed disks
},
'tags': {
'purpose': 'high-availability',
'application': 'web-tier'
}
}
availability_set = compute_client.availability_sets.create_or_update(
'myResourceGroup',
'myAvailabilitySet',
availability_set_parameters
)
print(f"Availability set created: {availability_set.name}")
# Create proximity placement group for low latency
ppg_parameters = {
'location': 'East US',
'proximity_placement_group_type': 'Standard',
'tags': {
'purpose': 'low-latency',
'tier': 'database'
}
}
ppg = compute_client.proximity_placement_groups.create_or_update(
'myResourceGroup',
'myProximityGroup',
ppg_parameters
)
print(f"Proximity placement group created: {ppg.name}")# Create dedicated host group
host_group_parameters = {
'location': 'East US',
'platform_fault_domain_count': 2,
'support_automatic_placement': True,
'tags': {
'purpose': 'dedicated-hosting',
'compliance': 'required'
}
}
host_group = compute_client.dedicated_host_groups.create_or_update(
'myResourceGroup',
'myHostGroup',
host_group_parameters
)
# Create dedicated host
host_parameters = {
'location': 'East US',
'sku': {
'name': 'DSv3-Type1'
},
'platform_fault_domain': 0,
'auto_replace_on_failure': True,
'license_type': 'Windows_Server_Hybrid'
}
operation = compute_client.dedicated_hosts.begin_create_or_update(
'myResourceGroup',
'myHostGroup',
'myDedicatedHost',
host_parameters
)
dedicated_host = operation.result()
print(f"Dedicated host created: {dedicated_host.name}")
# Check host capacity
instance_view = dedicated_host.instance_view
if instance_view and instance_view.available_capacity:
for capacity in instance_view.available_capacity.allocatable_v_ms:
print(f"VM Size: {capacity.vm_size}, Count: {capacity.count}")# Create capacity reservation group
crg_parameters = {
'location': 'East US',
'zones': ['1', '2'],
'tags': {
'purpose': 'guaranteed-capacity',
'workload': 'critical'
}
}
crg = compute_client.capacity_reservation_groups.create_or_update(
'myResourceGroup',
'myCapacityGroup',
crg_parameters
)
# Create capacity reservation
reservation_parameters = {
'location': 'East US',
'sku': {
'name': 'Standard_D2s_v3',
'capacity': 10 # Reserve 10 instances
},
'zones': ['1'],
'tags': {
'reservation_for': 'peak_hours'
}
}
operation = compute_client.capacity_reservations.begin_create_or_update(
'myResourceGroup',
'myCapacityGroup',
'myCapacityReservation',
reservation_parameters
)
reservation = operation.result()
print(f"Capacity reservation created: {reservation.name}")
# Monitor reservation utilization
instance_view = reservation.instance_view
if instance_view:
utilization = instance_view.utilization_info
print(f"Reserved: {utilization.virtual_machines_allocated}")
print(f"Available: {reservation.sku.capacity - len(utilization.virtual_machines_allocated)}")# Create SSH public key resource
ssh_key_parameters = {
'location': 'East US',
'tags': {
'owner': 'admin',
'purpose': 'linux-vms'
}
}
ssh_key = compute_client.ssh_public_keys.create(
'myResourceGroup',
'mySSHKey',
ssh_key_parameters
)
# Generate new SSH key pair
key_pair = compute_client.ssh_public_keys.generate_key_pair(
'myResourceGroup',
'mySSHKey'
)
print(f"Public key generated: {key_pair.public_key[:50]}...")
print("Store the private key securely!")
# Use the SSH key in VM creation
vm_parameters = {
'location': 'East US',
'hardware_profile': {'vm_size': 'Standard_B1s'},
'storage_profile': {
'image_reference': {
'publisher': 'Canonical',
'offer': '0001-com-ubuntu-server-focal',
'sku': '20_04-lts-gen2',
'version': 'latest'
}
},
'os_profile': {
'computer_name': 'myvm',
'admin_username': 'azureuser',
'disable_password_authentication': True,
'linux_configuration': {
'ssh': {
'public_keys': [{
'path': '/home/azureuser/.ssh/authorized_keys',
'key_data': key_pair.public_key
}]
}
}
},
'network_profile': {
'network_interfaces': [{
'id': '/subscriptions/.../networkInterfaces/mynic'
}]
},
# Use the availability set and proximity placement group
'availability_set': {
'id': availability_set.id
},
'proximity_placement_group': {
'id': ppg.id
}
}
operation = compute_client.virtual_machines.begin_create_or_update(
'myResourceGroup',
'myHighAvailabilityVM',
vm_parameters
)
vm = operation.result()
print(f"High availability VM created: {vm.name}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-compute