From 5cf991b09c3a04c2d98a2e3e60c6d2797f306038 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 11 Apr 2011 16:06:45 +0530 Subject: Added clear volume directory function and bug fixed. Added clear_volume_directory.py file fixed invalid syntax error in create_volume_directory.py file Renamed CreateVolumeExportDirectory.py into create_volume_directory.py --- .../src/nodes/CreateVolumeExportDirectory.py | 70 ---------------------- .../src/nodes/clear_volume_directory.py | 69 +++++++++++++++++++++ .../src/nodes/create_volume_directory.py | 70 ++++++++++++++++++++++ 3 files changed, 139 insertions(+), 70 deletions(-) delete mode 100755 src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py create mode 100755 src/com.gluster.storage.management.server.scripts/src/nodes/clear_volume_directory.py create mode 100755 src/com.gluster.storage.management.server.scripts/src/nodes/create_volume_directory.py (limited to 'src/com.gluster.storage.management.server.scripts') diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py b/src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py deleted file mode 100755 index 59dc3c19..00000000 --- a/src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py +++ /dev/null @@ -1,70 +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 sys -import syslog -from XmlHandler import ResponseXml -import DiskUtils -import Utils -import Common - -def createDirectory(disk, volumeName): - - # Retrieving disk uuid - diskUuid = DiskUtils.getUuidByDiskPartition(DiskUtils.getDevice(disk)) - - rs = ResponseXml() - if not diskUuid: - Common.log(syslog.LOG_ERR, "failed to find disk:%s uuid" % disk) - rs.appendTagRoute("status.code", "-1") - rs.appendTagRoute("status.message", "Error: Unable to find disk uuid") - return rs.toprettyxml() - - # Retrieving disk mount point using disk uuid - diskMountPoint = DiskUtils.getMountPointByUuid(diskUuid) - if not os.path.exists(diskMountPoint): - Common.log(syslog.LOG_ERR, "failed to retrieve disk:%s mount point" % disk) - rs.appendTagRoute("status.code", "-1") - rs.appendTagRoute("status.message", "Error: Failed to retrieve disk details") - return rs.toprettyxml() - - # creating volume directory under disk mount point - volumeDirectory = "%s/%s" % (diskMountPoint, volumeName) - if not os.path.exists(volumeDirectory): - command = ["sudo", "mkdir", volumeDirectory] - rv = Utils.runCommandFG(command, stdout=True, root=True) - message = Common.stripEmptyLines(rv["Stdout"]) - if rv["Stderr"]: - error = Common.stripEmptyLines(rv["Stderr"]) - message += "Error: [%s]" % (error) - Common.log(syslog.LOG_ERR, "failed to create volume directory %s, %s" % (volumeDirectory, error) - rs.appendTagRoute("status.code", rv["Status"]) - rs.appendTagRoute("status.message", message) - return rs.toprettyxml() - -def main(): - if len(sys.argv) != 3: - print >> sys.stderr, "usage: %s " % sys.argv[0] - sys.exit(-1) - - disk = sys.argv[1] - volumeName = sys.argv[2] - print createDirectory(disk, volumeName) - sys.exit(0) - -main() diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/clear_volume_directory.py b/src/com.gluster.storage.management.server.scripts/src/nodes/clear_volume_directory.py new file mode 100755 index 00000000..e9f3ab43 --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/nodes/clear_volume_directory.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 sys +import syslog +from XmlHandler import ResponseXml +import DiskUtils +import Utils +import Common + +def clearVolumeDirectory(disk, volumeName): + + # Retrieving disk uuid + diskUuid = DiskUtils.getUuidByDiskPartition(DiskUtils.getDevice(disk)) + + rs = ResponseXml() + if not diskUuid: + Common.log(syslog.LOG_ERR, "failed to find disk:%s uuid" % disk) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: Unable to find disk uuid") + return rs.toprettyxml() + + # Retrieving disk mount point using disk uuid + diskMountPoint = DiskUtils.getMountPointByUuid(diskUuid) + if not os.path.exists(diskMountPoint): + Common.log(syslog.LOG_ERR, "failed to retrieve disk:%s mount point" % disk) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: Failed to retrieve disk details") + return rs.toprettyxml() + + # clear volume directory from the disk + volumeDirectory = "%s/%s" % (diskMountPoint, volumeName) + command = ["sudo", "rm", "-fr", volumeDirectory] + rv = Utils.runCommandFG(command, stdout=True, root=True) + message = Common.stripEmptyLines(rv["Stdout"]) + if rv["Stderr"]: + error = Common.stripEmptyLines(rv["Stderr"]) + message += "Error: [%s]" % (error) + Common.log(syslog.LOG_ERR, "failed to clear volume directory %s, %s" % (volumeDirectory, error)) + rs.appendTagRoute("status.code", rv["Status"]) + rs.appendTagRoute("status.message", message) + return rs.toprettyxml() + +def main(): + if len(sys.argv) != 3: + print >> sys.stderr, "usage: %s " % sys.argv[0] + sys.exit(-1) + + disk = sys.argv[1] + volumeName = sys.argv[2] + print clearVolumeDirectory(disk, volumeName) + sys.exit(0) + +main() diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/create_volume_directory.py b/src/com.gluster.storage.management.server.scripts/src/nodes/create_volume_directory.py new file mode 100755 index 00000000..1b994ab3 --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/nodes/create_volume_directory.py @@ -0,0 +1,70 @@ +#!/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 sys +import syslog +from XmlHandler import ResponseXml +import DiskUtils +import Utils +import Common + +def createDirectory(disk, volumeName): + + # Retrieving disk uuid + diskUuid = DiskUtils.getUuidByDiskPartition(DiskUtils.getDevice(disk)) + + rs = ResponseXml() + if not diskUuid: + Common.log(syslog.LOG_ERR, "failed to find disk:%s uuid" % disk) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: Unable to find disk uuid") + return rs.toprettyxml() + + # Retrieving disk mount point using disk uuid + diskMountPoint = DiskUtils.getMountPointByUuid(diskUuid) + if not os.path.exists(diskMountPoint): + Common.log(syslog.LOG_ERR, "failed to retrieve disk:%s mount point" % disk) + rs.appendTagRoute("status.code", "-1") + rs.appendTagRoute("status.message", "Error: Failed to retrieve disk details") + return rs.toprettyxml() + + # creating volume directory under disk mount point + volumeDirectory = "%s/%s" % (diskMountPoint, volumeName) + if not os.path.exists(volumeDirectory): + command = ["sudo", "mkdir", volumeDirectory] + rv = Utils.runCommandFG(command, stdout=True, root=True) + message = Common.stripEmptyLines(rv["Stdout"]) + if rv["Stderr"]: + error = Common.stripEmptyLines(rv["Stderr"]) + message += "Error: [%s]" % (error) + Common.log(syslog.LOG_ERR, "failed to create volume directory %s, %s" % (volumeDirectory, error)) + rs.appendTagRoute("status.code", rv["Status"]) + rs.appendTagRoute("status.message", message) + return rs.toprettyxml() + +def main(): + if len(sys.argv) != 3: + print >> sys.stderr, "usage: %s " % sys.argv[0] + sys.exit(-1) + + disk = sys.argv[1] + volumeName = sys.argv[2] + print createDirectory(disk, volumeName) + sys.exit(0) + +main() -- cgit