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_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", "")
51 return self.mountpoint == y.mountpoint
55 def _getArgsAsStr(self):
61 retval += " --asprimary"
62 if hasattr(self, "end") and self.end != 0:
63 retval += " --end=%s" % self.end
65 retval += " --fstype=\"%s\"" % self.fstype
68 if self.maxSizeMB > 0:
69 retval += " --maxsize=%d" % self.maxSizeMB
71 retval += " --noformat"
72 if self.onbiosdisk != "":
73 retval += " --onbiosdisk=%s" % self.onbiosdisk
75 retval += " --ondisk=%s" % self.disk
77 retval += " --onpart=%s" % self.onPart
79 retval += " --recommended"
80 if self.size and self.size != 0:
81 retval += " --size=%s" % self.size
82 if hasattr(self, "start") and self.start != 0:
83 retval += " --start=%s" % self.start
88 retval = BaseData.__str__(self)
90 mountpoint_str = "%s" % self.mountpoint
92 mountpoint_str = "(No mount point)"
93 retval += "part %s%s\n" % (mountpoint_str, self._getArgsAsStr())
96 class FC4_PartData(FC3_PartData):
97 removedKeywords = FC3_PartData.removedKeywords
98 removedAttrs = FC3_PartData.removedAttrs
100 def __init__(self, *args, **kwargs):
101 FC3_PartData.__init__(self, *args, **kwargs)
102 self.bytesPerInode = kwargs.get("bytesPerInode", 4096)
103 self.fsopts = kwargs.get("fsopts", "")
104 self.label = kwargs.get("label", "")
105 self.fslabel = kwargs.get("fslabel", "")
107 def _getArgsAsStr(self):
108 retval = FC3_PartData._getArgsAsStr(self)
110 if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0:
111 retval += " --bytes-per-inode=%d" % self.bytesPerInode
112 if self.fsopts != "":
113 retval += " --fsoptions=\"%s\"" % self.fsopts
115 retval += " --label=%s" % self.label
116 if self.fslabel != "":
117 retval += " --fslabel=%s" % self.fslabel
121 class RHEL5_PartData(FC4_PartData):
122 removedKeywords = FC4_PartData.removedKeywords
123 removedAttrs = FC4_PartData.removedAttrs
125 def __init__(self, *args, **kwargs):
126 FC4_PartData.__init__(self, *args, **kwargs)
127 self.encrypted = kwargs.get("encrypted", False)
128 self.passphrase = kwargs.get("passphrase", "")
130 def _getArgsAsStr(self):
131 retval = FC4_PartData._getArgsAsStr(self)
134 retval += " --encrypted"
136 if self.passphrase != "":
137 retval += " --passphrase=\"%s\"" % self.passphrase
141 class F9_PartData(FC4_PartData):
142 removedKeywords = FC4_PartData.removedKeywords + ["bytesPerInode"]
143 removedAttrs = FC4_PartData.removedAttrs + ["bytesPerInode"]
145 def __init__(self, *args, **kwargs):
146 FC4_PartData.__init__(self, *args, **kwargs)
147 self.deleteRemovedAttrs()
149 self.fsopts = kwargs.get("fsopts", "")
150 self.label = kwargs.get("label", "")
151 self.fsprofile = kwargs.get("fsprofile", "")
152 self.encrypted = kwargs.get("encrypted", False)
153 self.passphrase = kwargs.get("passphrase", "")
155 def _getArgsAsStr(self):
156 retval = FC4_PartData._getArgsAsStr(self)
158 if self.fsprofile != "":
159 retval += " --fsprofile=\"%s\"" % self.fsprofile
161 retval += " --encrypted"
163 if self.passphrase != "":
164 retval += " --passphrase=\"%s\"" % self.passphrase
168 class F11_PartData(F9_PartData):
169 removedKeywords = F9_PartData.removedKeywords + ["start", "end"]
170 removedAttrs = F9_PartData.removedAttrs + ["start", "end"]
172 class F12_PartData(F11_PartData):
173 removedKeywords = F11_PartData.removedKeywords
174 removedAttrs = F11_PartData.removedAttrs
176 def __init__(self, *args, **kwargs):
177 F11_PartData.__init__(self, *args, **kwargs)
179 self.escrowcert = kwargs.get("escrowcert", "")
180 self.backuppassphrase = kwargs.get("backuppassphrase", False)
182 def _getArgsAsStr(self):
183 retval = F11_PartData._getArgsAsStr(self)
185 if self.encrypted and self.escrowcert != "":
186 retval += " --escrowcert=\"%s\"" % self.escrowcert
188 if self.backuppassphrase:
189 retval += " --backuppassphrase"
193 F14_PartData = F12_PartData
195 class FC3_Partition(KickstartCommand):
196 removedKeywords = KickstartCommand.removedKeywords
197 removedAttrs = KickstartCommand.removedAttrs
199 def __init__(self, writePriority=130, *args, **kwargs):
200 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
201 self.op = self._getParser()
203 self.partitions = kwargs.get("partitions", [])
208 for part in self.partitions:
209 retval += part.__str__()
212 return "# Disk partitioning information\n" + retval
216 def _getParser(self):
217 def part_cb (option, opt_str, value, parser):
218 if value.startswith("/dev/"):
219 parser.values.ensure_value(option.dest, value[5:])
221 parser.values.ensure_value(option.dest, value)
223 op = KSOptionParser()
224 op.add_option("--active", dest="active", action="store_true",
226 op.add_option("--asprimary", dest="primOnly", action="store_true",
228 op.add_option("--end", dest="end", action="store", type="int",
230 op.add_option("--fstype", "--type", dest="fstype")
231 op.add_option("--grow", dest="grow", action="store_true", default=False)
232 op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int",
234 op.add_option("--noformat", dest="format", action="store_false",
236 op.add_option("--onbiosdisk", dest="onbiosdisk")
237 op.add_option("--ondisk", "--ondrive", dest="disk")
238 op.add_option("--onpart", "--usepart", dest="onPart", action="callback",
239 callback=part_cb, nargs=1, type="string")
240 op.add_option("--recommended", dest="recommended", action="store_true",
242 op.add_option("--size", dest="size", action="store", type="int",
244 op.add_option("--start", dest="start", action="store", type="int",
248 def parse(self, args):
249 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
251 pd = self.handler.PartData()
252 self._setToObj(self.op, opts, pd)
253 pd.lineno = self.lineno
255 pd.mountpoint = extra[0]
256 if pd in self.dataList():
257 warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint)
264 return self.partitions
266 class FC4_Partition(FC3_Partition):
267 removedKeywords = FC3_Partition.removedKeywords
268 removedAttrs = FC3_Partition.removedAttrs
270 def __init__(self, writePriority=130, *args, **kwargs):
271 FC3_Partition.__init__(self, writePriority, *args, **kwargs)
273 def part_cb (option, opt_str, value, parser):
274 if value.startswith("/dev/"):
275 parser.values.ensure_value(option.dest, value[5:])
277 parser.values.ensure_value(option.dest, value)
279 def _getParser(self):
280 op = FC3_Partition._getParser(self)
281 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
283 op.add_option("--fsoptions", dest="fsopts")
284 op.add_option("--label", dest="label")
285 op.add_option("--fslabel", dest="fslabel")
288 class RHEL5_Partition(FC4_Partition):
289 removedKeywords = FC4_Partition.removedKeywords
290 removedAttrs = FC4_Partition.removedAttrs
292 def __init__(self, writePriority=130, *args, **kwargs):
293 FC4_Partition.__init__(self, writePriority, *args, **kwargs)
295 def part_cb (option, opt_str, value, parser):
296 if value.startswith("/dev/"):
297 parser.values.ensure_value(option.dest, value[5:])
299 parser.values.ensure_value(option.dest, value)
301 def _getParser(self):
302 op = FC4_Partition._getParser(self)
303 op.add_option("--encrypted", action="store_true", default=False)
304 op.add_option("--passphrase")
307 class F9_Partition(FC4_Partition):
308 removedKeywords = FC4_Partition.removedKeywords
309 removedAttrs = FC4_Partition.removedAttrs
311 def __init__(self, writePriority=130, *args, **kwargs):
312 FC4_Partition.__init__(self, writePriority, *args, **kwargs)
314 def part_cb (option, opt_str, value, parser):
315 if value.startswith("/dev/"):
316 parser.values.ensure_value(option.dest, value[5:])
318 parser.values.ensure_value(option.dest, value)
320 def _getParser(self):
321 op = FC4_Partition._getParser(self)
322 op.add_option("--bytes-per-inode", deprecated=1)
323 op.add_option("--fsprofile")
324 op.add_option("--encrypted", action="store_true", default=False)
325 op.add_option("--passphrase")
328 class F11_Partition(F9_Partition):
329 removedKeywords = F9_Partition.removedKeywords
330 removedAttrs = F9_Partition.removedAttrs
332 def _getParser(self):
333 op = F9_Partition._getParser(self)
334 op.add_option("--start", deprecated=1)
335 op.add_option("--end", deprecated=1)
338 class F12_Partition(F11_Partition):
339 removedKeywords = F11_Partition.removedKeywords
340 removedAttrs = F11_Partition.removedAttrs
342 def _getParser(self):
343 op = F11_Partition._getParser(self)
344 op.add_option("--escrowcert")
345 op.add_option("--backuppassphrase", action="store_true", default=False)
348 class F14_Partition(F12_Partition):
349 removedKeywords = F12_Partition.removedKeywords
350 removedAttrs = F12_Partition.removedAttrs
352 def _getParser(self):
353 op = F12_Partition._getParser(self)
354 op.remove_option("--bytes-per-inode")
355 op.remove_option("--start")
356 op.remove_option("--end")