1 |
charliebrady |
1.1 |
# lvmpv.py |
2 |
|
|
# Device format classes for anaconda's storage configuration module. |
3 |
|
|
# |
4 |
|
|
# Copyright (C) 2009 Red Hat, Inc. |
5 |
|
|
# |
6 |
|
|
# This copyrighted material is made available to anyone wishing to use, |
7 |
|
|
# modify, copy, or redistribute it subject to the terms and conditions of |
8 |
|
|
# the GNU General Public License v.2, or (at your option) any later version. |
9 |
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
10 |
|
|
# ANY WARRANTY expressed or implied, including the implied warranties of |
11 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
12 |
|
|
# Public License for more details. You should have received a copy of the |
13 |
|
|
# GNU General Public License along with this program; if not, write to the |
14 |
|
|
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 |
|
|
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the |
16 |
|
|
# source code or documentation are not subject to the GNU General Public |
17 |
|
|
# License and may only be used or replicated with the express permission of |
18 |
|
|
# Red Hat, Inc. |
19 |
|
|
# |
20 |
|
|
# Red Hat Author(s): Dave Lehman <dlehman@redhat.com> |
21 |
|
|
# |
22 |
|
|
|
23 |
|
|
import os |
24 |
|
|
|
25 |
|
|
from ..storage_log import log_method_call |
26 |
|
|
from parted import PARTITION_LVM |
27 |
|
|
from ..errors import * |
28 |
|
|
from ..devicelibs import lvm |
29 |
|
|
from . import DeviceFormat, register_device_format |
30 |
|
|
|
31 |
|
|
import gettext |
32 |
|
|
_ = lambda x: gettext.ldgettext("anaconda", x) |
33 |
|
|
|
34 |
|
|
import logging |
35 |
|
|
log = logging.getLogger("storage") |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
class LVMPhysicalVolume(DeviceFormat): |
39 |
|
|
""" An LVM physical volume. """ |
40 |
|
|
_type = "lvmpv" |
41 |
|
|
_name = "physical volume (LVM)" |
42 |
|
|
_udevTypes = ["LVM2_member"] |
43 |
|
|
partedFlag = PARTITION_LVM |
44 |
|
|
_formattable = True # can be formatted |
45 |
|
|
_supported = True # is supported |
46 |
|
|
_linuxNative = True # for clearpart |
47 |
|
|
_packages = ["lvm2"] # required packages |
48 |
|
|
|
49 |
|
|
def __init__(self, *args, **kwargs): |
50 |
|
|
""" Create an LVMPhysicalVolume instance. |
51 |
|
|
|
52 |
|
|
Keyword Arguments: |
53 |
|
|
|
54 |
|
|
device -- path to the underlying device |
55 |
|
|
uuid -- this PV's uuid (not the VG uuid) |
56 |
|
|
vgName -- the name of the VG this PV belongs to |
57 |
|
|
vgUuid -- the UUID of the VG this PV belongs to |
58 |
|
|
peStart -- offset of first physical extent |
59 |
|
|
exists -- indicates whether this is an existing format |
60 |
|
|
|
61 |
|
|
""" |
62 |
|
|
log_method_call(self, *args, **kwargs) |
63 |
|
|
DeviceFormat.__init__(self, *args, **kwargs) |
64 |
|
|
self.vgName = kwargs.get("vgName") |
65 |
|
|
self.vgUuid = kwargs.get("vgUuid") |
66 |
|
|
# liblvm may be able to tell us this at some point, even |
67 |
|
|
# for not-yet-created devices |
68 |
|
|
self.peStart = kwargs.get("peStart", 1.0) # in MB |
69 |
|
|
|
70 |
|
|
def __str__(self): |
71 |
|
|
s = DeviceFormat.__str__(self) |
72 |
|
|
s += (" vgName = %(vgName)s vgUUID = %(vgUUID)s" |
73 |
|
|
" peStart = %(peStart)s" % |
74 |
|
|
{"vgName": self.vgName, "vgUUID": self.vgUuid, |
75 |
|
|
"peStart": self.peStart}) |
76 |
|
|
return s |
77 |
|
|
|
78 |
|
|
@property |
79 |
|
|
def dict(self): |
80 |
|
|
d = super(LVMPhysicalVolume, self).dict |
81 |
|
|
d.update({"vgName": self.vgName, "vgUUID": self.vgUuid, |
82 |
|
|
"peStart": self.peStart}) |
83 |
|
|
return d |
84 |
|
|
|
85 |
|
|
def probe(self): |
86 |
|
|
""" Probe for any missing information about this device. """ |
87 |
|
|
log_method_call(self, device=self.device, |
88 |
|
|
type=self.type, status=self.status) |
89 |
|
|
if not self.exists: |
90 |
|
|
raise PhysicalVolumeError("format has not been created") |
91 |
|
|
|
92 |
|
|
#info = lvm.pvinfo(self.device) |
93 |
|
|
#self.vgName = info['vg_name'] |
94 |
|
|
#self.vgUuid = info['vg_uuid'] |
95 |
|
|
|
96 |
|
|
def create(self, *args, **kwargs): |
97 |
|
|
""" Create the format. """ |
98 |
|
|
log_method_call(self, device=self.device, |
99 |
|
|
type=self.type, status=self.status) |
100 |
|
|
intf = kwargs.get("intf") |
101 |
|
|
w = None |
102 |
|
|
if intf: |
103 |
|
|
w = intf.progressWindow(_("Formatting"), |
104 |
|
|
_("Creating %s on %s") |
105 |
|
|
% (self.name, self.device), |
106 |
|
|
100, pulse = True) |
107 |
|
|
|
108 |
|
|
try: |
109 |
|
|
DeviceFormat.create(self, *args, **kwargs) |
110 |
|
|
# Consider use of -Z|--zero |
111 |
|
|
# -f|--force or -y|--yes may be required |
112 |
|
|
|
113 |
|
|
# lvm has issues with persistence of metadata, so here comes the |
114 |
|
|
# hammer... |
115 |
|
|
DeviceFormat.destroy(self, *args, **kwargs) |
116 |
|
|
|
117 |
|
|
lvm.pvcreate(self.device, progress=w) |
118 |
|
|
except Exception: |
119 |
|
|
raise |
120 |
|
|
else: |
121 |
|
|
self.exists = True |
122 |
|
|
self.notifyKernel() |
123 |
|
|
finally: |
124 |
|
|
if w: |
125 |
|
|
w.pop() |
126 |
|
|
|
127 |
|
|
def destroy(self, *args, **kwargs): |
128 |
|
|
""" Destroy the format. """ |
129 |
|
|
log_method_call(self, device=self.device, |
130 |
|
|
type=self.type, status=self.status) |
131 |
|
|
if not self.exists: |
132 |
|
|
raise PhysicalVolumeError("format has not been created") |
133 |
|
|
|
134 |
|
|
if self.status: |
135 |
|
|
raise PhysicalVolumeError("device is active") |
136 |
|
|
|
137 |
|
|
# FIXME: verify path exists? |
138 |
|
|
try: |
139 |
|
|
lvm.pvremove(self.device) |
140 |
|
|
except LVMError: |
141 |
|
|
DeviceFormat.destroy(self, *args, **kwargs) |
142 |
|
|
|
143 |
|
|
self.exists = False |
144 |
|
|
self.notifyKernel() |
145 |
|
|
|
146 |
|
|
@property |
147 |
|
|
def status(self): |
148 |
|
|
# XXX hack |
149 |
|
|
return (self.exists and self.vgName and |
150 |
|
|
os.path.isdir("/dev/mapper/%s" % self.vgName)) |
151 |
|
|
|
152 |
|
|
def writeKS(self, f): |
153 |
|
|
f.write("pv.%s" % self.majorminor) |
154 |
|
|
|
155 |
|
|
register_device_format(LVMPhysicalVolume) |
156 |
|
|
|