diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-04-09 15:38:07 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-04-09 15:38:07 +0300 |
commit | 0e61b9d24e4a43e93499d1795fc1d99a19f8ac90 (patch) | |
tree | d37dd1354b8c0cf8fa4da83a78b219687c5ff31f | |
download | scripts-0e61b9d24e4a43e93499d1795fc1d99a19f8ac90.tar.gz scripts-0e61b9d24e4a43e93499d1795fc1d99a19f8ac90.tar.bz2 |
Initial commit
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | copy-tags | 107 | ||||
-rwxr-xr-x | volexpand | 150 |
3 files changed, 259 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7407993 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.emacs* +*~ diff --git a/copy-tags b/copy-tags new file mode 100755 index 0000000..433b4b4 --- /dev/null +++ b/copy-tags @@ -0,0 +1,107 @@ +#! /bin/sh + +help() { + cat <<EOT +usage: $0 [OPTIONS] SRC DST +copies tags between from EC2 object SRC to DST + +OPTIONS are: + -O, --access-key=STRING set access key to use + -W, --secret-key=STRING set secret key to use + -a, --access-file=NAME set access file + -c, --config-file=FILE use FILE instead of the default configuration + --region=NAME set AWS region (availability zone) + --ssl use SSL (HTTPS) connection + -M, --map=MAPNAME use this map instead of the default one (implies + --translate) + -x, --translate translate resource IDs + + -h, --help display this help summary + +When using -x, use these options to select appropriate map: + -a SRC and DST are AMIs + -i SRC and DST are instances + -s SRC and DST are snapshots + -v SRC and DST are volumes + +Alternatively, both SRC and DST may be specified using the following +notation: + -r, --resource-id=MAP:ID +where ID is the resource identifier and MAP specifies the map to use +for translation. +EOT +} + +obj= +ECLAT_OPTIONS= +while [ $# -ne 0 ] +do + case $1 in + ECLAT_OPTIONS=*) + eval $1 + shift + ;; + -[aisv]) + obj=$1; shift;; + -h|--help) + help;; + -[MOWac]*) + opt=$(expr "$1" : '-\(.\).*') + arg=$(expr "$1" : '-.\(.*\)') + if [ -z "$arg" ]; then + shift + if [ $# -eq 0 ]; then + echo >&2 "$0: option -$opt requres argument" + exit 1 + fi + ECLAT_OPTIONS="$ECLAT_OPTIONS -$opt$1" + else + ECLAT_OPTIONS="$ECLAT_OPTIONS $1" + fi + shift + ;; + -x|-n|--dry-run|--access-key=*|--secret-key=*|--access-file=*|--config-file=*|--region=*|--ssl|--map=*) + ECLAT_OPTIONS="$ECLAT_OPTIONS $1" + shift + ;; + -r*|--resource-id=*) + break;; + --) shift; break;; + -*) echo >&2 "$0: unrecognized option $1" + exit 1 + ;; + *) break;; + esac +done + +if [ $# != 2 ]; then + help + exit 1 +fi + +case $1 in +-r*|--resource-id*) + case $2 in + -r*|--resource-id*) + if [ -n "$obj" ]; then + echo >&2 "$0: conflicting object types: $obj and $1" + exit 1 + fi + ;; + *) echo >&2 "$0: either none or both arguments must have -r prefix" + exit 1 + ;; + esac + ;; +esac + +export ECLAT_OPTIONS + +eclat -e 'if (.DescribeTagsResponse) + for (var in .DescribeTagsResponse.tagSet.item) + print(var.key,"=",var.value,"\n");' \ + describe-tags $obj $1 | + eclat create-tags $obj $2 -T - + +# EOF + diff --git a/volexpand b/volexpand new file mode 100755 index 0000000..fff6686 --- /dev/null +++ b/volexpand @@ -0,0 +1,150 @@ +#! /bin/sh +# Expand EC2 volume +# Copyright (C) 2012, 2013 Sergey Poznyakoff +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with This Program. If not, see <http://www.gnu.org/licenses/>. + +eclat_opts=-Y + +help() { + cat <<EOT +usage: $0 [OPTIONS] VOLUME SIZE +OPTIONS are: + + -O STRING set access key to use + -x translate resource IDs + -M MAP use this map instead of the default one (implies -x) + -d CAT[.LEVEL] set debugging level + -r REGION set AWS region (availability zone) + +EOT + exit 0 +} + +# runeclat ARGS FORMAT CMD ARGS... +runeclat() { + local v vars fmt + vars="$1" + shift + fmt="$1"'else if (.Response.Errors) { + error("Error: ",.Response.Errors.Error.Message,"\n"); + exit(1); + } else { + error("Unrecognized response:\n"); + dump(.); + exit(1); + }' + shift + ret=$(eclat $eclat_opts --format-expr "$fmt" $*) + if [ $? -ne 0 ]; then + echo >&2 "$0: eclat $1 failed" + exit 1 + fi + set -- $ret + for v in $vars + do + eval $v=\$1 + shift + done + REST=$* +} + +while getopts "M:O:hx" OPTION +do + case $OPTION in + d|M|O) eclat_opts="$eclat_opts -$OPTION$OPTARG";; + r) eclat_opts="$eclat_opts --region=$OPTARG";; + x) eclat_opts="$eclat_opts $OPTION";; + h) help;; + esac +done + +shift $(($OPTIND - 1)) + +if [ $# -ne 2 ]; then + echo 2>&1 "$0: bad number of arguments" + exit 1 +fi + +VOL=$1 +SIZE=$2 + +runeclat "vsize vstat ZONE" ' + if (.DescribeVolumesResponse.volumeSet.item) { + let var = last; + print(var.size,"\t",var.status,"\t",var.availabilityZone,"\n"); + }' describe-volumes $VOL + +if [ $vstat != "available" ]; then + echo >&2 "$0: volume $VOL has status \"$vstat\"" + echo >&2 "$0: operation aborted" + exit 2 +fi + +if [ $SIZE -le $vsize ]; then + echo >&2 "$0: requested size ($SIZE) is less than or equal to the current volume size ($vsize)" + echo >&2 "$0: operation aborted" + exit 2 +fi + +echo "creating snapshot from $VOL" + +runeclat "SNAP STAT P100" ' + if (.CreateSnapshotResponse) { + let resp = .CreateSnapshotResponse; + print(resp.snapshotId,"\t",resp.status,"\t",resp.progress,"\n"); + }' create-snapshot $VOL + +echo "snapshot $SNAP is being created" +prev=$P100 +while [ $STAT != completed ] +do + if [ "$prev" != "$P100" ]; then + echo "$0: $SNAP => $P100%" + fi + prev=$P100 + sleep 10 + runeclat "STAT P100" ' + if (.DescribeSnapshotsResponse.snapshotSet) { + let var=last.item; + print(var.status,"\t",var.progress,"\n"); + }' describe-snapshots $SNAP +done + +echo "snapshot $SNAP is completed" + +runeclat "VOLID STAT" ' + if (.CreateVolumeResponse) { + print(.CreateVolumeResponse.volumeId,"\t", + .CreateVolumeResponse.status,"\n"); + }' create-volume -s $SNAP $SIZE $ZONE + +echo "Creating volume $VOLID" +while [ $STAT = "creating" ] +do + sleep 10 + runeclat "STAT" ' + if (.DescribeVolumesResponse.volumeSet.item) { + print(last.status,"\n"); + }' describe-volumes $VOLID +done +echo "$VOLID: $STAT, snapshot $SNAP" +if [ $STAT != available ]; then + echo >&2 "$0: Created volume $VOLID has unexpected status $STAT" + exit 2 +fi + + + + |