Skip to content

Commit 349b9aa

Browse files
Agents/setup/updte readme and model (#211)
* delete script plus documentation updates * Model and Workspace location as same
1 parent 431b7d2 commit 349b9aa

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

scenarios/Agents/setup/network-secured-agent/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ languages:
2929

3030
This infrastructure-as-code (IaC) solution deploys a network-secured Azure AI agent environment with private networking, managed identities, and role-based access control (RBAC).
3131

32+
3233
## Note:
3334
Make sure you have an active Azure subscription that allows registering resource providers.
3435
Subnet delegation requires the Microsoft.App provider to be registered in your subscription. If it's not already registered, run the command below:
@@ -225,6 +226,12 @@ Storage: privatelink.blob.core.windows.net
225226
- Activity logging
226227
- Network monitoring
227228

229+
## Limitations
230+
- AI Services/Azure OpenAI resource must be in the same region as Hub and Project workspace. This restriction would be removed in next revision (coming soon).
231+
- The capability host sub-resources of Hub/Project must be deleted before deleting the Hub/Project resource itself. You can use the script as sample to delete it or can be done in alternate ways via ARM. This restriction would be removed in next revision (coming soon).
232+
- [Run delete script](../utils/deleteCaphost.sh)
233+
234+
228235
## Maintenance
229236

230237
### Regular Tasks

scenarios/Agents/setup/network-secured-agent/azuredeploy.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.33.93.31351",
8-
"templateHash": "2971870935601910382"
8+
"templateHash": "127170888874315892"
99
}
1010
},
1111
"parameters": {
@@ -165,7 +165,7 @@
165165
},
166166
"modelLocation": {
167167
"type": "string",
168-
"defaultValue": "eastus",
168+
"defaultValue": "[parameters('resourceGroupLocation')]",
169169
"metadata": {
170170
"description": "Model deployment location. If you want to deploy an Azure AI resource/model in different location than the rest of the resources created."
171171
}

scenarios/Agents/setup/network-secured-agent/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ param modelSkuName string = 'GlobalStandard'
106106
param modelCapacity int = 50
107107

108108
@description('Model deployment location. If you want to deploy an Azure AI resource/model in different location than the rest of the resources created.')
109-
param modelLocation string = 'eastus'
109+
param modelLocation string = resourceGroupLocation
110110

111111
@description('AI service kind, values can be "OpenAI" or "AIService"')
112112
param aisKind string = 'AIServices'
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# Script to delete an Azure ML capability host
4+
5+
# Prompt for required information
6+
read -p "Enter Subscription ID: " subscription_id
7+
read -p "Enter Resource Group name: " resource_group
8+
read -p "Enter Hub or Project name: " workspace_name
9+
read -p "Enter CapabilityHost name: " caphost_name
10+
11+
# Get Azure access token
12+
echo "Getting Azure access token..."
13+
access_token=$(az account get-access-token --query accessToken -o tsv)
14+
15+
if [ -z "$access_token" ]; then
16+
echo "Error: Failed to get access token. Please make sure you're logged in with 'az login'"
17+
exit 1
18+
fi
19+
20+
# Construct the API URL
21+
api_url="https://management.azure.com/subscriptions/${subscription_id}/resourceGroups/${resource_group}/providers/Microsoft.MachineLearningServices/workspaces/${workspace_name}/capabilityHosts/${caphost_name}?api-version=2024-10-01-preview"
22+
23+
echo "Deleting capability host: ${caphost_name}"
24+
echo "API URL: ${api_url}"
25+
26+
# Send DELETE request and capture headers
27+
echo "Sending DELETE request..."
28+
response_headers=$(mktemp)
29+
curl -X DELETE \
30+
-H "Authorization: Bearer ${access_token}" \
31+
-H "Content-Type: application/json" \
32+
-D "${response_headers}" \
33+
-s \
34+
"${api_url}"
35+
36+
# Check if the curl command was successful
37+
if [ $? -ne 0 ]; then
38+
echo -e "\nError: Failed to send deletion request."
39+
rm -f "${response_headers}"
40+
exit 1
41+
fi
42+
43+
# Extract the Azure-AsyncOperation URL from the response headers
44+
operation_url=$(grep -i "Azure-AsyncOperation" "${response_headers}" | cut -d' ' -f2 | tr -d '\r')
45+
46+
if [ -z "${operation_url}" ]; then
47+
echo -e "\nError: Could not find operation URL in the response."
48+
cat "${response_headers}"
49+
rm -f "${response_headers}"
50+
exit 1
51+
fi
52+
53+
rm -f "${response_headers}"
54+
55+
echo -e "\nCapability host deletion request initiated."
56+
echo "Monitoring operation: ${operation_url}"
57+
58+
# Poll the operation URL until the operation completes
59+
status="InProgress"
60+
while [ "${status}" = "InProgress" ]; do
61+
echo "Checking operation status..."
62+
63+
# Get the operation status
64+
operation_response=$(curl -s \
65+
-H "Authorization: Bearer ${access_token}" \
66+
-H "Content-Type: application/json" \
67+
"${operation_url}")
68+
69+
# Extract the status from the response
70+
status=$(echo "${operation_response}" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
71+
72+
if [ -z "${status}" ]; then
73+
echo "Error: Could not determine operation status."
74+
echo "Response: ${operation_response}"
75+
exit 1
76+
fi
77+
78+
echo "Current status: ${status}"
79+
80+
if [ "${status}" = "InProgress" ]; then
81+
echo "Operation still in progress. Waiting 10 seconds before checking again..."
82+
sleep 10
83+
fi
84+
done
85+
86+
# Check the final status
87+
if [ "${status}" = "Succeeded" ]; then
88+
echo -e "\nCapability host deletion completed successfully."
89+
else
90+
echo -e "\nCapability host deletion failed with status: ${status}"
91+
echo "Response: ${operation_response}"
92+
exit 1
93+
fi

0 commit comments

Comments
 (0)