Skip to content

Commit 08603ee

Browse files
committed
merge with clu again
2 parents e7701e3 + 364a997 commit 08603ee

38 files changed

+797
-885
lines changed

examples/resource-management/04-RoleAssignments.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ az role assignment create --ObjectId "$userId" --RoleDefinitionId "$roleDefiniti
2121

2222
printf "\n3. Delete last created Role Assignment.\n"
2323
assignments=$(az role assignment get)
24-
assignmentId=$(echo $assignments | cat | jq '.[-1].ObjectId' -s --raw-output)
24+
assignmentId=$(echo $assignments | cat | jq '.[-1:][0].ObjectId' -s --raw-output)
25+
echo "Deleting assignment: $assignmentId"
2526
az role assignment remove --ObjectId "$assignmentId" --Scope "$scope" --RoleDefinitionId "$roleDefinitionId" -f
2627
export MSYS_NO_PATHCONV=
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing App Service Plans in Azure ===\n"
4+
5+
#setup
6+
printf "\nSetup: Creating a new resource group: %s at location: %s.\n" "$groupName" "$location"
7+
export whpName=`randomName testplan`
8+
tier="Standard"
9+
size="Medium"
10+
capacity=2
11+
skuName="S2"
12+
azure group create --name "$groupName" --location "$location"
13+
14+
printf "\n1. Create a new app service plan %s " "$whpName"
15+
azure app service plan create -n "$whpName" -g "$groupName" -l "$location" --tier "$tier" --size "$size" --workers "$capacity"
16+
17+
printf "\n2. Get information about the app service plan : %s.\n" "$whpName"
18+
whpInfo=`azure app service plan get --name $whpName --group $groupName`
19+
20+
printf "\nValidating app service plan name: %s\n" "$whpName"
21+
[ $(echo $whpInfo | jq '.name' --raw-output) == "$whpName" ]
22+
[ $(echo $whpInfo | jq '.location' --raw-output) == "West US" ]
23+
[ $(echo $whpInfo | jq '.sku.tier' --raw-output) == "$tier" ]
24+
[ $(echo $whpInfo | jq '.sku.name' --raw-output) == "$skuName" ]
25+
[ $(echo $whpInfo | jq '.sku.capacity' --raw-output) -eq $capacity ]
26+
27+
printf "\n3. Set the appservice plan: %s " "$whpName"
28+
newTier="Shared"
29+
newCapacity=0
30+
newSize="Medium"
31+
setPlanInfo=`azure app service plan set -n $whpName -g $groupName --tier $newTier --workers --workers $newCapacity --size $newSize`
32+
[ $(echo $setPlanInfo | jq '.name' --raw-output) == "$whpName" ]
33+
[ $(echo $setPlanInfo | jq '.sku.tier' --raw-output) == "$newTier" ]
34+
[ $(echo $setPlanInfo | jq '.sku.capacity' --raw-output) -eq $newCapacity ]
35+
[ $(echo $setPlanInfo | jq '.sku.name' --raw-output) == "D1" ]
36+
[ $(echo $setPlanInfo | jq '.["properties.geoRegion"]' --raw-output) == "West US" ]
37+
38+
whpName2=`randomName testplan`
39+
printf "\n4. Creating a new app service plan: %s" "$whpName2"
40+
location2="East US"
41+
azure app service plan create -n "$whpName2" -g "$groupName" -l "$location2" --tier "$tier" --size "$size" --workers "$capacity"
42+
43+
printf "\n5. Get All app service plans by name: %s" "$whpName2"
44+
whpInfo2=`azure app service plan get --name $whpName2`
45+
[ $(echo $whpInfo | jq '.name' --raw-output) == "$whpName2" ]
46+
[ $(echo $whpInfo | jq '.location' --raw-output) == "$location2" ]
47+
[ $(echo $whpInfo | jq '.sku.tier' --raw-output) == "$tier" ]
48+
[ $(echo $whpInfo | jq '.sku.name' --raw-output) == "$skuName" ]
49+
[ $(echo $whpInfo | jq '.sku.capacity' --raw-output) -eq $capacity ]
50+
51+
printf "\n6. Get All app service plans by resource group: %s" "$groupName"
52+
plansByGroup=`azure app service plan get --group $groupName`
53+
[ $plansByGroup == *"$whpName"* ]
54+
[ $plansByGroup == *"$whpName2"* ]
55+
56+
printf "\n7. Get All app service plans by location: %s" "$location2"
57+
plansByLocation=`azure app service plan get -l $location2`
58+
[ $plansByLocation == *"$whpName2"* ]
59+
60+
printf "\n8. Get All app service plans in a subscription."
61+
plansInSubscription=`azure app service plan get`
62+
[ $plansInSubscription == *"$whpName"* ]
63+
[ $plansInSubscription == *"$whpName2"* ]
64+
65+
printf "\n9. Remove app service plan: %s." "$whpName"
66+
azure app service plan remove -n $whpName -g $groupName
67+
68+
printf "\n10. Remove app service plan: %s." "$whpName2"
69+
azure app service plan remove -n $whpName2 -g $groupName
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing Web App Slot in Azure ===\n"
4+
5+
pingwebapp() {
6+
# a helper function to ping a webapp
7+
}
8+
9+
#setup
10+
printf "\nSetup: Creating a new resource group: %s at location: %s.\n" "$groupName" "$location"
11+
12+
appName=`randomName testweb`
13+
slotname1="staging"
14+
slotname2="testing"
15+
planName=`randomName testplan`
16+
tier="Standard"
17+
apiversion="2015-08-01"
18+
resourceType="Microsoft.Web/sites"
19+
20+
azure group create --name "$groupName" --location "$location"
21+
22+
printf "\n1. Create a new app service plan %s " "$planName"
23+
azure app service plan create -n "$planName" -g "$groupName" -l "$location" --tier "$tier"
24+
25+
printf "\n2. Create a new web app %s " "$appName"
26+
webappInfo=`azure webapp create -g "$groupName" -n "$appName" -l "$location" --plan "$planName"`
27+
28+
printf "\nValidating web app name %s " "$appName"
29+
[ $(echo $webappInfo | jq '.name' --raw-output) == "$appName" ]
30+
31+
printf "\n3. Create a web app slot %s " "$slotname1"
32+
slot1=`azure webapp slot create -g "$groupName" --plan "$planName" -n "$appName" --slot "$slotname1"`
33+
appWithSlotName1="$appName/$slotname1"
34+
35+
printf "\nValidating web app slot %s " "$slotname1"
36+
[ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotName1" ]
37+
38+
printf "\nValidating web app slot get for %s " "$slotname1"
39+
slot1=`azure webapp slot get -g "$groupName" -n "$appName" --slot "$slotname1"`
40+
[ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotName1" ]
41+
42+
printf "\nValidating web app slot via pipline obj for %s " "$slotname1"
43+
slot1=`echo "$webappInfo" | azure webapp slot get --slot "$slotname1"`
44+
45+
printf "\n4. Create another web app slot %s " "$slotname2"
46+
slot2=`azure webapp slot create -g "$groupName" --plan "$planName" -n "$appName" --slot "$slotname2"`
47+
appWithSlotName2="$appName/$slotname2"
48+
49+
printf "\n5. Get the webapp slots:"
50+
slots=`azure webapp slot get -g "$groupName" -n "$appName"`
51+
slotN1=`echo $slots | jq '.[0].name'`
52+
slotN2=`echo $slots | jq '.[1].name'`
53+
slotNames=`echo $slotN1 $slotN2`
54+
55+
printf "\nValidating web app slots %s " "$slotname1 and $slotname2"
56+
[[ $slotNames == *"$appWithSlotName1"* ]]
57+
[[ $slotNames == *"$appWithSlotName2"* ]]
58+
59+
printf "\n6. Change web app slot %s service plan" "$slotname2"
60+
printf "\n7. Set web app slot %s config properties" "$slotname2"
61+
printf "\n8. Set web app slot %s settings and connection strings" "$slotname2"
62+
63+
printf "\n9. Get web app slot %s publishing profile" "$slotname1"
64+
printf "\n10. Get web app slot %s publishing profile via pipline obj" "$slotname1"
65+
66+
printf "\n11. Get web app slot metrics %s " "$slotname1"
67+
for i in {1..10}
68+
do
69+
pingwebapp $slot1
70+
done
71+
72+
endTime=`date +"%A, %B %d, %Y %X"`
73+
startTime=`date +"%A, %B %d, %Y %X" --date "3 hour ago"`
74+
$metricsNames="\"('CPU', 'Requests')\""
75+
76+
# !Not able to test since complex object issue.
77+
metrics=`azure webapp slot metrics get -g "$groupName" -n "$appName" --slot "$slotname1" --granularity PT1M --starttime "$startTime" --endtime "$endTime" --metrics "$metricsNames"`
78+
79+
printf "\nValidating web app slot metrics %s " "$slotname1"
80+
for i in $metricsNames
81+
do
82+
[ $(echo $metrics ) == "$i" ]
83+
done
84+
85+
# !Not able to test pipeline for now
86+
printf "\nValidating web app slot metrics via pipline obj %s " "$slotname1"
87+
88+
printf "\n12. Stop web app slot: %s." "$slotname1"
89+
slot1=`echo "$slot1" | azure webapp slot stop`
90+
printf "\nValidating web app slot %s stopped " "$slotname1"
91+
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Stopped" ]
92+
93+
printf "\n13 Stop web app slot: %s." "$slotname1"
94+
slot1=`echo "$slot1" | azure webapp slot start`
95+
printf "\nValidating web app slot %s running " "$slotname1"
96+
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
97+
98+
printf "\n14 Stop web app slot: %s." "$slotname1"
99+
slot1=`echo "$slot1" | azure webapp slot stop`
100+
printf "\nValidating web app slot %s stopped " "$slotname1"
101+
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Stopped" ]
102+
103+
printf "\n15 Stop web app slot: %s." "$slotname1"
104+
slot1=`echo "$slot1" | azure webapp slot start`
105+
printf "\nValidating web app slot %s running " "$slotname1"
106+
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
107+
108+
printf "\n16 Restart web app slot: %s." "$slotname1"
109+
slot1=`echo "$slot1" | azure webapp slot restart`
110+
printf "\nValidating web app slot %s Running " "$slotname1"
111+
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
112+
113+
printf "\n17 Restart web app slot: %s." "$slotname1"
114+
slot1=`echo "$slot1" | azure webapp slot restart`
115+
printf "\nValidating web app slot %s Running " "$slotname1"
116+
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
117+
118+
# Clone ------
119+
# !Not able to test since complex object input issue.
120+
# printf "\n10. Clone web app slot: %s." "$slotname1"
121+
# slotClone=`azure web app slot clone`
122+
# appWithSlotNameClone="$appName/slotname1"
123+
124+
# printf "\nValidating cloned web app slot %s " "$slotname1"
125+
# [ $(echo $slotClone | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
126+
127+
# printf "\nValidating web app slot get for %s " "$slotname1"
128+
# slot1=`azure webapp slot get -g "$groupName" -n "$appName" --slot "$slotname1"`
129+
# [ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
130+
#-------
131+
132+
# Cleanup
133+
printf "\n20. Remove web app slot: %s." "$slotname1"
134+
azure webapp slot remove -g "$groupName" -n "$appName" --slot "$slotname1"
135+
136+
printf "\n20. Remove web app: %s." "$appName"
137+
azure webapp remove -g "$groupName" -n "$appName"
138+
139+
printf "\n20. Remove app service plan: %s." "$planName"
140+
azure app service plan remove -g "$groupName" -n "$planName"
141+
142+
printf "\n20. Remove resource group: %s." "$groupName"

0 commit comments

Comments
 (0)