From 08f2d4cd2307f68b9a3413b8b570d8cc047218dc Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Mon, 9 Feb 2015 17:58:16 -0800 Subject: [PATCH] oem/azure: add replicate-image.sh --- oem/azure/common.sh | 17 +++++++++++ oem/azure/replicate-image.sh | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 oem/azure/replicate-image.sh diff --git a/oem/azure/common.sh b/oem/azure/common.sh index 08bd72d2e4..c388985fa2 100644 --- a/oem/azure/common.sh +++ b/oem/azure/common.sh @@ -1,4 +1,21 @@ AZURE_ENVIRONMENT=AzureCloud +REGIONS=( + "West Europe" + "North Europe" + "East Asia" + "Southeast Asia" + "East US" + "West US" + "Japan East" + "Japan West" + "Central US" + "East US 2" + "Brazil South" + "North Central US" + "South Central US" + "Australia East" + "Australia Southeast" +) getManagementEndpoint() { azure account env show --environment=$AZURE_ENVIRONMENT --json | \ diff --git a/oem/azure/replicate-image.sh b/oem/azure/replicate-image.sh new file mode 100755 index 0000000000..e0ced6c774 --- /dev/null +++ b/oem/azure/replicate-image.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# This script will replicate the given image into all Azure regions. It needs +# to be run in an environment where the azure-xplat-cli has been installed and +# configured with the production credentials and (optionally) SUBSCRIPTION_ID +# is defined, containing the subscription GUID. + +DIR=$(dirname $0) +. $DIR/common.sh + +set -e + +GROUP="${1^}" +VERSION=$2 + +if [[ -z $GROUP || -z $VERSION ]]; then + echo "Usage: $0 " + exit 2 +fi + +image_name="CoreOS-${GROUP}-${VERSION}" + +subscription_id=$SUBSCRIPTION_ID +if [ -z $subscription_id ]; then + subscription_id=$(getSubscriptionId) +fi + +requestBody="\n\t\n" +for region in "${REGIONS[@]}"; do + requestBody+="\t\t$region\n" +done +requestBody+="\t\n" + +url="$(getManagementEndpoint)/${subscription_id}/services/images/${image_name}/replicate" + +workdir=$(mktemp --directory) +trap "rm --force --recursive ${workdir}" SIGINT SIGTERM EXIT + +azure account cert export \ + --file="${workdir}/cert" \ + --subscription="${subscription_id}" > /dev/null + +result=$(echo -e "${requestBody}" | curl \ + --silent \ + --request PUT \ + --header "x-ms-version: 2014-10-01" \ + --header "Content-Type: application/xml" \ + --cert "${workdir}/cert" \ + --url "${url}" \ + --write-out "%{http_code}" \ + --output "${workdir}/out" \ + --data-binary @-) + +if [[ $result != 200 ]]; then + echo "${result} - $(< ${workdir}/out)" + exit 1 +fi