{"id":1386,"library":"azure-mgmt-trafficmanager","title":"Azure Traffic Manager Management","description":"The Azure Traffic Manager Management Client Library for Python allows developers to programmatically manage Azure Traffic Manager profiles, endpoints, and configurations. It is part of the Azure SDK for Python, currently at version 1.1.0, and typically follows a frequent release cadence, often coinciding with Azure service updates.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/trafficmanager/azure-mgmt-trafficmanager","tags":["azure","management","cloud","traffic manager","dns","load balancing"],"install":[{"cmd":"pip install azure-mgmt-trafficmanager azure-identity","lang":"bash","label":"Install core library and authentication"}],"dependencies":[{"reason":"Required for authentication with Azure services.","package":"azure-identity","optional":false},{"reason":"Core functionalities for Azure management plane clients.","package":"azure-mgmt-core","optional":false}],"imports":[{"symbol":"TrafficManagerManagementClient","correct":"from azure.mgmt.trafficmanager import TrafficManagerManagementClient"},{"note":"The `msrestazure` based credentials are for older SDK versions (Track 1). Modern Azure SDKs (Track 2) use `azure-identity`.","wrong":"from msrestazure.azure_active_directory import AADTokenCredentials","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.trafficmanager import TrafficManagerManagementClient\n\n# --- Environment Variables (for local development) ---\n# AZURE_SUBSCRIPTION_ID: Your Azure Subscription ID\n# AZURE_CLIENT_ID: Your Azure AD Application (client) ID\n# AZURE_CLIENT_SECRET: Your Azure AD Application client secret\n# AZURE_TENANT_ID: Your Azure AD Tenant ID\n\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\nresource_group_name = \"my-traffic-manager-rg\"\nprofile_name = \"myuniquetmprofile123\" # Must be globally unique\n\n# Authenticate using DefaultAzureCredential\n# This credential type tries various auth methods suitable for local dev and production\ncredential = DefaultAzureCredential()\n\n# Create a TrafficManagerManagementClient\ntraffic_manager_client = TrafficManagerManagementClient(credential, subscription_id)\n\nprint(f\"Listing Traffic Manager profiles in subscription {subscription_id}:\")\nfor profile in traffic_manager_client.profiles.list_by_subscription():\n    print(f\"- {profile.name} (Status: {profile.profile_status})\")\n\n# Example: Create a simple Traffic Manager profile\n# Note: This is a basic example, a real profile would need endpoints\nlocation = \"global\" # Traffic Manager is a global service\n\nprofile_parameters = {\n    \"location\": location,\n    \"profile_status\": \"Enabled\",\n    \"traffic_routing_method\": \"Performance\",\n    \"dns_config\": {\n        \"relative_name\": profile_name, # This forms the globally unique FQDN: <relative_name>.trafficmanager.net\n        \"ttl\": 300\n    },\n    \"monitor_config\": {\n        \"protocol\": \"HTTP\",\n        \"port\": 80,\n        \"path\": \"/\"\n    }\n}\n\nprint(f\"\\nAttempting to create/update Traffic Manager profile '{profile_name}'...\")\npoller = traffic_manager_client.profiles.begin_create_or_update(\n    resource_group_name,\n    profile_name,\n    profile_parameters\n)\nprofile_result = poller.result()\nprint(f\"Profile '{profile_result.name}' created/updated successfully.\")\nprint(f\"FQDN: {profile_result.dns_config.fqdn}\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with `DefaultAzureCredential`, create a `TrafficManagerManagementClient`, list existing Traffic Manager profiles, and create a new basic profile. Ensure your environment variables for Azure authentication are set, or replace placeholders with actual values."},"warnings":[{"fix":"Migrate your authentication code to use classes from `azure.identity`, like `DefaultAzureCredential`. See Azure Identity documentation for more details.","message":"Older Azure Management SDKs (often referred to as Track 1) used `msrestazure.azure_active_directory.AADTokenCredentials` for authentication. Modern Azure SDKs (Track 2, including this library) exclusively use `azure-identity` library for authentication, such as `DefaultAzureCredential`.","severity":"breaking","affected_versions":"<1.0.0 (Track 1 libraries) vs. >=1.0.0 (Track 2 libraries)"},{"fix":"Choose a highly unique name for your Traffic Manager profile, often by incorporating a random string or GUID, to ensure global uniqueness.","message":"Traffic Manager profile names (`dns_config.relative_name`) must be globally unique across all of Azure, not just within your subscription or resource group. If the name is already taken, creation will fail.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `profile_parameters['location'] = 'global'` when defining your profile configuration.","message":"When creating or updating a Traffic Manager profile, the `location` property must always be set to 'global'. Traffic Manager is a global service and does not reside in a specific Azure region.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the official Azure SDK for Python documentation and samples on GitHub to ensure you are using the most up-to-date and recommended patterns for client interaction and resource management.","message":"Older methods for working with management clients might be replaced by new patterns (e.g., direct property access vs. `get_` methods). Always refer to the latest SDK documentation and samples for the current idiomatic usage.","severity":"deprecated","affected_versions":"Prior major versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}