summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.server.scripts/src/DiskUtils.py152
-rw-r--r--src/com.gluster.storage.management.server.scripts/src/FsTabUtils.py92
-rw-r--r--src/com.gluster.storage.management.server.scripts/src/RRDUtils.py72
-rwxr-xr-xsrc/com.gluster.storage.management.server.scripts/src/get_server_details.py41
4 files changed, 299 insertions, 58 deletions
diff --git a/src/com.gluster.storage.management.server.scripts/src/DiskUtils.py b/src/com.gluster.storage.management.server.scripts/src/DiskUtils.py
index 03c5019e..8571a807 100644
--- a/src/com.gluster.storage.management.server.scripts/src/DiskUtils.py
+++ b/src/com.gluster.storage.management.server.scripts/src/DiskUtils.py
@@ -21,19 +21,22 @@ import dbus
import syslog
import Globals
import Common
+import time
import Utils
+import Disk
+import Protocol
ONE_MB_SIZE = 1048576
def _stripDev(device):
- if isString(device) and device.startswith("/dev/"):
+ if Utils.isString(device) and device.startswith("/dev/"):
return device[5:]
return device
def _addDev(deviceName):
- if isString(deviceName) and not deviceName.startswith("/dev/"):
+ if Utils.isString(deviceName) and not deviceName.startswith("/dev/"):
return "/dev/" + deviceName
return deviceName
@@ -48,7 +51,7 @@ def getDeviceName(device):
def getDevice(deviceName):
- if isString(deviceName):
+ if Utils.isString(deviceName):
return _addDev(deviceName)
if type(deviceName) == type([]):
nameList = []
@@ -73,7 +76,7 @@ def getUuidByDiskPartition(device):
def getDiskPartitionUuid(partition):
- log("WARNING: getDiskPartitionUuid() is deprecated by getUuidByDiskPartition()")
+ Utils.log("WARNING: getDiskPartitionUuid() is deprecated by getUuidByDiskPartition()")
return getUuidByDiskPartition(partition)
@@ -81,17 +84,18 @@ def getDiskPartitionByLabel(label):
## TODO: Finding needs to be enhanced
labelFile = "/dev/disk/by-label/%s" % label
if os.path.exists(labelFile):
- return getDeviceName(os.path.realpath(labelFile))
+ if os.path.islink(labelFile):
+ return getDeviceName(os.path.realpath(labelFile))
return None
def getDeviceByLabel(label):
- log("WARNING: getDeviceByLabel() is deprecated by getDiskPartitionByLabel()")
+ Utils.log("WARNING: getDeviceByLabel() is deprecated by getDiskPartitionByLabel()")
return getDiskPartitionByLabel(label)
def getDiskPartitionLabel(device):
- rv = runCommandFG(["sudo", "e2label", device], stdout=True)
+ rv = Utils.runCommandFG(["sudo", "e2label", device], stdout=True)
if rv["Status"] == 0:
return rv["Stdout"].strip()
return False
@@ -104,19 +108,21 @@ def getRootPartition(fsTabFile=Globals.FSTAB_FILE):
if fsTabEntry["Device"].startswith("UUID="):
return getDiskPartitionByUuid(fsTabEntry["Device"].split("UUID=")[-1])
if fsTabEntry["Device"].startswith("LABEL="):
- return getDiskPartitionByLabel(fsTabEntry["Device"].split("LABEL=")[-1])
+ partitionName = getDiskPartitionByLabel(fsTabEntry["Device"].split("LABEL=")[-1])
+ if partitionName:
+ return partitionName
return getDeviceName(fsTabEntry["Device"])
return None
def getOsDisk():
- log("WARNING: getOsDisk() is deprecated by getRootPartition()")
+ Utils.log("WARNING: getOsDisk() is deprecated by getRootPartition()")
return getRootPartition()
-def getDiskList(diskDeviceList=None):
+def getDiskInfo(diskDeviceList=None):
diskDeviceList = getDevice(diskDeviceList)
- if isString(diskDeviceList):
+ if Utils.isString(diskDeviceList):
diskDeviceList = [diskDeviceList]
dbusSystemBus = dbus.SystemBus()
@@ -125,12 +131,15 @@ def getDiskList(diskDeviceList=None):
halManager = dbus.Interface(halObj, "org.freedesktop.Hal.Manager")
storageUdiList = halManager.FindDeviceByCapability("storage")
+ diskInfo = {}
diskList = []
+ totalDiskSpace = 0
+ totalDiskUsage = 0
for udi in storageUdiList:
halDeviceObj = dbusSystemBus.get_object("org.freedesktop.Hal", udi)
halDevice = dbus.Interface(halDeviceObj,
"org.freedesktop.Hal.Device")
- if halDevice.GetProperty("storage.drive_type") == "cdrom" or \
+ if halDevice.GetProperty("storage.drive_type") in ["cdrom", "floppy"] or \
halDevice.GetProperty("block.is_volume"):
continue
@@ -142,11 +151,12 @@ def getDiskList(diskDeviceList=None):
if halDevice.GetProperty('storage.removable'):
disk["Size"] = long(halDevice.GetProperty('storage.removable.media_size'))
else:
- disk["Size"] = long(halDevice.GetProperty('storage.size'))
+ disk["Size"] = long(halDevice.GetProperty('storage.size')) / 1024**2
disk["Interface"] = str(halDevice.GetProperty('storage.bus'))
disk["DriveType"] = str(halDevice.GetProperty('storage.drive_type'))
partitionList = []
partitionUdiList = halManager.FindDeviceStringMatch("info.parent", udi)
+ diskSpaceInUse = 0
for partitionUdi in partitionUdiList:
partitionHalDeviceObj = dbusSystemBus.get_object("org.freedesktop.Hal",
partitionUdi)
@@ -157,24 +167,36 @@ def getDiskList(diskDeviceList=None):
partition = {}
partition["Device"] = str(partitionHalDevice.GetProperty('block.device'))
partition["Uuid"] = str(partitionHalDevice.GetProperty('volume.uuid'))
- partition["Size"] = long(partitionHalDevice.GetProperty('volume.size'))
+ partition["Size"] = long(partitionHalDevice.GetProperty('volume.size')) / 1024**2
partition["Fstype"] = str(partitionHalDevice.GetProperty('volume.fstype'))
partition["Fsversion"] = str(partitionHalDevice.GetProperty('volume.fsversion'))
partition["Label"] = str(partitionHalDevice.GetProperty('volume.label'))
+ partition["mountPoint"] = str(partitionHalDevice.GetProperty('volume.mount_point'))
+ partition["readOnlyAccess"] = str(partitionHalDevice.GetProperty('volume.is_mounted_read_only'))
partition["Used"] = 0L
if partitionHalDevice.GetProperty("volume.is_mounted"):
- rv = runCommandFG(["df", str(partitionHalDevice.GetProperty('volume.mount_point'))], stdout=True)
+ rv = Utils.runCommandFG(["df", str(partitionHalDevice.GetProperty('volume.mount_point'))], stdout=True)
if rv["Status"] == 0:
try:
- partition["Used"] = long(rv["Stdout"].split("\n")[1].split()[2])
+ partition["Used"] = long(rv["Stdout"].split("\n")[1].split()[2]) / 1024
+ diskSpaceInUse += partition["Used"]
except IndexError:
pass
except ValueError:
pass
partitionList.append(partition)
disk["Partitions"] = partitionList
+ disk["Used"] = diskSpaceInUse
+ totalDiskSpace += disk["Size"]
+ totalDiskUsage += disk["Used"]
diskList.append(disk)
- return diskList
+ diskInfo["disks"] = diskList
+ diskInfo["totalDiskSpace"] = totalDiskSpace
+ diskInfo["diskSpaceInUse"] = totalDiskUsage
+ return diskInfo
+
+def getDiskList(diskDeviceList=None):
+ return diskInfo["disks"]
def readFsTab(fsTabFile=Globals.FSTAB_FILE):
try:
@@ -252,7 +274,7 @@ def getDiskSizeInfo(partition):
rv = Utils.runCommandFG(command, stdout=True, root=True)
message = Common.stripEmptyLines(rv["Stdout"])
if rv["Stderr"]:
- Common.log(syslog.LOG_ERR, "failed to get disk details. %s" % Common.stripEmptyLines(rv["Stdout"]))
+ Common.Utils.log(syslog.LOG_ERR, "failed to get disk details. %s" % Common.stripEmptyLines(rv["Stdout"]))
return None, None, None
for line in rv["Stdout"].split("\n"):
tokens = line.split()
@@ -282,7 +304,7 @@ def getDiskSizeInfo(partition):
rv = Utils.runCommandFG(command, stdout=True, root=True)
message = Common.stripEmptyLines(rv["Stdout"])
if rv["Stderr"]:
- Common.log(syslog.LOG_ERR, "failed to get disk details. %s" % Common.stripEmptyLines(rv["Stdout"]))
+ Common.Utils.log(syslog.LOG_ERR, "failed to get disk details. %s" % Common.stripEmptyLines(rv["Stdout"]))
return None, None, None
lines = rv["Stdout"].split(";\n")
@@ -303,6 +325,96 @@ def refreshHal():
rv = Utils.runCommandFG(["lshal"], stdout=True, root=True)
if rv["Stderr"]:
error = Common.stripEmptyLines(rv["Stderr"])
- Common.log(syslog.LOG_ERR, "failed to execute lshal command. Error: %s" % error)
+ Common.Utils.log(syslog.LOG_ERR, "failed to execute lshal command. Error: %s" % error)
return False
return True
+
+
+def isDataDiskPartitionFormatted(device):
+ #Todo: Proper label needs to be added for data partition
+ #if getDiskPartitionLabel(device) != Globals.DATA_PARTITION_LABEL:
+ # return False
+
+ 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
+
+ uuid = getUuidByDiskPartition(device)
+ if not uuid:
+ return False
+
+ for fsTabEntry in readFsTab():
+ if fsTabEntry["Device"] == ("UUID=%s" % uuid) and fsTabEntry["MountPoint"] == mountPoint:
+ return True
+ return False
+
+
+def getDiskDom(diskDeviceList=None, bootPartition=None, skipDisk=None):
+ diskDeviceList = getDevice(diskDeviceList)
+ if Utils.isString(diskDeviceList):
+ diskDeviceList = [diskDeviceList]
+
+ if skipDisk:
+ skipDisk = getDevice(skipDisk)
+ if Utils.isString(skipDisk):
+ skipDisk = [skipDisk]
+
+ diskInfo = getDiskInfo(diskDeviceList)
+ diskList = diskInfo["disks"]
+ if not diskList:
+ return None
+
+ diskDom = Protocol.XDOM()
+ disksTag = diskDom.createTag("disks", None)
+ disksTag.appendChild(diskDom.createTag("totalDiskSpace", diskInfo["totalDiskSpace"]))
+ disksTag.appendChild(diskDom.createTag("diskSpaceInUse", diskInfo["diskSpaceInUse"]))
+ if not bootPartition:
+ bootPartition = getRootPartition()
+ for disk in diskList:
+ if skipDisk and disk["Device"] in skipDisk:
+ continue
+ diskTag = diskDom.createTag("disk", None)
+ diskTag.appendChild(diskDom.createTag("device", getDeviceName(disk["Device"])))
+ diskTag.appendChild(diskDom.createTag("description", disk["Description"]))
+ diskTag.appendChild(diskDom.createTag("size", str(disk["Size"])))
+ diskTag.appendChild(diskDom.createTag("used", str(disk["Used"])))
+ diskTag.appendChild(diskDom.createTag("interface", disk["Interface"]))
+ if disk["Partitions"]:
+ diskTag.appendChild(diskDom.createTag("init", "yes"))
+ else:
+ diskTag.appendChild(diskDom.createTag("init", "no"))
+ for partition in disk["Partitions"]:
+ partitionTag = diskDom.createTag("partition", None)
+ device = getDeviceName(partition["Device"])
+ partitionTag.appendChild(diskDom.createTag("name", device))
+ partitionTag.appendChild(diskDom.createTag("mountPoint", partition['mountPoint']))
+ if not partition["Uuid"]:
+ partitionTag.appendChild(diskDom.createTag("uuid", getUuidByDiskPartition("/dev/" + device)))
+ else:
+ partitionTag.appendChild(diskDom.createTag("uuid", partition["Uuid"]))
+ partitionTag.appendChild(diskDom.createTag("size", str(partition["Size"])))
+ partitionTag.appendChild(diskDom.createTag("free", str((partition["Size"] - partition["Used"]))))
+ partitionTag.appendChild(diskDom.createTag("used", partition["Used"]))
+ partitionTag.appendChild(diskDom.createTag("filesystem", partition["Fstype"]))
+ partitionTag.appendChild(diskDom.createTag("readOnlyAccess", partition["readOnlyAccess"]))
+ if partition['mountPoint'] or isDataDiskPartitionFormatted(partition["Device"]):
+ partitionTag.appendChild(diskDom.createTag("status", "READY"))
+ else:
+ partitionTag.appendChild(diskDom.createTag("status", "UNINITIALIZED"))
+ if "/export/" in partition["mountPoint"]:
+ partitionTag.appendChild(diskDom.createTag("dataDisk", "True"))
+ else:
+ partitionTag.appendChild(diskDom.createTag("dataDisk", "False"))
+ if "/" == partition["mountPoint"]:
+ partitionTag.appendChild(diskDom.createTag("boot", "yes"))
+ else:
+ partitionTag.appendChild(diskDom.createTag("boot", "no"))
+ diskTag.appendChild(partitionTag)
+ disksTag.appendChild(diskTag)
+ diskDom.addTag(disksTag)
+ return diskDom
diff --git a/src/com.gluster.storage.management.server.scripts/src/FsTabUtils.py b/src/com.gluster.storage.management.server.scripts/src/FsTabUtils.py
new file mode 100644
index 00000000..fcac4196
--- /dev/null
+++ b/src/com.gluster.storage.management.server.scripts/src/FsTabUtils.py
@@ -0,0 +1,92 @@
+# 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 Globals
+
+def readFsTab(fsTabFile=Globals.FSTAB_FILE):
+ try:
+ fsTabfp = open(fsTabFile)
+ except IOError, e:
+ log("readFsTab(): " + str(e))
+ return None
+
+ fsTabEntryList = []
+ for line in fsTabfp:
+ tokens = line.strip().split()
+ if not tokens or tokens[0].startswith('#'):
+ continue
+ fsTabEntry = {}
+ fsTabEntry["Device"] = None
+ fsTabEntry["MountPoint"] = None
+ fsTabEntry["FsType"] = None
+ fsTabEntry["Options"] = None
+ fsTabEntry["DumpOption"] = 0
+ fsTabEntry["fsckOrder"] = 0
+ try:
+ fsTabEntry["Device"] = tokens[0]
+ fsTabEntry["MountPoint"] = tokens[1]
+ fsTabEntry["FsType"] = tokens[2]
+ fsTabEntry["Options"] = tokens[3]
+ fsTabEntry["DumpOption"] = tokens[4]
+ fsTabEntry["fsckOrder"] = tokens[5]
+ except IndexError:
+ pass
+ if fsTabEntry["Device"] and fsTabEntry["MountPoint"] and fsTabEntry["FsType"] and fsTabEntry["Options"]:
+ fsTabEntryList.append(fsTabEntry)
+
+ fsTabfp.close()
+ return fsTabEntryList
+
+def writeFsTab(fsTabEntryList, fsTabFile=Globals.FSTAB_FILE):
+ try:
+ fsTabfp = open(fsTabFile, "w")
+ for fsTabEntry in fsTabEntryList:
+ fsTabfp.write("%s\t%s\t%s\t%s\t%s\t%s\n" %
+ (fsTabEntry["Device"], fsTabEntry["MountPoint"],
+ fsTabEntry["FsType"], fsTabEntry["Options"],
+ fsTabEntry["DumpOption"], fsTabEntry["fsckOrder"]))
+ fsTabfp.close()
+ except IOError, e:
+ log("writeFsTab(): " + str(e))
+ return False
+ return True
+
+def addFsTabEntry(fsTabEntry, fsTabFile=Globals.FSTAB_FILE):
+ try:
+ fsTabfp = open(fsTabFile, "a")
+ fsTabfp.write("%s\t%s\t%s\t%s\t%s\t%s\n" %
+ (fsTabEntry["Device"], fsTabEntry["MountPoint"],
+ fsTabEntry["FsType"], fsTabEntry["Options"],
+ fsTabEntry["DumpOption"], fsTabEntry["fsckOrder"]))
+ fsTabfp.close()
+ except IOError, e:
+ log("addFsTabEntry(): " + str(e))
+ return False
+ return True
+
+def removeFsTabEntry(fsTabEntry, fsTabFile=Globals.FSTAB_FILE):
+ fsTabEntryList = readFsTab(fsTabFile)
+ if not fsTabEntryList:
+ return False
+
+ try:
+ fsTabEntryList.remove(fsTabEntry)
+ except ValueError:
+ return False
+
+ return writeFsTab(fsTabEntryList, fsTabFile)
+
diff --git a/src/com.gluster.storage.management.server.scripts/src/RRDUtils.py b/src/com.gluster.storage.management.server.scripts/src/RRDUtils.py
new file mode 100644
index 00000000..1ad0deee
--- /dev/null
+++ b/src/com.gluster.storage.management.server.scripts/src/RRDUtils.py
@@ -0,0 +1,72 @@
+import rrdtool
+import os
+from socket import gethostname
+from itertools import groupby
+
+class RRD:
+ def __init__ (self):
+ self.COLORS = [0xff7777, 0x7777ff, 0x55ff55, 0xffcc77, 0xff77ff, 0x77ffff,0xffff77, 0x55aaff]
+ self.HOST = gethostname()
+ self.DIR = "/var/lib/collectd"
+
+ def fade_component(self, component):
+ return ((component + 255 * 5) / 6)
+
+ def fade_color(self, color):
+ r = 0;
+ for i in [0,1,2]:
+ shft = (i * 8)
+ component = ((color >> shft) & 255)
+ r |= (self.fade_component(component) << shft)
+ return r
+
+ def generate_pngs(self):
+
+ rrdlist = os.popen ("find %s -type f -name '*.rrd'" % self.DIR)
+
+ for rrd in rrdlist:
+ self.dss = []
+ self.defs = ""
+
+ rrdinfo = rrdtool.info(rrd.strip())
+
+ for key in rrdinfo.keys():
+ if key.split('[')[0] == 'ds':
+ self.dss.append(key.split('[')[1].split(']')[0])
+ self.dss.sort()
+
+ self.dss = [a for a,b in groupby(self.dss)]
+
+ for ds in self.dss:
+ self.defs = self.defs + " DEF:%s_avg=%s:%s:AVERAGE " % (ds, rrd.strip(), ds)
+ self.defs = self.defs + " DEF:%s_max=%s:%s:MAX " % (ds, rrd.strip(), ds)
+
+ j = 0
+ for ds in self.dss:
+ color = self.COLORS[j % len(self.COLORS)]
+ j = j + 1
+ faded_color = self.fade_color(color)
+ self.defs = self.defs + " AREA:%s_max#%06x " % (ds, faded_color)
+
+ j = 0
+ for ds in self.dss:
+ color = self.COLORS[j % len(self.COLORS)]
+ j = j + 1
+ self.defs = self.defs + " LINE2:%s_avg#%06x:%s " % (ds, color, ds)
+ self.defs = self.defs + " GPRINT:%s_avg:AVERAGE:%%5.1lf%%sAvg " % ds
+ self.defs = self.defs + " GPRINT:%s_max:MAX:%%5.1lf%%sMax " % ds
+
+ for span in ['1hour', '1day', '1week', '1month']:
+ os.system ("mkdir -p %s/%s" % (self.DIR, self.HOST))
+ image = os.path.dirname(rrd.strip()) + "-" + span + ".png"
+ cmd = "rrdtool graph " + image + " -t \"%s %s\"" % (os.path.dirname(rrd.strip()), span) + " --imgformat PNG --width 600 --height 100 --start now-" + span + " --end now --interlaced " + self.defs + " >/dev/null 2>&1"
+ os.system(cmd)
+
+
+def main ():
+
+ rrd = RRD ()
+ rrd.generate_pngs ()
+
+if __name__ == "__main__":
+ main()
diff --git a/src/com.gluster.storage.management.server.scripts/src/get_server_details.py b/src/com.gluster.storage.management.server.scripts/src/get_server_details.py
index ce1d97e6..2ab3cdd4 100755
--- a/src/com.gluster.storage.management.server.scripts/src/get_server_details.py
+++ b/src/com.gluster.storage.management.server.scripts/src/get_server_details.py
@@ -33,7 +33,6 @@ from optparse import OptionParser
def getServerDetails(listall):
-
serverName = socket.gethostname()
meminfo = getMeminfo()
cpu = 100 * float(getLoadavg())
@@ -94,10 +93,8 @@ def getServerDetails(listall):
# refreshing hal data
DiskUtils.refreshHal()
- diskObj = Disk()
- disks = diskObj.getMountableDiskList()
-
- if disks is None:
+ diskDom = DiskUtils.getDiskDom()
+ if not diskDom:
print "No disk found!"
syslog.syslog(syslog.LOG_ERR, "Error finding disk information of server:%s" % serverName)
return None
@@ -108,39 +105,7 @@ def getServerDetails(listall):
serverTag.appendChild(responseDom.createTag("status", "ONLINE"))
serverTag.appendChild(responseDom.createTag("uuid", None))
- totalDiskSpace = 0
- diskSpaceInUse = 0
- diskTag = responseDom.createTag("disks")
- for disk in disks:
- if not listall:
- if not disk['mount_point'].startswith("/export/"):
- continue
- if disk['interface'] in ['usb', 'mmc']:
- continue
- partitionTag = responseDom.createTag("disk", None)
- partitionTag.appendChild(responseDom.createTag("name", os.path.basename(disk['device'])))
- partitionTag.appendChild(responseDom.createTag("mountPoint", disk['mount_point']))
- partitionTag.appendChild(responseDom.createTag("serverName", serverName))
- partitionTag.appendChild(responseDom.createTag("description", disk['description']))
- total, used, free = 0, 0, 0
- if disk['size']:
- total, used, free = DiskUtils.getDiskSizeInfo(disk['device'])
- if total:
- partitionTag.appendChild(responseDom.createTag("space", str(total)))
- totalDiskSpace += total
- else:
- partitionTag.appendChild(responseDom.createTag("space", "NA"))
- if used:
- partitionTag.appendChild(responseDom.createTag("spaceInUse", str(used)))
- diskSpaceInUse += used
- partitionTag.appendChild(responseDom.createTag("status", "AVAILABLE"))
- else:
- partitionTag.appendChild(responseDom.createTag("spaceInUse", "NA"))
- partitionTag.appendChild(responseDom.createTag("status", "UNINITIALIZED"))
- diskTag.appendChild(partitionTag)
- serverTag.appendChild(diskTag)
- serverTag.appendChild(responseDom.createTag("totalDiskSpace", str(totalDiskSpace)))
- serverTag.appendChild(responseDom.createTag("diskSpaceInUse", str(diskSpaceInUse)))
+ serverTag.appendChild(diskDom.getElementsByTagRoute("disks")[0])
return serverTag
def main():