Statistics
| Branch: | Revision:

root / rbd / grow @ 35acd6c9

History | View | Annotate | Download (2.3 kB)

1
#!/usr/bin/env python
2
#
3
# Copyright (C) 2011 Greek Research and Technology Network
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

    
20
"""Grow an existing rbd Image
21

    
22
This program grows an existing rbd Image which resides in a
23
RADOS cluster
24

    
25
It takes it's input from environment variables. Specifically the
26
following variables should be present:
27

    
28
 - VOL_NAME: The name of the Image to grow
29
 - POOL:     The RADOS pool in which the Image resides
30
 - VOL_SIZE: The current Image's size
31
 - VOL_NEW_SIZE: The new size of the Image after it's grown
32

    
33
Returns 0 upon successful grow, 1 upon failure
34

    
35
"""
36

    
37
import os
38
import sys
39

    
40
sys.path.append("/usr/share/ganeti")
41

    
42
from ganeti import utils
43

    
44

    
45
def ReadEnv():
46
  """Read the mandatory enviromental variables
47

    
48
  """
49
  name = os.getenv("VOL_NAME")
50
  if name is None:
51
    sys.stderr.write('The environment variable VOL_NAME is missing.\n')
52
    return None
53
#  pool = os.getenv("POOL")
54
  pool = "rbd"
55
  if pool is None:
56
    sys.stderr.write('The environment variable POOL is missing.\n')
57
    return None
58
  new_size = os.getenv("VOL_NEW_SIZE")
59
  if new_size is None:
60
    sys.stderr.write('The environment variable VOL_NEW_SIZE is missing.\n')
61
    return None
62

    
63
  return (name, pool, new_size)
64

    
65

    
66
def main():
67
  env = ReadEnv()
68
  if env is None:
69
    sys.stderr.write('Wrong environment. Aborting...\n')
70
    return 1
71

    
72
  rbd_name, rbd_pool, new_size = env
73

    
74
  cmd = ["rbd", "resize", "-p", "%s" % rbd_pool, "%s" % rbd_name,
75
         "--size", "%s" % new_size]
76
  result = utils.RunCmd(cmd)
77
  if result.failed:
78
    sys.stderr.write('rbd resize failed (%s): %s\n' %
79
                     (result.fail_reason, result.output))
80
    return 1
81

    
82
  return 0
83

    
84

    
85
if __name__ == "__main__":
86
    sys.exit(main())