Microsoft Azure Web Apps Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Management of App Service Environments (ASE) for isolated, high-scale application hosting with advanced networking and security features.
azure.mgmt.web.operations.AppServiceEnvironmentsOperationsclient.app_service_environmentsfrom azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web.models import (
AppServiceEnvironment, AppServiceEnvironmentResource,
VirtualNetworkProfile, WorkerPool, HostingEnvironmentProfile
)
from azure.identity import DefaultAzureCredentialfrom azure.mgmt.web import WebSiteManagementClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
client = WebSiteManagementClient(credential, subscription_id)
# List all App Service Environments
ases = client.app_service_environments.list()
for ase in ases:
print(f"ASE: {ase.name}, Location: {ase.location}, Status: {ase.status}")
# Get specific ASE details
ase_details = client.app_service_environments.get(
resource_group_name="my-resource-group",
name="my-ase"
)
print(f"ASE Kind: {ase_details.kind}, Max Workers: {ase_details.maximum_number_of_machines}")Create a new ASE or update an existing one.
def create_or_update(
self,
resource_group_name: str,
name: str,
hosting_environment_envelope: AppServiceEnvironment,
**kwargs
) -> AppServiceEnvironment:
"""
Create or update an App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
hosting_environment_envelope: ASE configuration
Returns:
AppServiceEnvironment object
"""Usage Example:
from azure.mgmt.web.models import (
AppServiceEnvironment, VirtualNetworkProfile, WorkerPool
)
# Configure ASE settings
vnet_profile = VirtualNetworkProfile(
id="/subscriptions/{subscription-id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet-name}",
subnet="/subscriptions/{subscription-id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet-name}/subnets/{subnet-name}"
)
worker_pools = [
WorkerPool(
worker_size_id=0, # Small
compute_mode="Shared", # Shared or Dedicated
worker_size="Small",
worker_count=2
),
WorkerPool(
worker_size_id=1, # Medium
compute_mode="Dedicated",
worker_size="Medium",
worker_count=0
),
WorkerPool(
worker_size_id=2, # Large
compute_mode="Dedicated",
worker_size="Large",
worker_count=0
)
]
ase_config = AppServiceEnvironment(
location="East US",
kind="ASEV2", # ASEV2 or ASEV3
virtual_network=vnet_profile,
internal_load_balancing_mode="Web", # None, Web, Publishing, or WebPublishing
multi_size="Standard_D1_v2",
multi_role_count=2,
worker_pools=worker_pools,
dns_suffix="myase.appserviceenvironment.net",
network_access_control_list=[
{
"action": "Permit",
"description": "Allow management traffic",
"order": 100,
"remote_subnet": "10.0.0.0/24"
}
]
)
# Create ASE (this is a long-running operation)
ase = client.app_service_environments.create_or_update(
resource_group_name="my-resource-group",
name="my-ase",
hosting_environment_envelope=ase_config
)Retrieve details for a specific ASE.
def get(
self,
resource_group_name: str,
name: str,
**kwargs
) -> AppServiceEnvironment:
"""
Get App Service Environment details.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
AppServiceEnvironment object
"""Get all ASEs in a subscription or resource group.
def list(self, **kwargs) -> List[AppServiceEnvironment]:
"""
List all App Service Environments in the subscription.
Returns:
List of AppServiceEnvironment objects
"""
def list_by_resource_group(
self,
resource_group_name: str,
**kwargs
) -> List[AppServiceEnvironment]:
"""
List App Service Environments in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
List of AppServiceEnvironment objects
"""Remove an App Service Environment.
def delete(
self,
resource_group_name: str,
name: str,
**kwargs
) -> None:
"""
Delete an App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
"""Get all worker pools in an ASE.
def list_worker_pools(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[WorkerPoolResource]:
"""
List worker pools in the App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of WorkerPoolResource objects
"""Retrieve details for a specific worker pool.
def get_worker_pool(
self,
resource_group_name: str,
name: str,
worker_pool_name: str,
**kwargs
) -> WorkerPoolResource:
"""
Get worker pool details.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
worker_pool_name: Name of the worker pool
Returns:
WorkerPoolResource object
"""Modify worker pool configuration.
def create_or_update_worker_pool(
self,
resource_group_name: str,
name: str,
worker_pool_name: str,
worker_pool_envelope: WorkerPoolResource,
**kwargs
) -> WorkerPoolResource:
"""
Create or update a worker pool.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
worker_pool_name: Name of the worker pool
worker_pool_envelope: Worker pool configuration
Returns:
WorkerPoolResource object
"""Usage Example:
# List worker pools
worker_pools = client.app_service_environments.list_worker_pools(
resource_group_name="my-resource-group",
name="my-ase"
)
for pool in worker_pools:
print(f"Pool: {pool.name}, Size: {pool.worker_size}, Count: {pool.worker_count}")
# Update worker pool to scale up
from azure.mgmt.web.models import WorkerPoolResource
updated_pool = WorkerPoolResource(
worker_size="Medium",
worker_count=4,
compute_mode="Dedicated"
)
client.app_service_environments.create_or_update_worker_pool(
resource_group_name="my-resource-group",
name="my-ase",
worker_pool_name="1", # Worker pool ID (0, 1, 2)
worker_pool_envelope=updated_pool
)Retrieve the multi-role pool configuration.
def get_multi_role_pool(
self,
resource_group_name: str,
name: str,
**kwargs
) -> WorkerPoolResource:
"""
Get multi-role pool details.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
WorkerPoolResource object representing the multi-role pool
"""Modify the multi-role pool configuration.
def create_or_update_multi_role_pool(
self,
resource_group_name: str,
name: str,
multi_role_pool_envelope: WorkerPoolResource,
**kwargs
) -> WorkerPoolResource:
"""
Create or update the multi-role pool.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
multi_role_pool_envelope: Multi-role pool configuration
Returns:
WorkerPoolResource object
"""Get inbound network dependencies for the ASE.
def list_inbound_network_dependencies_endpoints(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[InboundEnvironmentEndpoint]:
"""
List inbound network dependencies.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of InboundEnvironmentEndpoint objects
"""Get outbound network dependencies for the ASE.
def list_outbound_network_dependencies_endpoints(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[OutboundEnvironmentEndpoint]:
"""
List outbound network dependencies.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of OutboundEnvironmentEndpoint objects
"""Usage Example:
# Check inbound network dependencies
inbound_deps = client.app_service_environments.list_inbound_network_dependencies_endpoints(
resource_group_name="my-resource-group",
name="my-ase"
)
for dep in inbound_deps:
print(f"Inbound: {dep.description}")
for endpoint in dep.endpoints:
print(f" - {endpoint}")
# Check outbound network dependencies
outbound_deps = client.app_service_environments.list_outbound_network_dependencies_endpoints(
resource_group_name="my-resource-group",
name="my-ase"
)
for dep in outbound_deps:
print(f"Outbound: {dep.category}")
for endpoint in dep.endpoints:
print(f" - {endpoint.domain_name}:{endpoint.port}")Temporarily suspend an ASE.
def suspend(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[Site]:
"""
Suspend an App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of Site objects (apps in the ASE)
"""Resume a suspended ASE.
def resume(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[Site]:
"""
Resume an App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of Site objects (apps in the ASE)
"""Restart an App Service Environment.
def reboot(
self,
resource_group_name: str,
name: str,
**kwargs
) -> None:
"""
Reboot an App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
"""Usage Example:
# Suspend ASE for maintenance
suspended_apps = client.app_service_environments.suspend(
resource_group_name="my-resource-group",
name="my-ase"
)
print(f"Suspended ASE with {len(suspended_apps)} apps")
# Resume ASE after maintenance
resumed_apps = client.app_service_environments.resume(
resource_group_name="my-resource-group",
name="my-ase"
)
print(f"Resumed ASE with {len(resumed_apps)} apps")Get all applications hosted in the ASE.
def list_web_apps(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[Site]:
"""
List web apps in the App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of Site objects
"""Get all App Service Plans in the ASE.
def list_app_service_plans(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[AppServicePlan]:
"""
List App Service Plans in the App Service Environment.
Args:
resource_group_name: Name of the resource group
name: Name of the App Service Environment
Returns:
List of AppServicePlan objects
"""class AppServiceEnvironment:
"""Represents an App Service Environment."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
kind: Optional[str] # ASEV2, ASEV3
provisioning_state: Optional[str]
status: Optional[str] # Preparing, Ready, Scaling, Deleting
virtual_network: Optional[VirtualNetworkProfile]
internal_load_balancing_mode: Optional[str] # None, Web, Publishing, WebPublishing
multi_size: Optional[str] # VM size for multi-role pool
multi_role_count: Optional[int]
worker_pools: Optional[List[WorkerPool]]
ipssl_address_count: Optional[int]
dns_suffix: Optional[str]
maximum_number_of_machines: Optional[int]
front_end_scale_factor: Optional[int]
network_access_control_list: Optional[List[NetworkAccessControlEntry]]
user_whitelisted_ip_ranges: Optional[List[str]]
has_linux_workers: Optional[bool]
upgrade_preference: Optional[str] # None, Early, Late, Manualclass WorkerPool:
"""Represents a worker pool in an ASE."""
worker_size_id: Optional[int] # 0=Small, 1=Medium, 2=Large
compute_mode: Optional[str] # Shared, Dedicated
worker_size: Optional[str] # Small, Medium, Large, ExtraLarge
worker_count: Optional[int]
instance_names: Optional[List[str]]class VirtualNetworkProfile:
"""Virtual network configuration for ASE."""
id: Optional[str] # Virtual network resource ID
name: Optional[str]
type: Optional[str]
subnet: Optional[str] # Subnet resource IDclass WorkerPoolResource:
"""Worker pool resource representation."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
worker_size_id: Optional[int]
compute_mode: Optional[str]
worker_size: Optional[str]
worker_count: Optional[int]
instance_names: Optional[List[str]]
sku: Optional[SkuDescription]class InboundEnvironmentEndpoint:
"""Inbound network endpoint information."""
description: Optional[str]
endpoints: Optional[List[str]]
ports: Optional[List[str]]class OutboundEnvironmentEndpoint:
"""Outbound network endpoint information."""
category: Optional[str]
endpoints: Optional[List[EndpointDependency]]class EndpointDependency:
"""Network endpoint dependency."""
domain_name: Optional[str]
endpoint_details: Optional[List[EndpointDetail]]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-web