-
Notifications
You must be signed in to change notification settings - Fork 1
/
spot-check-azure.sh
87 lines (77 loc) · 3.25 KB
/
spot-check-azure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# example
# bash spot-check-azure.sh Standard_ND6s "'EU West'"
export ARM_SKU=$1
export LOCATION=$2
export METER_NAME=$(echo "'$ARM_SKU Spot'"| sed 's/Standard_//g' |sed 's/_/ /g')
export ARM_SKU_NAME=$(echo "'$ARM_SKU'")
export API_URL=https://prices.azure.com/api/retail/prices
get_all_sku_data(){
DONE="false"
PAGE=0
get_page > ./"page${PAGE}.json"
until [ "$DONE" == "true" ]
do
cat "./page${PAGE}.json"|jq -r '.NextPageLink'
# if [ -z "$API_URL" ]; then
export DONE="true"
# else
# get_page > "./page${PAGE}.json"
# echo "Page${PAGE} ✅"
# let PAGE++
# export DONE="true"
# fi
done
}
get_page(){
docker run --platform linux/amd64 \
-e API_URL="$API_URL" \
-e LOCATION="$LOCATION" \
-e SERVICE_NAME="'Virtual Machines'" \
-e SERVICE_FAMILY="'Compute'" \
-e METER_NAME="$METER_NAME" \
-e ARM_SKU_NAME="$ARM_SKU_NAME" \
-e ARM_SKU="$ARM_SKU" \
-e ARM_CLIENT_ID=$(bw get item admin-robot |jq -r '.fields[] |select(.name=="clientId") |.value') \
-e ARM_CLIENT_SECRET=$(bw get item admin-robot |jq -r '.fields[] |select(.name=="clientSecret") |.value') \
-e ARM_TENANT_ID=$(bw get item admin-robot |jq -r '.fields[] |select(.name=="tenantId") |.value') \
mcr.microsoft.com/azure-cli:2.9.1 sh -c 'az login --service-principal \
--username "$ARM_CLIENT_ID" \
--password "$ARM_CLIENT_SECRET" \
--tenant "$ARM_TENANT_ID" -o none && \
echo "az rest --method get --uri \"${API_URL}?\\\$filter=location eq $LOCATION and serviceName eq $SERVICE_NAME and serviceFamily eq $SERVICE_FAMILY\""|sh'
}
get_price(){
docker run --platform linux/amd64 \
-e API_URL="https://prices.azure.com/api/retail/prices" \
-e LOCATION="$LOCATION" \
-e SERVICE_NAME="'Virtual Machines'" \
-e SERVICE_FAMILY="'Compute'" \
-e METER_NAME="$METER_NAME" \
-e ARM_SKU_NAME="$ARM_SKU_NAME" \
-e ARM_SKU="$ARM_SKU" \
-e ARM_CLIENT_ID=$(bw get item admin-robot |jq -r '.fields[] |select(.name=="clientId") |.value') \
-e ARM_CLIENT_SECRET=$(bw get item admin-robot |jq -r '.fields[] |select(.name=="clientSecret") |.value') \
-e ARM_TENANT_ID=$(bw get item admin-robot |jq -r '.fields[] |select(.name=="tenantId") |.value') \
mcr.microsoft.com/azure-cli:2.9.1 sh -c 'az login --service-principal \
--username "$ARM_CLIENT_ID" \
--password "$ARM_CLIENT_SECRET" \
--tenant "$ARM_TENANT_ID" 2>&1 > /dev/null && \
echo "az rest --method get --uri \"${API_URL}?\\\$filter=\
location eq $LOCATION and \
serviceName eq $SERVICE_NAME and \
serviceFamily eq $SERVICE_FAMILY and \
armSkuName eq $ARM_SKU_NAME and \
meterName eq $METER_NAME"\" \
--query \"[Items][0][*].{name:productName, sku:armSkuName, location:location, hourly_price:retailPrice, hourly_price:retailPrice, currency:currencyCode, type:type}\" \
-o json --only-show-errors'
}
get_cpu_info(){
export CPU=$(yq -r --prettyPrint -o=json '.vendors.azure.*.[] |select (.instance_name == env(ARM_SKU)) | .cpu' instances.yaml)
yq -r --prettyPrint -o=json '.processors.*.[] | select (.cpu_name == env(CPU))' instances.yaml > cpu-info.json
}
main(){
jq -s '.[0] * .[1]' cpu-info.json price.json
}
#get_price
get_all_sku_data