summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster/geo_rep_ops.py
blob: 44a3174f84a09a06b1e106e5cffd485be1b45cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#  Copyright (C) 2017-2018  Red Hat, Inc. <http://www.redhat.com>
#
#  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: Library for gluster geo-replication operations
"""

from glusto.core import Glusto as g


def create_shared_storage(mnode):
    """Create shared volume which is necessary for the setup of
       a geo-rep session

    Args:
        mnode(str): Node on which command is to be executed

    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 set all cluster.enable-shared-storage enable"
    return g.run(mnode, cmd)


def georep_createpem(mnode):
    """ Creates a common pem pub file on all the nodes in the master and
        is used to implement the passwordless SSH connection
    Args:
        mnode (str): Node on which cmd is to be executed
    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 system:: execute gsec_create"
    return g.run(mnode, cmd)


def georep_create(mnode, mastervol, slaveip, slavevol, user=None, force=False):
    """Pushes the keys to all the slave nodes and creates a geo-rep session
    Args:
        mnode (str) : Node on which cmd is to be executed
        mastervol (str) : The name of the mastervol
        slaveip (str): SlaveIP
        slavevol (str) The name of the slave volume
    kwargs:
        force (bool): If this option is set to True, then create geo-rep
            session will be executed with the force option.
            If it is set to False, then the geo-rep session is created
            without the force option
        user (str): If not set, the default is a root-user
            If specified, non-root user participates in the geo-rep
            session

    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 user:
        if force:
            cmd = "gluster volume geo-replication %s %s@%s::%s create push-pem \
                   force" % (mastervol, user, slaveip, slavevol)
        else:
            cmd = "gluster volume geo-replication %s %s@%s::%s create \
                   push-pem" % (mastervol, user, slaveip, slavevol)
    else:
        if force:
            cmd = "gluster volume geo-replication %s %s::%s create push-pem \
                   force" % (mastervol, slaveip, slavevol)
        else:
            cmd = "gluster volume geo-replication %s %s::%s create \
                   push-pem" % (mastervol, slaveip, slavevol)
    return g.run(mnode, cmd)


def georep_pause(mnode, mastervol, slaveip, slavevol, user=None):
    """Pauses the geo-replication session
    Args:
        mnode (str): Node on which cmd is to be executed
        mastervol (str):The name of the master volume
        slaveip (str): SlaveIP
        slavevol (str): The name of the slave volume
    Kwargs:
        user (str): If not set, the default is a root-user
        If specified, non-root user participates in geo-rep
        session
    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 user:
        cmd = "gluster volume geo-replication %s %s@%s::%s \
               pause" % (mastervol, user, slaveip, slavevol)
    else:
        cmd = "gluster volume geo-replication %s %s::%s \
               pause" % (mastervol, slaveip, slavevol)
    return g.run(mnode, cmd)


def georep_resume(mnode, mastervol, slaveip, slavevol, user=None):
    """Resumes the geo-replication session
    Args:
        mnode (str): Node on which cmd is to be executed
        mastervol (str):The name of the master volume
        slaveip (str): SlaveIP
        slavevol (str): The name of the slave volume
    Kwargs:
        user (str): If not set, the default is a root-user
        If specified, non-root user participates in geo-rep
        session
    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 user:
        cmd = "gluster volume geo-replication %s %s@%s::%s \
               resume" % (mastervol, user, slaveip, slavevol)
    else:
        cmd = "gluster volume geo-replication %s %s::%s \
               resume" % (mastervol, slaveip, slavevol)
    return g.run(mnode, cmd)