-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for deploying a digital twin that matches the smart traile…
…r use case (#19) * Add script for deploying a digital twin that matches the smart trailer use case * Minor script syntax changes and Readme updates
- Loading branch information
Showing
5 changed files
with
154 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"@context": [ | ||
"dtmi:dtdl:context;2" | ||
], | ||
"@type": "Interface", | ||
"@id": "dtmi:sdv:Cloud:Trailer;1", | ||
"description": "Trailer used for transporting cargo", | ||
"contents": [ | ||
{ | ||
"@type": "Property", | ||
"@id": "dtmi:sdv:Cloud:Trailer:Weight;1", | ||
"name": "Weight", | ||
"description": "The weight of the trailer", | ||
"schema": "integer" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
cloud_connectors/azure/scripts/digital_twins_setup_smart_trailer.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
# SPDX-License-Identifier: MIT | ||
|
||
set -e | ||
|
||
# Set the current directory to where the script lives. | ||
cd "$(dirname "$0")" | ||
|
||
# Function to display usage information | ||
usage() { | ||
echo "Usage: $0 [-r|--resource-group-name] <RESOURCE_GROUP_NAME> [-l|--location] <DEPLOYMENT_LOCATION> [-d|--digital-twins-name] <DIGITAL_TWINS_NAME>" | ||
echo "Example:" | ||
echo " $0 -r myRG -l westus2 -d myADT" | ||
} | ||
|
||
# Parse command line arguments | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
-r|--resource-group-name) | ||
resource_group="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-l|--location) | ||
location="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-d|--digital-twins-name) | ||
digital_twin_name="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-h|--help) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
echo "Unknown argument: $key" | ||
usage | ||
exit 1 | ||
esac | ||
done | ||
|
||
# Check if all required arguments have been set | ||
if [[ -z "${resource_group}" || -z "${location}" || -z "${digital_twin_name}" ]]; then | ||
echo "Error: Missing required arguments:" | ||
[[ -z "${resource_group}" ]] && echo " -r|--resource-group-name" | ||
[[ -z "${location}" ]] && echo " -l|--location" | ||
[[ -z "${digital_twin_name}" ]] && echo " -d|--digital-twins-name" | ||
echo -e "\n" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
# Check if the Digital Twins instance exists | ||
if az dt show -n "$digital_twin_name" > /dev/null 2>&1; then | ||
echo "Digital Twins instance '$digital_twin_name' already exists in resource group '$resource_group'" | ||
else | ||
echo -e "\nCreating the Azure Digital Twins resource" | ||
az dt create --dt-name "$digital_twin_name" --resource-group "$resource_group" --location "$location" | ||
fi | ||
|
||
# Assign the Digital Twins Data Owner role | ||
echo -e "\nAssigning the Azure Digital Twins Data Owner role" | ||
user_object_id=$(az ad signed-in-user show --query id -o tsv) | ||
az dt role-assignment create --dt-name "$digital_twin_name" --assignee "$user_object_id" --role "Azure Digital Twins Data Owner" | ||
|
||
# Upload the sample-dtdl models | ||
echo -e "\nUploading sample-dtdl models" | ||
for file in $(find ../sample-dtdl -name "trailer.json"); do | ||
if ! az dt model create --dt-name ${digital_twin_name} --models $file; then | ||
echo "$file" dtdl already uploaded. | ||
fi | ||
done | ||
|
||
# Create the Azure Digital Twin instances | ||
echo -e "\nCreating the Azure Digital Twin instances" | ||
az dt twin create --dt-name "$digital_twin_name" --dtmi "dtmi:sdv:Cloud:Trailer;1" --twin-id trailer | ||
|
||
echo -e "\nSetup finished for Freyja's Sample Azure Digital Twins" | ||
exit 0 |