From b8e32480bd75fc6dfc2cd1eb7eaac67e13f420ee Mon Sep 17 00:00:00 2001 From: Shwetha Panduranga Date: Mon, 3 Oct 2016 14:59:03 +0530 Subject: Adding libs for brick ops, volume helpers, mount helpers, gluster base class, heal related helpers, samba helpers, and windows ops helpers Change-Id: I0ad8fc7548c88e89d2ba6441166b9a38af76cea0 Signed-off-by: Shwetha Panduranga --- glustolibs-gluster/glustolibs/gluster/brick_ops.py | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 glustolibs-gluster/glustolibs/gluster/brick_ops.py (limited to 'glustolibs-gluster/glustolibs/gluster/brick_ops.py') diff --git a/glustolibs-gluster/glustolibs/gluster/brick_ops.py b/glustolibs-gluster/glustolibs/gluster/brick_ops.py new file mode 100644 index 000000000..ae55b6851 --- /dev/null +++ b/glustolibs-gluster/glustolibs/gluster/brick_ops.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# Copyright (C) 2015-2016 Red Hat, Inc. +# +# This program 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 2 of the License, or +# any later version. +# +# This program 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +""" + Description: Module for gluster brick operations +""" + +from glusto.core import Glusto as g + +def add_brick(mnode, volname, bricks_list, replica=None): + """Add Bricks specified in the bricks_list to the volume. + + Args: + mnode (str): None on which the commands are executed. + volname (str): Name of the volume + bricks_list (list): List of bricks to be added + + Kwargs: + replica (int): Replica count to increase the replica count of + the volume. + + Returns: + tuple: Tuple containing three elements (ret, out, err). + The first element 'ret' is of type 'int' and is the return value + of command execution. + + The second element 'out' is of type 'str' and is the stdout value + of the command execution. + + The third element 'err' is of type 'str' and is the stderr value + of the command execution. + """ + if replica is None: + cmd = ("gluster volume add-brick %s %s" % + (volname, ' '.join(bricks_list))) + else: + cmd = ("gluster volume add-brick %s replica %d %s" % + (volname, int(replica), ' '.join(bricks_list))) + + return g.run(mnode, cmd) + + +# remove_brick +def remove_brick(mnode, volname, bricks_list, option, replica=None): + """Remove bricks specified in the bricks_list from the volume. + + Args: + mnode (str): None on which the commands are executed. + volname (str): Name of the volume + bricks_list (list): List of bricks to be removed + option (str): Remove brick options: + + Kwargs: + replica (int): Replica count to increase the replica count of + the volume. + + Returns: + tuple: Tuple containing three elements (ret, out, err). + The first element 'ret' is of type 'int' and is the return value + of command execution. + + The second element 'out' is of type 'str' and is the stdout value + of the command execution. + + The third element 'err' is of type 'str' and is the stderr value + of the command execution. + """ + if option == "commit" or option == "force": + option = option + " --mode=script" + + if replica is None: + cmd = ("gluster volume remove-brick %s %s %s" % + (volname, ' '.join(bricks_list), option)) + else: + cmd = ("gluster volume remove-brick %s replica %d %s force " + "--mode=script" % (volname, int(replica), + ' '.join(bricks_list))) + + return g.run(mnode, cmd) + + +# replace_brick +def replace_brick(mnode, volname, src_brick, dst_brick): + """Replace src brick with dst brick from the volume. + + Args: + mnode (str): None on which the commands are executed. + volname (str): Name of the volume + src_brick (str): Source brick name + dst_brick (str): Destination brick name + + Returns: + tuple: Tuple containing three elements (ret, out, err). + The first element 'ret' is of type 'int' and is the return value + of command execution. + + The second element 'out' is of type 'str' and is the stdout value + of the command execution. + + The third element 'err' is of type 'str' and is the stderr value + of the command execution. + """ + cmd = ("gluster volume replace-brick %s %s %s commit force" % + (volname, src_brick, dst_brick)) + return g.run(mnode, cmd) -- cgit