From 425186f203fe435fef80b5fbb03790de131bf88d Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 27 Jul 2011 12:33:26 +0530 Subject: Updated format_device.py to throw exception while trying format device in AMI instance. --- .../src/Globals.py | 2 ++ .../src/format_device.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/com.gluster.storage.management.server.scripts/src/Globals.py b/src/com.gluster.storage.management.server.scripts/src/Globals.py index 877c6c68..5c1c4bee 100644 --- a/src/com.gluster.storage.management.server.scripts/src/Globals.py +++ b/src/com.gluster.storage.management.server.scripts/src/Globals.py @@ -118,3 +118,5 @@ DOWNLOAD_GLUSTER_UPDATE_MD5SUM = None REQUEST_MAP = {} VERSION_DICTONARY = {} ## + +AWS_WEB_SERVICE_URL = "http://169.254.169.254/latest" diff --git a/src/com.gluster.storage.management.server.scripts/src/format_device.py b/src/com.gluster.storage.management.server.scripts/src/format_device.py index 061236e0..3bc70532 100755 --- a/src/com.gluster.storage.management.server.scripts/src/format_device.py +++ b/src/com.gluster.storage.management.server.scripts/src/format_device.py @@ -18,12 +18,17 @@ import os import sys +import Globals import Utils import DiskUtils from optparse import OptionParser def main(): + if Utils.runCommand("wget -q -O /dev/null %s" % Globals.AWS_WEB_SERVICE_URL) == 0: + sys.stderr.write("format device unsupported") + sys.exit(1) + parser = OptionParser() parser.add_option("-t", "--type", action="store", type="string", dest="fstype") (options, args) = parser.parse_args() @@ -39,7 +44,7 @@ def main(): if DiskUtils.isDataDiskPartitionFormatted(device): sys.stderr.write("Device already formatted\n") - sys.exit(1) + sys.exit(2) if os.path.exists(deviceFormatStatusFile): Utils.log("format status file %s exists" % deviceFormatStatusFile) @@ -49,10 +54,10 @@ def main(): fp.close() if line.strip().upper() == "COMPLETED": sys.stderr.write("Device already formatted\n") - sys.exit(1) + sys.exit(3) else: sys.stderr.write("Device format already running\n") - sys.exit(2) + sys.exit(4) except IOError, e: Utils.log("failed to read format status file %s: %s" % (deviceFormatStatusFile, str(e))) sys.stderr.write("%s\n" % str(e)) @@ -61,7 +66,7 @@ def main(): if os.path.exists(deviceFormatLockFile): Utils.log("lock file %s exists" % deviceFormatLockFile) sys.stderr.write("Device format already running\n") - sys.exit(2) + sys.exit(5) if options.fstype: command = ["gluster_provision_block_wrapper.py", "-t", "%s" % (options.fstype), "%s" % (device)] @@ -72,7 +77,7 @@ def main(): pid = os.fork() except OSError, e: Utils.log("failed to fork a child process: %s" % str(e)) - sys.exit(1) + sys.exit(6) if pid == 0: os.execv("/usr/sbin/gluster_provision_block_wrapper.py", command) sys.exit(0) -- cgit