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 BaseData
, KickstartCommand
21 from pykickstart
.errors
import KickstartParseError
, KickstartValueError
, formatErrorMsg
22 from pykickstart
.options
import KSOptionParser
26 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
28 class FC3_PartData(BaseData
):
29 removedKeywords
= BaseData
.removedKeywords
30 removedAttrs
= BaseData
.removedAttrs
32 def __init__(self
, *args
, **kwargs
):
33 BaseData
.__init
__(self
, *args
, **kwargs
)
34 self
.active
= kwargs
.get("active", False)
35 self
.primOnly
= kwargs
.get("primOnly", False)
36 self
.end
= kwargs
.get("end", 0)
37 self
.fstype
= kwargs
.get("fstype", "")
38 self
.grow
= kwargs
.get("grow", False)
39 self
.maxSizeMB
= kwargs
.get("maxSizeMB", 0)
40 self
.format
= kwargs
.get("format", True)
41 self
.onbiosdisk
= kwargs
.get("onbiosdisk", "")
42 self
.disk
= kwargs
.get("disk", "")
43 self
.onPart
= kwargs
.get("onPart", "")
44 self
.recommended
= kwargs
.get("recommended", False)
45 self
.size
= kwargs
.get("size", None)
46 self
.start
= kwargs
.get("start", 0)
47 self
.mountpoint
= kwargs
.get("mountpoint", "")
53 return self
.mountpoint
== y
.mountpoint
58 def _getArgsAsStr(self
):
64 retval
+= " --asprimary"
65 if hasattr(self
, "end") and self
.end
!= 0:
66 retval
+= " --end=%s" % self
.end
68 retval
+= " --fstype=\"%s\"" % self
.fstype
71 if self
.maxSizeMB
> 0:
72 retval
+= " --maxsize=%d" % self
.maxSizeMB
74 retval
+= " --noformat"
75 if self
.onbiosdisk
!= "":
76 retval
+= " --onbiosdisk=%s" % self
.onbiosdisk
78 retval
+= " --ondisk=%s" % self
.disk
80 retval
+= " --onpart=%s" % self
.onPart
82 retval
+= " --recommended"
83 if self
.size
and self
.size
!= 0:
84 retval
+= " --size=%s" % self
.size
85 if hasattr(self
, "start") and self
.start
!= 0:
86 retval
+= " --start=%s" % self
.start
91 retval
= BaseData
.__str
__(self
)
92 retval
+= "part %s%s\n" % (self
.mountpoint
, self
._getArgsAsStr
())
95 class FC4_PartData(FC3_PartData
):
96 removedKeywords
= FC3_PartData
.removedKeywords
97 removedAttrs
= FC3_PartData
.removedAttrs
99 def __init__(self
, *args
, **kwargs
):
100 FC3_PartData
.__init
__(self
, *args
, **kwargs
)
101 self
.bytesPerInode
= kwargs
.get("bytesPerInode", 4096)
102 self
.fsopts
= kwargs
.get("fsopts", "")
103 self
.label
= kwargs
.get("label", "")
105 def _getArgsAsStr(self
):
106 retval
= FC3_PartData
._getArgsAsStr
(self
)
108 if hasattr(self
, "bytesPerInode") and self
.bytesPerInode
!= 0:
109 retval
+= " --bytes-per-inode=%d" % self
.bytesPerInode
110 if self
.fsopts
!= "":
111 retval
+= " --fsoptions=\"%s\"" % self
.fsopts
113 retval
+= " --label=%s" % self
.label
117 class RHEL5_PartData(FC4_PartData
):
118 removedKeywords
= FC4_PartData
.removedKeywords
119 removedAttrs
= FC4_PartData
.removedAttrs
121 def __init__(self
, *args
, **kwargs
):
122 FC4_PartData
.__init
__(self
, *args
, **kwargs
)
123 self
.encrypted
= kwargs
.get("encrypted", False)
124 self
.passphrase
= kwargs
.get("passphrase", "")
126 def _getArgsAsStr(self
):
127 retval
= FC4_PartData
._getArgsAsStr
(self
)
130 retval
+= " --encrypted"
132 if self
.passphrase
!= "":
133 retval
+= " --passphrase=\"%s\"" % self
.passphrase
137 class F9_PartData(FC4_PartData
):
138 removedKeywords
= FC4_PartData
.removedKeywords
+ ["bytesPerInode"]
139 removedAttrs
= FC4_PartData
.removedAttrs
+ ["bytesPerInode"]
141 def __init__(self
, *args
, **kwargs
):
142 FC4_PartData
.__init
__(self
, *args
, **kwargs
)
143 self
.deleteRemovedAttrs()
145 self
.fsopts
= kwargs
.get("fsopts", "")
146 self
.label
= kwargs
.get("label", "")
147 self
.fsprofile
= kwargs
.get("fsprofile", "")
148 self
.encrypted
= kwargs
.get("encrypted", False)
149 self
.passphrase
= kwargs
.get("passphrase", "")
151 def _getArgsAsStr(self
):
152 retval
= FC4_PartData
._getArgsAsStr
(self
)
154 if self
.fsprofile
!= "":
155 retval
+= " --fsprofile=\"%s\"" % self
.fsprofile
157 retval
+= " --encrypted"
159 if self
.passphrase
!= "":
160 retval
+= " --passphrase=\"%s\"" % self
.passphrase
164 class F11_PartData(F9_PartData
):
165 removedKeywords
= F9_PartData
.removedKeywords
+ ["start", "end"]
166 removedAttrs
= F9_PartData
.removedAttrs
+ ["start", "end"]
168 class F12_PartData(F11_PartData
):
169 removedKeywords
= F11_PartData
.removedKeywords
170 removedAttrs
= F11_PartData
.removedAttrs
172 def __init__(self
, *args
, **kwargs
):
173 F11_PartData
.__init
__(self
, *args
, **kwargs
)
175 self
.escrowcert
= kwargs
.get("escrowcert", "")
176 self
.backuppassphrase
= kwargs
.get("backuppassphrase", False)
178 def _getArgsAsStr(self
):
179 retval
= F11_PartData
._getArgsAsStr
(self
)
181 if self
.encrypted
and self
.escrowcert
!= "":
182 retval
+= " --escrowcert=\"%s\"" % self
.escrowcert
184 if self
.backuppassphrase
:
185 retval
+= " --backuppassphrase"
189 class RHEL6_PartData(F12_PartData
):
190 removedKeywords
= F12_PartData
.removedKeywords
191 removedAttrs
= F12_PartData
.removedAttrs
193 def __init__(self
, *args
, **kwargs
):
194 F12_PartData
.__init
__(self
, *args
, **kwargs
)
196 self
.cipher
= kwargs
.get("cipher", "")
197 self
.hibernation
= kwargs
.get("hibernation", False)
199 def _getArgsAsStr(self
):
200 retval
= F12_PartData
._getArgsAsStr
(self
)
202 if self
.encrypted
and self
.cipher
:
203 retval
+= " --cipher=\"%s\"" % self
.cipher
205 retval
+= " --hibernation"
209 F14_PartData
= F12_PartData
211 class F17_PartData(F14_PartData
):
212 def __init__(self
, *args
, **kwargs
):
213 F14_PartData
.__init
__(self
, *args
, **kwargs
)
215 self
.resize
= kwargs
.get("resize", False)
217 def _getArgsAsStr(self
):
218 retval
= F14_PartData
._getArgsAsStr
(self
)
221 retval
+= " --resize"
225 class F18_PartData(F17_PartData
):
226 def __init__(self
, *args
, **kwargs
):
227 F17_PartData
.__init
__(self
, *args
, **kwargs
)
229 self
.hibernation
= kwargs
.get("hibernation", False)
230 self
.cipher
= kwargs
.get("cipher", "")
232 def _getArgsAsStr(self
):
233 retval
= F17_PartData
._getArgsAsStr
(self
)
236 retval
+= " --hibernation"
238 if self
.encrypted
and self
.cipher
:
239 retval
+= " --cipher=\"%s\"" % self
.cipher
243 class FC3_Partition(KickstartCommand
):
244 removedKeywords
= KickstartCommand
.removedKeywords
245 removedAttrs
= KickstartCommand
.removedAttrs
247 def __init__(self
, writePriority
=130, *args
, **kwargs
):
248 KickstartCommand
.__init
__(self
, writePriority
, *args
, **kwargs
)
249 self
.op
= self
._getParser
()
251 self
.partitions
= kwargs
.get("partitions", [])
256 for part
in self
.partitions
:
257 retval
+= part
.__str
__()
260 return "# Disk partitioning information\n" + retval
264 def _getParser(self
):
265 def part_cb (option
, opt_str
, value
, parser
):
266 if value
.startswith("/dev/"):
267 parser
.values
.ensure_value(option
.dest
, value
[5:])
269 parser
.values
.ensure_value(option
.dest
, value
)
271 op
= KSOptionParser()
272 op
.add_option("--active", dest
="active", action
="store_true",
274 op
.add_option("--asprimary", dest
="primOnly", action
="store_true",
276 op
.add_option("--end", dest
="end", action
="store", type="int",
278 op
.add_option("--fstype", "--type", dest
="fstype")
279 op
.add_option("--grow", dest
="grow", action
="store_true", default
=False)
280 op
.add_option("--maxsize", dest
="maxSizeMB", action
="store", type="int",
282 op
.add_option("--noformat", dest
="format", action
="store_false",
284 op
.add_option("--onbiosdisk", dest
="onbiosdisk")
285 op
.add_option("--ondisk", "--ondrive", dest
="disk")
286 op
.add_option("--onpart", "--usepart", dest
="onPart", action
="callback",
287 callback
=part_cb
, nargs
=1, type="string")
288 op
.add_option("--recommended", dest
="recommended", action
="store_true",
290 op
.add_option("--size", dest
="size", action
="store", type="int",
292 op
.add_option("--start", dest
="start", action
="store", type="int",
296 def parse(self
, args
):
297 (opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
300 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_("Mount point required for %s") % "partition"))
302 pd
= self
.handler
.PartData()
303 self
._setToObj
(self
.op
, opts
, pd
)
304 pd
.lineno
= self
.lineno
305 pd
.mountpoint
=extra
[0]
307 # Check for duplicates in the data list.
308 if pd
in self
.dataList():
309 warnings
.warn(_("A partition with the mountpoint %s has already been defined.") % pd
.mountpoint
)
314 return self
.partitions
316 class FC4_Partition(FC3_Partition
):
317 removedKeywords
= FC3_Partition
.removedKeywords
318 removedAttrs
= FC3_Partition
.removedAttrs
320 def __init__(self
, writePriority
=130, *args
, **kwargs
):
321 FC3_Partition
.__init
__(self
, writePriority
, *args
, **kwargs
)
323 # pylint: disable=unused-variable
324 def part_cb (option
, opt_str
, value
, parser
):
325 if value
.startswith("/dev/"):
326 parser
.values
.ensure_value(option
.dest
, value
[5:])
328 parser
.values
.ensure_value(option
.dest
, value
)
330 def _getParser(self
):
331 op
= FC3_Partition
._getParser
(self
)
332 op
.add_option("--bytes-per-inode", dest
="bytesPerInode", action
="store",
334 op
.add_option("--fsoptions", dest
="fsopts")
335 op
.add_option("--label", dest
="label")
338 class RHEL5_Partition(FC4_Partition
):
339 removedKeywords
= FC4_Partition
.removedKeywords
340 removedAttrs
= FC4_Partition
.removedAttrs
342 def __init__(self
, writePriority
=130, *args
, **kwargs
):
343 FC4_Partition
.__init
__(self
, writePriority
, *args
, **kwargs
)
345 # pylint: disable=unused-variable
346 def part_cb (option
, opt_str
, value
, parser
):
347 if value
.startswith("/dev/"):
348 parser
.values
.ensure_value(option
.dest
, value
[5:])
350 parser
.values
.ensure_value(option
.dest
, value
)
352 def _getParser(self
):
353 op
= FC4_Partition
._getParser
(self
)
354 op
.add_option("--encrypted", action
="store_true", default
=False)
355 op
.add_option("--passphrase")
358 class F9_Partition(FC4_Partition
):
359 removedKeywords
= FC4_Partition
.removedKeywords
360 removedAttrs
= FC4_Partition
.removedAttrs
362 def __init__(self
, writePriority
=130, *args
, **kwargs
):
363 FC4_Partition
.__init
__(self
, writePriority
, *args
, **kwargs
)
365 # pylint: disable=unused-variable
366 def part_cb (option
, opt_str
, value
, parser
):
367 if value
.startswith("/dev/"):
368 parser
.values
.ensure_value(option
.dest
, value
[5:])
370 parser
.values
.ensure_value(option
.dest
, value
)
372 def _getParser(self
):
373 op
= FC4_Partition
._getParser
(self
)
374 op
.add_option("--bytes-per-inode", deprecated
=1)
375 op
.add_option("--fsprofile")
376 op
.add_option("--encrypted", action
="store_true", default
=False)
377 op
.add_option("--passphrase")
380 class F11_Partition(F9_Partition
):
381 removedKeywords
= F9_Partition
.removedKeywords
382 removedAttrs
= F9_Partition
.removedAttrs
384 def _getParser(self
):
385 op
= F9_Partition
._getParser
(self
)
386 op
.add_option("--start", deprecated
=1)
387 op
.add_option("--end", deprecated
=1)
390 class F12_Partition(F11_Partition
):
391 removedKeywords
= F11_Partition
.removedKeywords
392 removedAttrs
= F11_Partition
.removedAttrs
394 def _getParser(self
):
395 op
= F11_Partition
._getParser
(self
)
396 op
.add_option("--escrowcert")
397 op
.add_option("--backuppassphrase", action
="store_true", default
=False)
400 class RHEL6_Partition(F12_Partition
):
401 removedKeywords
= F12_Partition
.removedKeywords
402 removedAttrs
= F12_Partition
.removedAttrs
404 def _getParser(self
):
405 op
= F12_Partition
._getParser
(self
)
406 op
.add_option("--cipher")
407 op
.add_option("--hibernation", dest
="hibernation", action
="store_true",
411 def parse(self
, args
):
412 # first call the overriden command
413 retval
= F12_Partition
.parse(self
, args
)
414 # the part command can't be used together with the autopart command
415 # due to the hard to debug behavior their combination introduces
416 if self
.handler
.autopart
.seen
:
417 errorMsg
= _("The part/partition and autopart commands can't be used at the same time")
418 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))
421 class F14_Partition(F12_Partition
):
422 removedKeywords
= F12_Partition
.removedKeywords
423 removedAttrs
= F12_Partition
.removedAttrs
425 def _getParser(self
):
426 op
= F12_Partition
._getParser
(self
)
427 op
.remove_option("--bytes-per-inode")
428 op
.remove_option("--start")
429 op
.remove_option("--end")
432 class F17_Partition(F14_Partition
):
433 def _getParser(self
):
434 op
= F14_Partition
._getParser
(self
)
435 op
.add_option("--resize", action
="store_true", default
=False)
438 def parse(self
, args
):
439 retval
= F14_Partition
.parse(self
, args
)
441 if retval
.resize
and not retval
.onPart
:
442 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=_("--resize can only be used in conjunction with --onpart")))
444 if retval
.resize
and not retval
.size
:
445 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=_("--resize requires --size to specify new size")))
449 class F18_Partition(F17_Partition
):
450 def _getParser(self
):
451 op
= F17_Partition
._getParser
(self
)
452 op
.add_option("--hibernation", dest
="hibernation", action
="store_true", default
=False)
453 op
.add_option("--cipher")
457 class F20_Partition(F18_Partition
):
458 def parse(self
, args
):
459 # first call the overriden command
460 retval
= F18_Partition
.parse(self
, args
)
461 # the part command can't be used together with the autopart command
462 # due to the hard to debug behavior their combination introduces
463 if self
.handler
.autopart
.seen
:
464 errorMsg
= _("The part/partition and autopart commands can't be used at the same time")
465 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))
467 # when using tmpfs, grow is not suported
468 if retval
.fstype
== "tmpfs":
469 if retval
.grow
or retval
.maxSizeMB
!= 0:
470 errorMsg
= _("The --fstype=tmpfs option can't be used together with --grow or --maxsize")
471 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))