root / lib / storage / gluster.py @ 8106dd64
History | View | Annotate | Download (4.3 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2013 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
"""Gluster storage class.
|
22 |
|
23 |
This class is very similar to FileStorage, given that Gluster when mounted
|
24 |
behaves essentially like a regular file system. Unlike RBD, there are no
|
25 |
special provisions for block device abstractions (yet).
|
26 |
|
27 |
"""
|
28 |
from ganeti import errors |
29 |
|
30 |
from ganeti.storage import base |
31 |
from ganeti.storage.filestorage import FileDeviceHelper |
32 |
|
33 |
|
34 |
class GlusterStorage(base.BlockDev): |
35 |
"""File device using the Gluster backend.
|
36 |
|
37 |
This class represents a file storage backend device stored on Gluster. The
|
38 |
system administrator must mount the Gluster device himself at boot time before
|
39 |
Ganeti is run.
|
40 |
|
41 |
The unique_id for the file device is a (file_driver, file_path) tuple.
|
42 |
|
43 |
"""
|
44 |
def __init__(self, unique_id, children, size, params, dyn_params): |
45 |
"""Initalizes a file device backend.
|
46 |
|
47 |
"""
|
48 |
if children:
|
49 |
base.ThrowError("Invalid setup for file device")
|
50 |
super(GlusterStorage, self).__init__(unique_id, children, size, params, |
51 |
dyn_params) |
52 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: |
53 |
raise ValueError("Invalid configuration data %s" % str(unique_id)) |
54 |
self.driver = unique_id[0] |
55 |
self.dev_path = unique_id[1] |
56 |
|
57 |
self.file = FileDeviceHelper(self.dev_path) |
58 |
|
59 |
self.Attach()
|
60 |
|
61 |
def Assemble(self): |
62 |
"""Assemble the device.
|
63 |
|
64 |
Checks whether the file device exists, raises BlockDeviceError otherwise.
|
65 |
|
66 |
"""
|
67 |
assert self.attached, "Gluster file assembled without being attached" |
68 |
self.file.Exists(assert_exists=True) |
69 |
|
70 |
def Shutdown(self): |
71 |
"""Shutdown the device.
|
72 |
|
73 |
"""
|
74 |
|
75 |
self.file = None |
76 |
self.dev_path = None |
77 |
self.attached = False |
78 |
|
79 |
def Open(self, force=False): |
80 |
"""Make the device ready for I/O.
|
81 |
|
82 |
This is a no-op for the file type.
|
83 |
|
84 |
"""
|
85 |
assert self.attached, "Gluster file opened without being attached" |
86 |
|
87 |
def Close(self): |
88 |
"""Notifies that the device will no longer be used for I/O.
|
89 |
|
90 |
This is a no-op for the file type.
|
91 |
"""
|
92 |
pass
|
93 |
|
94 |
def Remove(self): |
95 |
"""Remove the file backing the block device.
|
96 |
|
97 |
@rtype: boolean
|
98 |
@return: True if the removal was successful
|
99 |
|
100 |
"""
|
101 |
return self.file.Remove() |
102 |
|
103 |
def Rename(self, new_id): |
104 |
"""Renames the file.
|
105 |
|
106 |
"""
|
107 |
# TODO: implement rename for file-based storage
|
108 |
base.ThrowError("Rename is not supported for Gluster storage")
|
109 |
|
110 |
def Grow(self, amount, dryrun, backingstore, excl_stor): |
111 |
"""Grow the file
|
112 |
|
113 |
@param amount: the amount (in mebibytes) to grow with
|
114 |
|
115 |
"""
|
116 |
self.file.Grow(amount, dryrun, backingstore, excl_stor)
|
117 |
|
118 |
def Attach(self): |
119 |
"""Attach to an existing file.
|
120 |
|
121 |
Check if this file already exists.
|
122 |
|
123 |
@rtype: boolean
|
124 |
@return: True if file exists
|
125 |
|
126 |
"""
|
127 |
self.attached = self.file.Exists() |
128 |
return self.attached |
129 |
|
130 |
def GetActualSize(self): |
131 |
"""Return the actual disk size.
|
132 |
|
133 |
@note: the device needs to be active when this is called
|
134 |
|
135 |
"""
|
136 |
return self.file.Size() |
137 |
|
138 |
@classmethod
|
139 |
def Create(cls, unique_id, children, size, spindles, params, excl_stor, |
140 |
dyn_params): |
141 |
"""Create a new file.
|
142 |
|
143 |
@param size: the size of file in MiB
|
144 |
|
145 |
@rtype: L{bdev.FileStorage}
|
146 |
@return: an instance of FileStorage
|
147 |
|
148 |
"""
|
149 |
if excl_stor:
|
150 |
raise errors.ProgrammerError("FileStorage device requested with" |
151 |
" exclusive_storage")
|
152 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2: |
153 |
raise ValueError("Invalid configuration data %s" % str(unique_id)) |
154 |
|
155 |
dev_path = unique_id[1]
|
156 |
|
157 |
FileDeviceHelper.Create(dev_path, size) |
158 |
return GlusterStorage(unique_id, children, size, params, dyn_params)
|