2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2008, 2012 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 KickstartCommand
21 from pykickstart
.constants
import AUTOPART_TYPE_BTRFS
, AUTOPART_TYPE_LVM
, AUTOPART_TYPE_LVM_THINP
, AUTOPART_TYPE_PLAIN
22 from pykickstart
.errors
import KickstartParseError
, KickstartValueError
, formatErrorMsg
23 from pykickstart
.options
import KSOptionParser
26 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
28 class FC3_AutoPart(KickstartCommand
):
29 removedKeywords
= KickstartCommand
.removedKeywords
30 removedAttrs
= KickstartCommand
.removedAttrs
32 def __init__(self
, writePriority
=100, *args
, **kwargs
):
33 KickstartCommand
.__init
__(self
, writePriority
, *args
, **kwargs
)
34 self
.autopart
= kwargs
.get("autopart", False)
37 retval
= KickstartCommand
.__str
__(self
)
40 retval
+= "autopart\n"
44 def parse(self
, args
):
46 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_("Kickstart command %s does not take any arguments") % "autopart"))
51 class F9_AutoPart(FC3_AutoPart
):
52 removedKeywords
= FC3_AutoPart
.removedKeywords
53 removedAttrs
= FC3_AutoPart
.removedAttrs
55 def __init__(self
, writePriority
=100, *args
, **kwargs
):
56 FC3_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
57 self
.encrypted
= kwargs
.get("encrypted", False)
58 self
.passphrase
= kwargs
.get("passphrase", "")
60 self
.op
= self
._getParser
()
63 retval
= KickstartCommand
.__str
__(self
)
71 retval
+= " --encrypted"
73 if self
.passphrase
!= "":
74 retval
+= " --passphrase=\"%s\""% self
.passphrase
81 op
.add_option("--encrypted", action
="store_true", default
=False)
82 op
.add_option("--passphrase")
85 def parse(self
, args
):
86 (opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
87 # Rely on any error handling from baseclass
88 FC3_AutoPart
.parse(self
, extra
)
90 self
._setToSelf
(self
.op
, opts
)
93 class F12_AutoPart(F9_AutoPart
):
94 removedKeywords
= F9_AutoPart
.removedKeywords
95 removedAttrs
= F9_AutoPart
.removedAttrs
97 def __init__(self
, writePriority
=100, *args
, **kwargs
):
98 F9_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
100 self
.escrowcert
= kwargs
.get("escrowcert", "")
101 self
.backuppassphrase
= kwargs
.get("backuppassphrase", False)
104 retval
= F9_AutoPart
.__str
__(self
)
106 if not self
.autopart
:
109 if self
.encrypted
and self
.escrowcert
!= "":
110 retval
= retval
.strip()
112 retval
+= " --escrowcert=\"%s\"" % self
.escrowcert
114 if self
.backuppassphrase
:
115 retval
+= " --backuppassphrase"
121 def _getParser(self
):
122 op
= F9_AutoPart
._getParser
(self
)
123 op
.add_option("--escrowcert")
124 op
.add_option("--backuppassphrase", action
="store_true", default
=False)
127 class RHEL6_AutoPart(F12_AutoPart
):
128 removedKeywords
= F12_AutoPart
.removedKeywords
129 removedAttrs
= F12_AutoPart
.removedAttrs
131 def __init__(self
, writePriority
=100, *args
, **kwargs
):
132 F12_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
133 self
.cipher
= kwargs
.get("cipher", "")
136 retval
= F12_AutoPart
.__str
__(self
)
137 if not self
.autopart
:
140 if self
.encrypted
and self
.cipher
:
141 # remove any trailing newline
142 retval
= retval
.strip()
143 retval
+= " --cipher=\"%s\"" % self
.cipher
148 def _getParser(self
):
149 op
= F12_AutoPart
._getParser
(self
)
150 op
.add_option("--cipher")
153 def parse(self
, args
):
154 # call the overriden command to do it's job first
155 retval
= F12_AutoPart
.parse(self
, args
)
157 # Using autopart together with other partitioning command such as
158 # part/partition, raid, logvol or volgroup can lead to hard to debug
159 # behavior that might among other result into an unbootable system.
161 # Therefore if any of those commands is detected in the same kickstart
162 # together with autopart, an error is raised and installation is
164 conflicting_command
= ""
166 # seen indicates that the corresponding
167 # command has been seen in kickstart
168 if self
.handler
.partition
.seen
:
169 conflicting_command
= "part/partition"
170 elif self
.handler
.raid
.seen
:
171 conflicting_command
= "raid"
172 elif self
.handler
.volgroup
.seen
:
173 conflicting_command
= "volgroup"
174 elif self
.handler
.logvol
.seen
:
175 conflicting_command
= "logvol"
177 if conflicting_command
:
178 # allow for translation of the error message
179 errorMsg
= _("The %s and autopart commands can't be used at the same time") % \
181 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))
185 class F16_AutoPart(F12_AutoPart
):
186 removedKeywords
= F12_AutoPart
.removedKeywords
187 removedAttrs
= F12_AutoPart
.removedAttrs
189 def __init__(self
, writePriority
=100, *args
, **kwargs
):
190 F12_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
191 self
.lvm
= kwargs
.get("lvm", True)
194 retval
= F12_AutoPart
.__str
__(self
)
195 if not self
.autopart
:
198 # If requested, disable LVM autopart
200 # remove any trailing newline
201 retval
= retval
.strip()
207 def _getParser(self
):
208 op
= F12_AutoPart
._getParser
(self
)
209 op
.add_option("--nolvm", action
="store_false", dest
="lvm",
213 class F17_AutoPart(F16_AutoPart
):
214 def __init__(self
, writePriority
=100, *args
, **kwargs
):
215 F16_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
216 self
.type = kwargs
.get("type", None)
217 self
.typeMap
= { "lvm": AUTOPART_TYPE_LVM
,
218 "btrfs": AUTOPART_TYPE_BTRFS
,
219 "plain": AUTOPART_TYPE_PLAIN
,
220 "partition": AUTOPART_TYPE_PLAIN
}
222 def _typeAsStr(self
):
225 for (key
, value
) in list(self
.typeMap
.items()):
226 if value
== self
.type:
230 if retval
== "partition":
236 retval
= F16_AutoPart
.__str
__(self
)
237 if not self
.autopart
:
240 ty
= self
._typeAsStr
()
242 # remove any trailing newline
243 retval
= retval
.strip()
244 retval
+= " --type=%s\n" % ty
248 def _getParser(self
):
249 def type_cb(option
, opt_str
, value
, parser
):
250 if value
.lower() in self
.typeMap
:
251 parser
.values
.ensure_value(option
.dest
,
252 self
.typeMap
[value
.lower()])
254 def nolvm_cb(option
, opt_str
, value
, parser
):
255 parser
.values
.ensure_value(option
.dest
, AUTOPART_TYPE_PLAIN
)
257 op
= F16_AutoPart
._getParser
(self
)
258 op
.add_option("--nolvm", action
="callback", callback
=nolvm_cb
,
259 dest
="type", nargs
=0)
261 op
.add_option("--type", action
="callback", callback
=type_cb
,
262 dest
="type", nargs
=1, type="string")
265 def parse(self
, args
):
266 (opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
267 # Rely on any error handling from baseclass
268 F16_AutoPart
.parse(self
, extra
)
270 self
._setToSelf
(self
.op
, opts
)
272 # make this always True to avoid writing --nolvm
277 class F18_AutoPart(F17_AutoPart
):
278 removedKeywords
= F17_AutoPart
.removedKeywords
279 removedAttrs
= F17_AutoPart
.removedAttrs
281 def __init__(self
, writePriority
=100, *args
, **kwargs
):
282 F17_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
283 self
.cipher
= kwargs
.get("cipher", "")
286 retval
= F17_AutoPart
.__str
__(self
)
287 if not self
.autopart
:
290 if self
.encrypted
and self
.cipher
:
291 # remove any trailing newline
292 retval
= retval
.strip()
293 retval
+= " --cipher=\"%s\"" % self
.cipher
298 def _getParser(self
):
299 op
= F17_AutoPart
._getParser
(self
)
300 op
.add_option("--cipher")
304 class F20_AutoPart(F18_AutoPart
):
305 def __init__(self
, writePriority
=100, *args
, **kwargs
):
306 F18_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
307 self
.typeMap
["thinp"] = AUTOPART_TYPE_LVM_THINP
309 def parse(self
, args
):
310 # call the overriden command to do it's job first
311 retval
= F18_AutoPart
.parse(self
, args
)
313 # Using autopart together with other partitioning command such as
314 # part/partition, raid, logvol or volgroup can lead to hard to debug
315 # behavior that might among other result into an unbootable system.
317 # Therefore if any of those commands is detected in the same kickstart
318 # together with autopart, an error is raised and installation is
320 conflicting_command
= ""
322 # seen indicates that the corresponding
323 # command has been seen in kickstart
324 if self
.handler
.partition
.seen
:
325 conflicting_command
= "part/partition"
326 elif self
.handler
.raid
.seen
:
327 conflicting_command
= "raid"
328 elif self
.handler
.volgroup
.seen
:
329 conflicting_command
= "volgroup"
330 elif self
.handler
.logvol
.seen
:
331 conflicting_command
= "logvol"
333 if conflicting_command
:
334 # allow for translation of the error message
335 errorMsg
= _("The %s and autopart commands can't be used at the same time") % \
337 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))
340 class F21_AutoPart(F20_AutoPart
):
341 removedKeywords
= F20_AutoPart
.removedKeywords
342 removedAttrs
= F20_AutoPart
.removedAttrs
344 def __init__(self
, writePriority
=100, *args
, **kwargs
):
345 F20_AutoPart
.__init
__(self
, writePriority
=writePriority
, *args
, **kwargs
)
346 self
.fstype
= kwargs
.get("fstype", "")
349 retval
= F20_AutoPart
.__str
__(self
)
350 if not self
.autopart
:
354 # remove any trailing newline
355 retval
= retval
.strip()
356 retval
+= " --fstype=%s" % self
.fstype
361 def _getParser(self
):
362 op
= F20_AutoPart
._getParser
(self
)
363 op
.add_option("--fstype")
366 def parse(self
, args
):
367 # call the overriden command to do it's job first
368 retval
= F20_AutoPart
.parse(self
, args
)
370 # btrfs is not a valid filesystem type
371 if self
.fstype
== "btrfs":
372 raise KickstartParseError(formatErrorMsg(self
.lineno
,
373 msg
=_("autopart --fstype=btrfs is not valid fstype, use --type=btrfs instead")))
375 if self
._typeAsStr
() == "btrfs" and self
.fstype
:
376 raise KickstartParseError(formatErrorMsg(self
.lineno
,
377 msg
=_("autopart --fstype cannot be used with --type=btrfs")))