blob: 8ae002604af9dca08bdb1602813de7ddab199391 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/usr/bin/python
# Copyright (C) 2011 Gluster, Inc. <http://www.gluster.com>
# This file is part of Gluster Storage Platform.
#
import os
import sys
p1 = os.path.abspath(os.path.dirname(sys.argv[0]))
p2 = "%s/common" % os.path.dirname(p1)
if not p1 in sys.path:
sys.path.append(p1)
if not p2 in sys.path:
sys.path.append(p2)
import Globals
import Utils
import DiskUtils
from optparse import OptionParser
def main():
if Utils.runCommand("wget -t 1 -T 1 -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()
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(2)
if os.path.exists(deviceFormatStatusFile):
Utils.log("format status file %s exists" % deviceFormatStatusFile)
line = Utils.readFile(deviceFormatStatusFile)
if not line:
sys.stderr.write("failed to read format status file %s\n" % deviceFormatStatusFile)
sys.exit(-2)
if line.strip().upper() == "COMPLETED":
sys.stderr.write("Device already formatted\n")
sys.exit(3)
else:
sys.stderr.write("Device format already running\n")
sys.exit(4)
if os.path.exists(deviceFormatLockFile):
Utils.log("lock file %s exists" % deviceFormatLockFile)
sys.stderr.write("Device format already running\n")
sys.exit(5)
if options.fstype:
command = ["%s/gluster_provision_block_wrapper.py" % p1, "-t", "%s" % (options.fstype), "%s" % (device)]
else:
command = ["%s/gluster_provision_block_wrapper.py" % p1, "%s" % (device)]
try:
pid = os.fork()
except OSError, e:
Utils.log("failed to fork a child process: %s" % str(e))
sys.exit(6)
if pid == 0:
os.execv(command[0], command)
sys.exit(0)
if __name__ == "__main__":
main()
|