edge_stack/provision_env.sh

66 lines
5.3 KiB
Bash
Raw Normal View History

2022-08-03 17:27:48 +00:00
#!/bin/bash
# Variables
jwt=`http --verify=no POST https://192.168.10.1:9443/api/auth Username="adelorenzo" Password="Dimitri2014@" | jq '.jwt' | sed 's/^.//' | sed 's/.$//'`
access="ptr_wo8hpuQq7hgHa6m2HfNLzZdYiBw8ICuClCxPGva/ZTI="
2022-08-03 19:12:07 +00:00
edge_group_id=`http --verify=no GET https://192.168.10.1:9443/api/endpoint_groups "Authorization: Bearer $jwt" | jq -c '.[] | select( .Name == "edge" ) | .Id'`
2022-08-03 17:27:48 +00:00
temperature_tag=`http --verify=no GET https://192.168.10.1:9443/api/tags "Authorization: Bearer $jwt" | jq -c '.[] | select( .Name == "temperature" ) | .ID'`
speed_tag=`http --verify=no GET https://192.168.10.1:9443/api/tags "Authorization: Bearer $jwt" | jq -c '.[] | select( .Name == "speed" ) | .ID'`
pressure_tag=`http --verify=no GET https://192.168.10.1:9443/api/tags "Authorization: Bearer $jwt" | jq -c '.[] | select( .Name == "pressure" ) | .ID'`
power_tag=`http --verify=no GET https://192.168.10.1:9443/api/tags "Authorization: Bearer $jwt" | jq -c '.[] | select( .Name == "power" ) | .ID'`
humidity_tag=`http --verify=no GET https://192.168.10.1:9443/api/tags "Authorization: Bearer $jwt" | jq -c '.[] | select( .Name == "humidity" ) | .ID'`
# Provision edge devices
for i in {00..39}; do pct clone 4444 20$i --full 1 --hostname speed-edge20$i; pct start 20$i; done
for i in {40..79}; do pct clone 4444 20$i --full 1 --hostname speed-edge20$i; pct start 20$i; done
for i in {80..119}; do pct clone 4444 20$i --full 1 --hostname pressure-edge20$i; pct start 20$i; done
for i in {120..159}; do pct clone 4444 20$i --full 1 --hostname humidity-edge20$i; pct start 20$i; done
for i in {160..199}; do pct clone 4444 20$i --full 1 --hostname humidity-edge20$i; pct start 20$i; done
# Add edge agent
for i in {00..39}; do pct exec 20$i -- bash -c "curl http://192.168.11.10/install_edge_agent-x86.sh | bash -"; done
for i in {40..79}; do pct exec 20$i -- bash -c "curl http://192.168.11.10/install_edge_agent-x86.sh | bash -"; done
for i in {80..119}; do pct exec 20$i -- bash -c "curl http://192.168.11.10/install_edge_agent-x86.sh | bash -"; done
for i in {120..159}; do pct exec 20$i -- bash -c "curl http://192.168.11.10/install_edge_agent-x86.sh | bash -"; done
for i in {160..199}; do pct exec 20$i -- bash -c "curl http://192.168.11.10/install_edge_agent-x86.sh | bash -"; done
# Update the tags
for i in {00..39}
do
temperature_endpoint=`http --verify=no GET https://192.168.10.1:9443/api/endpoints "Authorization: Bearer $jwt" | jq -c '.[] | select( .Type == 4 ) | .Name,.Id' | paste - - | grep temp-edge20$i | awk '{ print $2 }'`
2022-08-03 19:12:07 +00:00
echo curl --request PUT --insecure --write-out \"%{http_code}\" --header \'Content-Type: application/json\' --header \'x-api-key: ptr_wo8hpuQq7hgHa6m2HfNLzZdYiBw8ICuClCxPGva/ZTI=\' --url \'https://192.168.10.1:9443/api/endpoints/$temperature_endpoint\' --data \'{\"TagIds\": ["$temperature_tag"]\, \"GroupID\":"$edge_group_id"}\' > tag_add.sh
2022-08-03 17:27:48 +00:00
chmod +x ./tag_add.sh
./tag_add.sh
done
for i in {40..79}
do
speed_endpoint=`http --verify=no GET https://192.168.10.1:9443/api/endpoints "Authorization: Bearer $jwt" | jq -c '.[] | select( .Type == 4 ) | .Name,.Id' | paste - - | grep speed-edge20$i | awk '{ print $2 }'`
2022-08-03 19:12:07 +00:00
echo curl --request PUT --insecure --write-out \"%{http_code}\" --header \'Content-Type: application/json\' --header \'x-api-key: ptr_wo8hpuQq7hgHa6m2HfNLzZdYiBw8ICuClCxPGva/ZTI=\' --url \'https://192.168.10.1:9443/api/endpoints/$speed_endpoint\' --data \'{\"TagIds\": ["$speed_tag"]\, \"GroupID\":"$edge_group_id"}\' > tag_add.sh
2022-08-03 17:27:48 +00:00
chmod +x ./tag_add.sh
./tag_add.sh
done
for i in {80..119}
do
pressure_endpoint=`http --verify=no GET https://192.168.10.1:9443/api/endpoints "Authorization: Bearer $jwt" | jq -c '.[] | select( .Type == 4 ) | .Name,.Id' | paste - - | grep pressure-edge20$i | awk '{ print $2 }'`
2022-08-03 19:12:07 +00:00
echo curl --request PUT --insecure --write-out \"%{http_code}\" --header \'Content-Type: application/json\' --header \'x-api-key: ptr_wo8hpuQq7hgHa6m2HfNLzZdYiBw8ICuClCxPGva/ZTI=\' --url \'https://192.168.10.1:9443/api/endpoints/$pressure_endpoint\' --data \'{\"TagIds\": ["$pressure_tag"]\, \"GroupID\":"$edge_group_id"}\' > tag_add.sh
2022-08-03 17:27:48 +00:00
chmod +x ./tag_add.sh
./tag_add.sh
done
for i in {120..159}
do
humidity_endpoint=`http --verify=no GET https://192.168.10.1:9443/api/endpoints "Authorization: Bearer $jwt" | jq -c '.[] | select( .Type == 4 ) | .Name,.Id' | paste - - | grep humidity-edge20$i | awk '{ print $2 }'`
2022-08-03 19:12:07 +00:00
echo curl --request PUT --insecure --write-out \"%{http_code}\" --header \'Content-Type: application/json\' --header \'x-api-key: ptr_wo8hpuQq7hgHa6m2HfNLzZdYiBw8ICuClCxPGva/ZTI=\' --url \'https://192.168.10.1:9443/api/endpoints/$humidity_endpoint\' --data \'{\"TagIds\": ["$humidity_tag"]\, \"GroupID\":"$edge_group_id"}\' > tag_add.sh
2022-08-03 17:27:48 +00:00
chmod +x ./tag_add.sh
./tag_add.sh
done
for i in {160..199}
do
power_endpoint=`http --verify=no GET https://192.168.10.1:9443/api/endpoints "Authorization: Bearer $jwt" | jq -c '.[] | select( .Type == 4 ) | .Name,.Id' | paste - - | grep power-edge20$i | awk '{ print $2 }'`
2022-08-03 19:12:07 +00:00
echo curl --request PUT --insecure --write-out \"%{http_code}\" --header \'Content-Type: application/json\' --header \'x-api-key: ptr_wo8hpuQq7hgHa6m2HfNLzZdYiBw8ICuClCxPGva/ZTI=\' --url \'https://192.168.10.1:9443/api/endpoints/$power_endpoint\' --data \'{\"TagIds\": ["$power_tag"]\, \"GroupID\":"$edge_group_id"}\' > tag_add.sh
2022-08-03 17:27:48 +00:00
chmod +x ./tag_add.sh
./tag_add.sh
done