summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py
diff options
context:
space:
mode:
authorShireesh Anjal <anjalshireesh@gmail.com>2011-09-23 04:56:48 -0700
committerShireesh Anjal <anjalshireesh@gmail.com>2011-09-23 04:56:48 -0700
commitb6b83d20cbd1701cf9ad82a1cae00dcfb077738a (patch)
treea3e13e98bbda5288445cc23f495c846cb1a71879 /src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py
parentb8ebf1e37b12fc8e147ddcb7b8c151e6048cf0e9 (diff)
parent7ab7bab50b36dd883662fbd009cd18780b4397a3 (diff)
Merge pull request #282 from TimothyAsir/master
Cleanup and bug fixes
Diffstat (limited to 'src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py')
-rw-r--r--src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py213
1 files changed, 4 insertions, 209 deletions
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py b/src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py
index 5d7b0b4a..4d1b701a 100644
--- a/src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/backend/DiskUtils.py
@@ -12,18 +12,10 @@ if not p1 in sys.path:
if not p2 in sys.path:
sys.path.append(p2)
import glob
-from copy import deepcopy
-import dbus
import Globals
-import time
import Utils
-import Disk
-import Protocol
import FsTabUtils
-ONE_MB_SIZE = 1048576
-
-
def _stripDev(device):
if Utils.isString(device) and device.startswith("/dev/"):
return device[5:]
@@ -70,11 +62,6 @@ def getUuidByDiskPartition(device):
return None
-def getDiskPartitionUuid(partition):
- Utils.log("WARNING: getDiskPartitionUuid() is deprecated by getUuidByDiskPartition()")
- return getUuidByDiskPartition(partition)
-
-
def getDiskPartitionByLabel(label):
## TODO: Finding needs to be enhanced
labelFile = "/dev/disk/by-label/%s" % label
@@ -84,11 +71,6 @@ def getDiskPartitionByLabel(label):
return None
-def getDeviceByLabel(label):
- Utils.log("WARNING: getDeviceByLabel() is deprecated by getDiskPartitionByLabel()")
- return getDiskPartitionByLabel(label)
-
-
def getDiskPartitionLabel(device):
rv = Utils.runCommand("e2label %s" % device, output=True, root=True)
if rv["Status"] == 0:
@@ -96,78 +78,6 @@ def getDiskPartitionLabel(device):
return False
-def getRootPartition(fsTabFile=Globals.FSTAB_FILE):
- fsTabEntryList = FsTabUtils.readFsTab(fsTabFile)
- for fsTabEntry in fsTabEntryList:
- if fsTabEntry["MountPoint"] == "/":
- if fsTabEntry["Device"].startswith("UUID="):
- return getDiskPartitionByUuid(fsTabEntry["Device"].split("UUID=")[-1])
- if fsTabEntry["Device"].startswith("LABEL="):
- partitionName = getDiskPartitionByLabel(fsTabEntry["Device"].split("LABEL=")[-1])
- if partitionName:
- return partitionName
- return getDeviceName(fsTabEntry["Device"])
- return None
-
-def getRaidDisk():
- array = []
- arrayList = []
- mdFound = False
-
- try:
- fp = open("/proc/mdstat")
- for line in fp:
- str = line.strip()
- if str.startswith("md"):
- array.append(str)
- mdFound = True
- continue
- if mdFound:
- if str:
- array.append(str)
- else:
- arrayList.append(array)
- array = []
- mdFound = False
- fp.close()
- except IOError, e:
- return None
-
- raidList = {}
- for array in arrayList:
- raid = {}
- tokens = array[0].split()
- raid['Interface'] = tokens[3]
- device = getDevice(tokens[0])
- raid['MountPoint'] = getDeviceMountPoint(device)
- if raid['MountPoint']:
- raid['Type'] = "DATA"
- raid['SpaceInUse'] = getDeviceUsedSpace(device)
- else:
- raid['SpaceInUse'] = None
- rv = Utils.runCommand("blkid -c /dev/null %s" % (device), output=True, root=True)
- raid['Uuid'] = None
- raid['FsType'] = None
- raid['Status'] = "UNINITIALIZED"
- if isDiskInFormatting(device):
- raid['Status'] = "INITIALIZING"
- if not rv["Stderr"]:
- words = rv["Stdout"].strip().split()
- if words:
- raid['Status'] = "INITIALIZED"
- if len(words) > 2:
- raid['Uuid'] = words[1].split("UUID=")[-1].split('"')[1]
- raid['FsType'] = words[2].split("TYPE=")[-1].split('"')[1]
- raid['Disks'] = [x.split('[')[0] for x in tokens[4:]]
- raid['Size'] = float(array[1].split()[0]) / 1024.0
- raidList[tokens[0]] = raid
- return raidList
-
-
-def getOsDisk():
- Utils.log("WARNING: getOsDisk() is deprecated by getRootPartition()")
- return getRootPartition()
-
def getDiskInfo(diskNameList=None):
procPartitionsDict = getProcPartitions()
diskDict = {}
@@ -239,127 +149,17 @@ def getDiskInfo(diskNameList=None):
return outputDict
-def getDiskList(diskDeviceList=None):
- return diskInfo["disks"]
-
-
-def checkDiskMountPoint(diskMountPoint):
- try:
- fstabEntries = open(Globals.FSTAB_FILE).readlines()
- except IOError, e:
- fstabEntries = []
- Utils.log("failed to read file %s: %s" % (Globals.FSTAB_FILE, str(e)))
- found = False
- for entry in fstabEntries:
- entry = entry.strip()
- if not entry:
- continue
- entries = entry.split()
- if entries and len(entries) > 1 and entries[0].startswith("UUID=") and entries[1].upper() == diskMountPoint.upper():
- return True
- return False
-
-
-def getMountPointByUuid(partitionUuid):
- # check uuid in etc/fstab
- try:
- fstabEntries = open(Globals.FSTAB_FILE).readlines()
- except IOError, e:
- fstabEntries = []
- Utils.log("failed to read file %s: %s" % (Globals.FSTAB_FILE, str(e)))
- found = False
- for entry in fstabEntries:
- entry = entry.strip()
- if not entry:
- continue
- if entry.split()[0] == "UUID=" + partitionUuid:
- return entry.split()[1]
- return None
-
-def getDeviceUsedSpace(device):
- rv = Utils.runCommand("df -kl %s" % (device), output=True, root=True)
- if rv["Status"] == 0:
- try:
- return long(rv["Stdout"].split("\n")[1].split()[2]) / 1024
- except IndexError, e:
- pass
- except ValueError, e:
- pass
-
-def getDiskSizeInfo(partition):
- # get values from df output
- total = None
- used = None
- free = None
- command = "df -kl -t ext3 -t ext4 -t xfs"
- rv = Utils.runCommand(command, output=True, root=True)
- message = Utils.stripEmptyLines(rv["Stdout"])
- if rv["Status"] != 0:
- Utils.log("failed to get disk partition details")
- return None, None, None
- for line in rv["Stdout"].split("\n"):
- tokens = line.split()
- if len(tokens) < 4:
- continue
- if tokens[0] == partition:
- total = int(tokens[1]) / 1024.0
- used = int(tokens[2]) / 1024.0
- free = int(tokens[3]) / 1024.0
- break
-
- if total:
- return total, used, free
-
- # get total size from parted output
- for i in range(len(partition), 0, -1):
- pos = i - 1
- if not partition[pos].isdigit():
- break
- disk = partition[:pos+1]
- partitionNumber = partition[pos+1:]
- if not partitionNumber.isdigit():
- return None, None, None
-
- number = int(partitionNumber)
- command = "parted -ms %s unit kb print" % disk
- rv = Utils.runCommand(command, output=True, root=True)
- if rv["Status"] != 0:
- Utils.log("failed to get disk partition details")
- return None, None, None
-
- lines = rv["Stdout"].split(";\n")
- if len(lines) < 3:
- return None,None,None
-
- for line in lines[2:]:
- tokens = line.split(':')
- if len(tokens) < 4:
- continue
- if tokens[0] == str(number):
- total = int(tokens[3].split('kB')[0]) / 1024.0
- break
- return total, used, free
-
-
def isDataDiskPartitionFormatted(device):
- #if getDiskPartitionLabel(device) != Globals.DATA_PARTITION_LABEL:
- # return False
- device = getDeviceName(device)
- diskObj = Disk.Disk()
- for disk in diskObj.getMountableDiskList():
- if disk['device'].upper() == device.upper():
- mountPoint = disk['mount_point']
- if not mountPoint:
- return False
- if not os.path.exists(mountPoint):
- return False
+ rv = Utils.runCommand("blkid -c /dev/null -o value %s" % device, output=True, root=True)
+ if rv["Status"] != 0:
+ return False
uuid = getUuidByDiskPartition(device)
if not uuid:
return False
for fsTabEntry in FsTabUtils.readFsTab():
- if fsTabEntry["Device"] == ("UUID=%s" % uuid) and fsTabEntry["MountPoint"] == mountPoint:
+ if fsTabEntry["Device"] == ("UUID=%s" % uuid) or fsTabEntry["Device"] == device:
return True
return False
@@ -369,11 +169,6 @@ def isDiskInFormatting(device):
return os.path.exists(DEVICE_FORMAT_LOCK_FILE)
-def isDiskInFormat(device):
- Utils.log("WARNING: isDiskInFormat() is deprecated by isDataDiskPartitionFormatted()")
- return isDataDiskPartitionFormatted(device)
-
-
def getDeviceMountPoint(device):
lines = Utils.readFile("/proc/mounts", lines=True)
uuid = getUuidByDiskPartition(device)