From 1500ca7e13074b2bc394ac4feb73e596d1203283 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 28 Apr 2011 14:08:22 +0530 Subject: Added function to get disk name by the given directory path Renamed get-disk-mount-point.py into get_disk_mount_point.py --- .../src/nodes/get-disk-mount-point.py | 64 -------------------- .../src/nodes/get_disk_mount_point.py | 64 ++++++++++++++++++++ .../src/nodes/get_disk_name_by_path.py | 69 ++++++++++++++++++++++ 3 files changed, 133 insertions(+), 64 deletions(-) delete mode 100755 src/com.gluster.storage.management.server.scripts/src/nodes/get-disk-mount-point.py create mode 100755 src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_mount_point.py create mode 100755 src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_name_by_path.py (limited to 'src') diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/get-disk-mount-point.py b/src/com.gluster.storage.management.server.scripts/src/nodes/get-disk-mount-point.py deleted file mode 100755 index b2274b4d..00000000 --- a/src/com.gluster.storage.management.server.scripts/src/nodes/get-disk-mount-point.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# Copyright (C) 2010 Gluster, Inc. -# 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 -# . - -import os -import syslog -import Common -from DiskUtils import * -from XmlHandler import ResponseXml - - -def getmountpoint(path): - if not path: - Common.log(syslog.LOG_ERR, "Not a valid path:%s" % path) - rs.appendTagRoute("status.code", "-1") - rs.appendTagRoute("status.message", "Error: given path name is empty") - return rs.toprettyxml() - - rs = ResponseXml() - mountPoint = None - - for line in readFsTab(): - if path.startswith(line['MountPoint']): - if not mountPoint: - mountPoint = line['MountPoint'] - if len(line['MountPoint']) > len(mountPoint): - mountPoint = line['MountPoint'] - - if "/" == mountPoint or not mountPoint: - Common.log(syslog.LOG_ERR, "failed to find mount point of the given path:%s" % path) - rs.appendTagRoute("status.code", "-1") - rs.appendTagRoute("status.message", "Error: Unable to find disk mount point") - return rs.toprettyxml() - - rs.appendTagRoute("status.code", "0") - rs.appendTagRoute("status.message", mountPoint) - return rs.toprettyxml() - -def main(): - if len(sys.argv) != 2: - print >> sys.stderr, "usage: %s " % sys.argv[0] - sys.exit(-1) - - path = sys.argv[1] - print getmountpoint(path) - sys.exit(0) - -if __name__ == "__main__": - main() - diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_mount_point.py b/src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_mount_point.py new file mode 100755 index 00000000..b2274b4d --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_mount_point.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +# Copyright (C) 2010 Gluster, Inc. +# 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 +# . + +import os +import syslog +import Common +from DiskUtils import * +from XmlHandler import ResponseXml + + +def getmountpoint(path): + if not path: + Common.log(syslog.LOG_ERR, "Not a valid path:%s" % path) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: given path name is empty") + return rs.toprettyxml() + + rs = ResponseXml() + mountPoint = None + + for line in readFsTab(): + if path.startswith(line['MountPoint']): + if not mountPoint: + mountPoint = line['MountPoint'] + if len(line['MountPoint']) > len(mountPoint): + mountPoint = line['MountPoint'] + + if "/" == mountPoint or not mountPoint: + Common.log(syslog.LOG_ERR, "failed to find mount point of the given path:%s" % path) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: Unable to find disk mount point") + return rs.toprettyxml() + + rs.appendTagRoute("status.code", "0") + rs.appendTagRoute("status.message", mountPoint) + return rs.toprettyxml() + +def main(): + if len(sys.argv) != 2: + print >> sys.stderr, "usage: %s " % sys.argv[0] + sys.exit(-1) + + path = sys.argv[1] + print getmountpoint(path) + sys.exit(0) + +if __name__ == "__main__": + main() + diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_name_by_path.py b/src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_name_by_path.py new file mode 100755 index 00000000..72eb80dd --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/nodes/get_disk_name_by_path.py @@ -0,0 +1,69 @@ +#!/usr/bin/python +# Copyright (C) 2010 Gluster, Inc. +# 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 +# . + +import os +import syslog +import Common +from DiskUtils import * +from XmlHandler import ResponseXml + + +def getmountpoint(path): + if not path: + Common.log(syslog.LOG_ERR, "Not a valid path:%s" % path) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: given path name is empty") + return rs.toprettyxml() + + rs = ResponseXml() + mountPoint = None + fsTabEntry = None + for line in readFsTab(): + if path.startswith(line['MountPoint']): + if not mountPoint: + mountPoint = line['MountPoint'] + fsTabEntry = line + if len(line['MountPoint']) > len(mountPoint): + mountPoint = line['MountPoint'] + fsTabEntry = line + + if "/" == mountPoint or not mountPoint: + Common.log(syslog.LOG_ERR, "failed to find mount point of the given path:%s" % path) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: Unable to find disk mount point") + return rs.toprettyxml() + + rs.appendTagRoute("status.code", "0") + if fsTabEntry["Device"].startswith("UUID="): + rs.appendTagRoute("status.message", getDiskPartitionByUuid(fsTabEntry["Device"].split("UUID=")[-1])) + else: + rs.appendTagRoute("status.message", "Unable to find disk name") + return rs.toprettyxml() + +def main(): + if len(sys.argv) != 2: + print >> sys.stderr, "usage: %s " % sys.argv[0] + sys.exit(-1) + + path = sys.argv[1] + print getmountpoint(path) + sys.exit(0) + +if __name__ == "__main__": + main() + -- cgit