2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2008 Red Hat, Inc.
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
20 from pykickstart.base import *
21 from pykickstart.errors import *
22 from pykickstart.options import *
26 _ = lambda x: gettext.ldgettext("pykickstart", x)
28 class FC3_LogVolData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
32 def __init__(self, *args, **kwargs):
33 BaseData.__init__(self, *args, **kwargs)
34 self.fstype = kwargs.get("fstype", "")
35 self.grow = kwargs.get("grow", False)
36 self.maxSizeMB = kwargs.get("maxSizeMB", 0)
37 self.name = kwargs.get("name", "")
38 self.format = kwargs.get("format", True)
39 self.percent = kwargs.get("percent", 0)
40 self.recommended = kwargs.get("recommended", False)
41 self.size = kwargs.get("size", None)
42 self.preexist = kwargs.get("preexist", False)
43 self.vgname = kwargs.get("vgname", "")
44 self.mountpoint = kwargs.get("mountpoint", "")
47 return self.vgname == y.vgname and self.name == y.name
49 def _getArgsAsStr(self):
53 retval += " --fstype=\"%s\"" % self.fstype
56 if self.maxSizeMB > 0:
57 retval += " --maxsize=%d" % self.maxSizeMB
59 retval += " --noformat"
61 retval += " --percent=%d" % self.percent
63 retval += " --recommended"
65 retval += " --size=%d" % self.size
67 retval += " --useexisting"
72 retval = BaseData.__str__(self)
73 retval += "logvol %s %s --name=%s --vgname=%s\n" % (self.mountpoint, self._getArgsAsStr(), self.name, self.vgname)
76 class FC4_LogVolData(FC3_LogVolData):
77 removedKeywords = FC3_LogVolData.removedKeywords
78 removedAttrs = FC3_LogVolData.removedAttrs
80 def __init__(self, *args, **kwargs):
81 FC3_LogVolData.__init__(self, *args, **kwargs)
82 self.bytesPerInode = kwargs.get("bytesPerInode", 4096)
83 self.fsopts = kwargs.get("fsopts", "")
85 def _getArgsAsStr(self):
86 retval = FC3_LogVolData._getArgsAsStr(self)
88 if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0:
89 retval += " --bytes-per-inode=%d" % self.bytesPerInode
91 retval += " --fsoptions=\"%s\"" % self.fsopts
95 class RHEL5_LogVolData(FC4_LogVolData):
96 removedKeywords = FC4_LogVolData.removedKeywords
97 removedAttrs = FC4_LogVolData.removedAttrs
99 def __init__(self, *args, **kwargs):
100 FC4_LogVolData.__init__(self, *args, **kwargs)
101 self.encrypted = kwargs.get("encrypted", False)
102 self.passphrase = kwargs.get("passphrase", "")
104 def _getArgsAsStr(self):
105 retval = FC4_LogVolData._getArgsAsStr(self)
108 retval += " --encrypted"
110 if self.passphrase != "":
111 retval += " --passphrase=\"%s\"" % self.passphrase
115 class F9_LogVolData(FC4_LogVolData):
116 removedKeywords = FC4_LogVolData.removedKeywords + ["bytesPerInode"]
117 removedAttrs = FC4_LogVolData.removedAttrs + ["bytesPerInode"]
119 def __init__(self, *args, **kwargs):
120 FC4_LogVolData.__init__(self, *args, **kwargs)
121 self.deleteRemovedAttrs()
123 self.fsopts = kwargs.get("fsopts", "")
124 self.fsprofile = kwargs.get("fsprofile", "")
125 self.encrypted = kwargs.get("encrypted", False)
126 self.passphrase = kwargs.get("passphrase", "")
128 def _getArgsAsStr(self):
129 retval = FC4_LogVolData._getArgsAsStr(self)
131 if self.fsprofile != "":
132 retval += " --fsprofile=\"%s\"" % self.fsprofile
134 retval += " --encrypted"
136 if self.passphrase != "":
137 retval += " --passphrase=\"%s\"" % self.passphrase
141 class F12_LogVolData(F9_LogVolData):
142 removedKeywords = F9_LogVolData.removedKeywords
143 removedAttrs = F9_LogVolData.removedAttrs
145 def __init__(self, *args, **kwargs):
146 F9_LogVolData.__init__(self, *args, **kwargs)
147 self.deleteRemovedAttrs()
149 self.escrowcert = kwargs.get("escrowcert", "")
150 self.backuppassphrase = kwargs.get("backuppassphrase", False)
152 def _getArgsAsStr(self):
153 retval = F9_LogVolData._getArgsAsStr(self)
155 if self.encrypted and self.escrowcert != "":
156 retval += " --escrowcert=\"%s\"" % self.escrowcert
158 if self.backuppassphrase:
159 retval += " --backuppassphrase"
163 F14_LogVolData = F12_LogVolData
165 class F15_LogVolData(F14_LogVolData):
166 removedKeywords = F14_LogVolData.removedKeywords
167 removedAttrs = F14_LogVolData.removedAttrs
169 def __init__(self, *args, **kwargs):
170 F14_LogVolData.__init__(self, *args, **kwargs)
171 self.label = kwargs.get("label", "")
173 def _getArgsAsStr(self):
174 retval = F14_LogVolData._getArgsAsStr(self)
177 retval += " --label=\"%s\"" % self.label
181 class FC3_LogVol(KickstartCommand):
182 removedKeywords = KickstartCommand.removedKeywords
183 removedAttrs = KickstartCommand.removedAttrs
185 def __init__(self, writePriority=133, *args, **kwargs):
186 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
187 self.op = self._getParser()
189 self.lvList = kwargs.get("lvList", [])
194 for part in self.lvList:
195 retval += part.__str__()
199 def _getParser(self):
200 def lv_cb (option, opt_str, value, parser):
201 parser.values.format = False
202 parser.values.preexist = True
204 op = KSOptionParser()
205 op.add_option("--fstype", dest="fstype")
206 op.add_option("--grow", dest="grow", action="store_true",
208 op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int",
210 op.add_option("--name", dest="name", required=1)
211 op.add_option("--noformat", action="callback", callback=lv_cb,
212 dest="format", default=True, nargs=0)
213 op.add_option("--percent", dest="percent", action="store", type="int",
215 op.add_option("--recommended", dest="recommended", action="store_true",
217 op.add_option("--size", dest="size", action="store", type="int",
219 op.add_option("--useexisting", dest="preexist", action="store_true",
221 op.add_option("--vgname", dest="vgname", required=1)
224 def parse(self, args):
225 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
228 raise KickstartValueError (formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "logvol"))
230 lvd = self.handler.LogVolData()
231 self._setToObj(self.op, opts, lvd)
232 lvd.lineno = self.lineno
233 lvd.mountpoint=extra[0]
235 # Check for duplicates in the data list.
236 if lvd in self.dataList():
237 warnings.warn(_("A logical volume with the name %s has already been defined in volume group %s.") % (lvd.device, lvd.vgname))
244 class FC4_LogVol(FC3_LogVol):
245 removedKeywords = FC3_LogVol.removedKeywords
246 removedAttrs = FC3_LogVol.removedAttrs
248 def _getParser(self):
249 op = FC3_LogVol._getParser(self)
250 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
252 op.add_option("--fsoptions", dest="fsopts")
255 class RHEL5_LogVol(FC4_LogVol):
256 removedKeywords = FC4_LogVol.removedKeywords
257 removedAttrs = FC4_LogVol.removedAttrs
259 def _getParser(self):
260 op = FC4_LogVol._getParser(self)
261 op.add_option("--encrypted", action="store_true", default=False)
262 op.add_option("--passphrase")
265 class F9_LogVol(FC4_LogVol):
266 removedKeywords = FC4_LogVol.removedKeywords
267 removedAttrs = FC4_LogVol.removedAttrs
269 def _getParser(self):
270 op = FC4_LogVol._getParser(self)
271 op.add_option("--bytes-per-inode", deprecated=1)
272 op.add_option("--fsprofile", dest="fsprofile", action="store",
273 type="string", nargs=1)
274 op.add_option("--encrypted", action="store_true", default=False)
275 op.add_option("--passphrase")
278 class F12_LogVol(F9_LogVol):
279 removedKeywords = F9_LogVol.removedKeywords
280 removedAttrs = F9_LogVol.removedAttrs
282 def _getParser(self):
283 op = F9_LogVol._getParser(self)
284 op.add_option("--escrowcert")
285 op.add_option("--backuppassphrase", action="store_true", default=False)
288 class F14_LogVol(F12_LogVol):
289 removedKeywords = F12_LogVol.removedKeywords
290 removedAttrs = F12_LogVol.removedAttrs
292 def _getParser(self):
293 op = F12_LogVol._getParser(self)
294 op.remove_option("--bytes-per-inode")
297 class F15_LogVol(F14_LogVol):
298 removedKeywords = F14_LogVol.removedKeywords
299 removedAttrs = F14_LogVol.removedAttrs
301 def _getParser(self):
302 op = F14_LogVol._getParser(self)
303 op.add_option("--label")