summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster/snap_scheduler.py
blob: 4493cf40f0cc2eaf93473625ec268b30fb44bbf1 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
#  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.

from glusto.core import Glusto as g

"""
    This file contains the Snapshot Scheduler operations
    like initialise scheduler, enable scheduler, add jobs,
    edit jobs, delete jobs, list jobs and scheduler status.
"""


def scheduler_init(servers):
    """Initialises snapshot scheduler
     Args:
         servers(str): List of servers on which cmd has to be executed.

     Returns:
         True - Success
         False - Failure
     Example:
          scheduler_init("abc.com")
    """

    if isinstance(servers, str):
        servers = [servers]

    cmd = "snap_scheduler.py init"
    for server in servers:
        ret, _, _ = g.run(server, cmd)
        if ret != 0:
            g.log.error("Unable to initialize scheduler on %s", server)
            return False
    return True


def scheduler_enable(mnode):
    """Enables snapshot scheduler on given node
     Args:
           mnode (str): Node on which cmd has 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.

     Example:
        scheduler_enable("abc.com")
    """

    cmd = "snap_scheduler.py enable"
    return g.run(mnode, cmd)


def scheduler_disable(mnode):
    """Disables snapshot scheduler on given node
    Args:
        servers (str): servers on which cmd has 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.

    Example:
        scheduler_disable("abc.com")
    """

    cmd = "snap_scheduler.py disable"
    return g.run(mnode, cmd)


def scheduler_add_jobs(mnode, jobname, scheduler, volname):
    """Add snapshot scheduler Jobs on given node
    Args:
        mnode (str): Node on which cmd has to be executed.
        jobname (str): scheduled Jobname
        scheduler (str): "* * * * *"
        * * * * *
        | | | | |
        | | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
        | | | +------ Month of the Year (range: 1-12)
        | | +-------- Day of the Month  (range: 1-31)
        | +---------- Hour              (range: 0-23)
        +------------ Minute            (range: 0-59)

        volname (str): Volume name to schedule a job.

    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.

    Example:
        scheduler_add_jobs("abc.com", "jobname", "*/10 * * * *", "volname")

        """
    cmd = ("snap_scheduler.py add \"%s\" \"%s\" %s"
           % (jobname, scheduler, volname))
    return g.run(mnode, cmd)


def scheduler_edit_jobs(mnode, jobname, scheduler, volname):
    """Edit the existing scheduled job

    Args:
        mnode (str): Node on which cmd has to be executed.
        jobname (str): scheduled Jobname
        scheduler (str): "* * * * *"
        * * * * *
        | | | | |
        | | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
        | | | +------ Month of the Year (range: 1-12)
        | | +-------- Day of the Month  (range: 1-31)
        | +---------- Hour              (range: 0-23)
        +------------ Minute            (range: 0-59)

        volname (str): Volume name to schedule a job.

    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.

    Example:
        scheduler_edit_jobs("abc.com", "Job1", "scheduler", "volname")
    """
    cmd = ("snap_scheduler.py edit \"%s\" \"%s\" %s"
           % (jobname, scheduler, volname))
    return g.run(mnode, cmd)


def scheduler_list(mnode):
    """Executes snapshot scheduler list command

    Args:
        mnode (str): Node on which cmd has 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.

    Example:
        scheduler_list("abc.com")
    """
    cmd = "snap_scheduler.py list"
    return g.run(mnode, cmd)


def scheduler_status(mnode):
    """Executes snapshot scheduler status command

    Args:
        mnode (str): Node on which cmd has 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.

    Example:
        scheduler_status("abc.xyz.com")
    """
    cmd = "snap_scheduler.py status"
    return g.run(mnode, cmd)


def scheduler_delete(mnode, jobname):
    """Deletes the already scheduled job

    Args:
        mnode (str): Node on which cmd has to be executed.
        jobname (str): scheduled Jobname

    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.

    Example:
        scheduler_delete("abc.xyz.com", "Job1")
    """
    cmd = "snap_scheduler.py delete %s" % jobname
    return g.run(mnode, cmd)