summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTim <timothyasir@gluster.com>2011-07-07 14:23:48 +0530
committerTim <timothyasir@gluster.com>2011-07-07 14:28:32 +0530
commit218132d9514d45312224d1996dce16f2d3722009 (patch)
treeb223a5cf33f87065ca040d5d6bce03d5d2a51088 /src
parent3c8399353ca5f81bfb08579a7b5856c3740a6c76 (diff)
parent5eabbd68b7036ef452847649f25af5f1e26e69db (diff)
Added format_device.py get_format_device_status.py gluster_provision_block_wrapper.py files
Merge branch 'master' of github.com:TimothyAsir/console
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com.gluster.storage.management.server.scripts/src/format_device.py78
-rwxr-xr-xsrc/com.gluster.storage.management.server.scripts/src/get_format_device_status.py119
-rwxr-xr-xsrc/com.gluster.storage.management.server.scripts/src/gluster_provision_block_wrapper.py120
3 files changed, 317 insertions, 0 deletions
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
new file mode 100755
index 00000000..80334d8a
--- /dev/null
+++ b/src/com.gluster.storage.management.server.scripts/src/format_device.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+# Copyright (C) 2010 Gluster, Inc. <http://www.gluster.com>
+# This file is part of Gluster Storage Platform.
+#
+# Gluster Storage Platform 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 of
+# the License, or (at your option) any later version.
+#
+# Gluster Storage Platform 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/>.
+
+import os
+import sys
+import Utils
+import DiskUtils
+from optparse import OptionParser
+
+
+def main():
+ parser = OptionParser()
+ parser.add_option("-t", "--type", action="store", type="string", dest="fstype")
+ (options, args) = parser.parse_args()
+
+ if len(args) != 1:
+ sys.stderr.write("usage: %s [-t FSTYPE] DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
+ sys.exit(-1)
+
+ device = DiskUtils.getDevice(args[0])
+ deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
+ deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
+ deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)
+
+ if DiskUtils.isDataDiskPartitionFormatted(device):
+ sys.stderr.write("Device already formatted\n")
+ sys.exit(1)
+
+ if os.path.exists(deviceFormatStatusFile):
+ Utils.log("format status file %s exists" % deviceFormatStatusFile)
+ try:
+ fp = open(deviceFormatStatusFile)
+ line = fp.read()
+ fp.close()
+ if line.strip().upper() == "COMPLETED":
+ sys.stderr.write("Device already formatted\n")
+ sys.exit(1)
+ else:
+ sys.stderr.write("Device format already running\n")
+ sys.exit(2)
+ except IOError, e:
+ Utils.log("failed to read format status file %s: %s" % (deviceFormatStatusFile, str(e)))
+ sys.stderr.write("%s\n" % str(e))
+ sys.exit(-2)
+
+ if os.path.exists(deviceFormatLockFile):
+ Utils.log("lock file %s exists" % deviceFormatLockFile)
+ sys.stderr.write("Device format already running\n")
+ sys.exit(2)
+
+ if options.fstype:
+ process = Utils.runCommandBG("gluster_provision_block_wrapper.py -t %s %s" % (options.fstype, device), root=True)
+ else:
+ process = Utils.runCommandBG("gluster_provision_block_wrapper.py %s" % device, root=True)
+ if process:
+ sys.exit(0)
+
+ sys.stderr.write("Device format failed\n")
+ sys.exit(3)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/src/com.gluster.storage.management.server.scripts/src/get_format_device_status.py b/src/com.gluster.storage.management.server.scripts/src/get_format_device_status.py
new file mode 100755
index 00000000..9fe2b231
--- /dev/null
+++ b/src/com.gluster.storage.management.server.scripts/src/get_format_device_status.py
@@ -0,0 +1,119 @@
+#!/usr/bin/python
+# Copyright (C) 2009,2010 Gluster, Inc. <http://www.gluster.com>
+# This file is part of Gluster Storage Platform.
+#
+# Gluster Storage Platform 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 of
+# the License, or (at your option) any later version.
+#
+# Gluster Storage Platform 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/>.
+
+import os
+import sys
+import Utils
+import DiskUtils
+from XmlHandler import ResponseXml
+
+def main():
+ if len(sys.argv) != 2:
+ sys.stderr.write("usage: %s DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
+ sys.exit(-1)
+
+ device = DiskUtils.getDevice(sys.argv[1])
+
+ deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
+ deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
+ deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)
+
+ if not os.path.exists(deviceFormatLockFile):
+ if not os.path.exists(deviceFormatStatusFile):
+ sys.stderr.write("Device format not initiated\n")
+ sys.exit(1)
+
+ if os.path.exists(deviceFormatStatusFile):
+ try:
+ fp = open(deviceFormatStatusFile)
+ line = fp.read()
+ fp.close()
+ line = line.strip()
+
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatStatusFile)
+
+ responseDom = ResponseXml()
+ responseDom.appendTagRoute("response.device", sys.argv[1])
+ responseDom.appendTagRoute("response.completedBlocks", "0")
+ responseDom.appendTagRoute("response.totalBlocks", "0")
+ responseDom.appendTagRoute("response.message", line)
+ if line.upper() == "COMPLETED":
+ responseDom.appendTagRoute("response.formatStatus", "COMPLETED")
+ else:
+ responseDom.appendTagRoute("response.formatStatus", "NOT_RUNNING")
+ print responseDom.toxml()
+ sys.exit(0)
+ except IOError, e:
+ Utils.log("failed to read format status file %s: %s" % (deviceFormatStatusFile, str(e)))
+ sys.stderr.write("%s\n" % str(e))
+ sys.exit(-2)
+
+ if not os.path.exists(deviceFormatOutputFile):
+ responseDom = ResponseXml()
+ responseDom.appendTagRoute("response.device", sys.argv[1])
+ responseDom.appendTagRoute("response.completedBlocks", "0")
+ responseDom.appendTagRoute("response.totalBlocks", "0")
+ responseDom.appendTagRoute("response.message", None)
+ responseDom.appendTagRoute("response.formatStatus", "IN_PROGRESS")
+ print responseDom.toxml()
+ sys.exit(0)
+
+ try:
+ fp = open(deviceFormatOutputFile)
+ content = fp.read()
+ fp.close()
+ except IOError, e:
+ Utils.log("failed to read format output file %s: %s" % (deviceFormatOutputFile, str(e)))
+ responseDom = ResponseXml()
+ responseDom.appendTagRoute("response.device", sys.argv[1])
+ responseDom.appendTagRoute("response.completedBlocks", "0")
+ responseDom.appendTagRoute("response.totalBlocks", "0")
+ responseDom.appendTagRoute("response.message", None)
+ responseDom.appendTagRoute("response.formatStatus", "IN_PROGRESS")
+ print responseDom.toxml()
+ sys.exit(0)
+
+ lines = [line for line in content
+ if "Writing inode tables" in line]
+ if not lines:
+ responseDom = ResponseXml()
+ responseDom.appendTagRoute("response.device", sys.argv[1])
+ responseDom.appendTagRoute("response.completedBlocks", "0")
+ responseDom.appendTagRoute("response.totalBlocks", "0")
+ responseDom.appendTagRoute("response.message", content[-1])
+ responseDom.appendTagRoute("response.formatStatus", "IN_PROGRESS")
+ print responseDom.toxml()
+ sys.exit(0)
+
+ tokens = [token for token in lines[-1].split("\x08") if token]
+ if "done" in tokens[-1]:
+ values = tokens[-2].split(':')[-1].strip().split('/')
+ else:
+ values = tokens[-1].split(':')[-1].strip().split('/')
+
+ responseDom.appendTagRoute("response.device", sys.argv[1])
+ responseDom.appendTagRoute("response.completedBlocks", values[0])
+ responseDom.appendTagRoute("response.totalBlocks", values[1])
+ responseDom.appendTagRoute("response.message", lines[-1])
+ responseDom.appendTagRoute("response.formatStatus", "IN_PROGRESS")
+ print responseDom.toxml()
+ sys.exit(0)
+
+if __name__ == "__main__":
+ main()
diff --git a/src/com.gluster.storage.management.server.scripts/src/gluster_provision_block_wrapper.py b/src/com.gluster.storage.management.server.scripts/src/gluster_provision_block_wrapper.py
new file mode 100755
index 00000000..8c47d958
--- /dev/null
+++ b/src/com.gluster.storage.management.server.scripts/src/gluster_provision_block_wrapper.py
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+# Copyright (C) 2010 Gluster, Inc. <http://www.gluster.com>
+# This file is part of Gluster Storage Platform.
+#
+# Gluster Storage Platform 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 of
+# the License, or (at your option) any later version.
+#
+# Gluster Storage Platform 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/>.
+
+import os
+import sys
+#import subprocess
+import Utils
+import DiskUtils
+from optparse import OptionParser
+
+def writeStatus(deviceFormatStatusFile, message):
+ try:
+ fp = open(deviceFormatStatusFile, "w")
+ fp.write(message)
+ fp.close()
+ except IOError, e:
+ Utils.log("Failed to update log file %s: %s" % (deviceFormatStatusFile, str(e)))
+ return False
+ return True
+
+
+def main():
+ parser = OptionParser()
+ parser.add_option("-t", "--type", action="store", type="string", dest="fstype")
+ (options, args) = parser.parse_args()
+
+ if len(args) != 1:
+ sys.stderr.write("usage: %s [-t FSTYPE] DEVICE" % os.path.basename(sys.argv[0]))
+ sys.exit(-1)
+
+ device = args[0]
+ deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
+ deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
+ deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)
+
+ if os.path.exists(deviceFormatStatusFile):
+ Utils.log("device format status file %s exists" % deviceFormatStatusFile)
+ sys.exit(1)
+
+ if os.path.exists(deviceFormatLockFile):
+ Utils.log("device format lock file %s exists" % deviceFormatLockFile)
+ sys.exit(2)
+
+ try:
+ fp = open(deviceFormatLockFile, "w")
+ fp.close()
+ except OSError, e:
+ Utils.log("failed to create lock file %s: %s" % (deviceFormatLockFile, str(e)))
+ writeStatus(deviceFormatStatusFile, "Lock file creation failed\n")
+ sys.exit(3)
+
+ try:
+ fptr = open(deviceFormatOutputFile, 'w')
+ except IOError, e:
+ Utils.log("failed to create output file %s" % deviceFormatOutputFile)
+ writeStatus(deviceFormatStatusFile, "Output file creation failed\n")
+ Utils.removeFile(deviceFormatLockFile)
+ sys.exit(4)
+
+ if options.fstype:
+ command = "gluster-provision-block -t %s %s" % (options.fstype, device)
+ else:
+ command = "gluster-provision-block %s" % (device)
+
+ process = Utils.runCommandBG(command,
+ stdinFileObj=subprocess.PIPE,
+ stdoutFileObj=fptr,
+ stderrFileObj=subprocess.PIPE)
+ if process:
+ status = process.wait()
+ else:
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatLockFile)
+ writeStatus(deviceFormatStatusFile, "Device format failed\n")
+ sys.exit(5)
+
+ ## try:
+ ## process = subprocess.Popen(command,
+ ## stdout=fptr,
+ ## stderr=subprocess.PIPE,
+ ## stdin=subprocess.PIPE,
+ ## close_fds=True)
+ ## status = process.wait()
+ ## except OSError:
+ ## os.unlink(deviceFormatOutputFile)
+ ## Utils.log(syslog.LOG_ERR, "formatting disk command failed. command: %s" % str(command))
+ ## writeStatus(deviceFormatStatusFile, "Formatting disk command failed\n")
+ ## removeLockFile()
+ ## sys.exit(-5)
+
+ if status != 0:
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatLockFile)
+ writeStatus(deviceFormatStatusFile, "Device format failed\n")
+ sys.exit(6)
+
+ if Utils.runCommand("/usr/bin/lshal") != 0:
+ Utils.log("failed running /usr/bin/lshal")
+ writeStatus(deviceFormatStatusFile, "Completed\n")
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatLockFile)
+ sys.exit(0)
+
+if __name__ == "__main__":
+ main()