New version.
[pykickstart.git] / pykickstart / commands / bootloader.py
blob0d0523ed6b30333afe0e8ed9cdc307fc320e0440
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007-2014 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.errors import KickstartValueError, formatErrorMsg
22 from pykickstart.options import KSOptionParser
24 import gettext
25 _ = lambda x: gettext.ldgettext("pykickstart", x)
27 class FC3_Bootloader(KickstartCommand):
28 removedKeywords = KickstartCommand.removedKeywords
29 removedAttrs = KickstartCommand.removedAttrs
31 def __init__(self, writePriority=10, *args, **kwargs):
32 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
33 self.op = self._getParser()
35 self.driveorder = kwargs.get("driveorder", [])
36 self.appendLine = kwargs.get("appendLine", "")
37 self.forceLBA = kwargs.get("forceLBA", False)
38 self.linear = kwargs.get("linear", True)
39 self.location = kwargs.get("location", "none")
40 self.md5pass = kwargs.get("md5pass", "")
41 self.password = kwargs.get("password", "")
42 self.upgrade = kwargs.get("upgrade", False)
43 self.useLilo = kwargs.get("useLilo", False)
45 self.deleteRemovedAttrs()
47 def _getArgsAsStr(self):
48 retval = ""
50 if self.appendLine != "":
51 retval += " --append=\"%s\"" % self.appendLine
52 if self.linear:
53 retval += " --linear"
54 if self.location:
55 retval += " --location=%s" % self.location
56 if hasattr(self, "forceLBA") and self.forceLBA:
57 retval += " --lba32"
58 if self.password != "":
59 retval += " --password=\"%s\"" % self.password
60 if self.md5pass != "":
61 retval += " --md5pass=\"%s\"" % self.md5pass
62 if self.upgrade:
63 retval += " --upgrade"
64 if self.useLilo:
65 retval += " --useLilo"
66 if len(self.driveorder) > 0:
67 retval += " --driveorder=\"%s\"" % ",".join(self.driveorder)
69 return retval
71 def __str__(self):
72 retval = KickstartCommand.__str__(self)
74 if self.location != "":
75 retval += "# System bootloader configuration\nbootloader"
76 retval += self._getArgsAsStr() + "\n"
78 return retval
80 def _getParser(self):
81 def driveorder_cb (option, opt_str, value, parser):
82 for d in value.split(','):
83 parser.values.ensure_value(option.dest, []).append(d)
85 op = KSOptionParser()
86 op.add_option("--append", dest="appendLine")
87 op.add_option("--linear", dest="linear", action="store_true",
88 default=True)
89 op.add_option("--nolinear", dest="linear", action="store_false")
90 op.add_option("--location", dest="location", type="choice",
91 default="mbr",
92 choices=["mbr", "partition", "none", "boot"])
93 op.add_option("--lba32", dest="forceLBA", action="store_true",
94 default=False)
95 op.add_option("--password", dest="password", default="")
96 op.add_option("--md5pass", dest="md5pass", default="")
97 op.add_option("--upgrade", dest="upgrade", action="store_true",
98 default=False)
99 op.add_option("--useLilo", dest="useLilo", action="store_true",
100 default=False)
101 op.add_option("--driveorder", dest="driveorder", action="callback",
102 callback=driveorder_cb, nargs=1, type="string")
103 return op
105 def parse(self, args):
106 (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
107 self._setToSelf(self.op, opts)
109 if self.currentCmd == "lilo":
110 self.useLilo = True
112 return self
114 class FC4_Bootloader(FC3_Bootloader):
115 removedKeywords = FC3_Bootloader.removedKeywords + ["linear", "useLilo"]
116 removedAttrs = FC3_Bootloader.removedAttrs + ["linear", "useLilo"]
118 def __init__(self, writePriority=10, *args, **kwargs):
119 FC3_Bootloader.__init__(self, writePriority, *args, **kwargs)
121 def _getArgsAsStr(self):
122 retval = ""
123 if self.appendLine != "":
124 retval += " --append=\"%s\"" % self.appendLine
125 if self.location:
126 retval += " --location=%s" % self.location
127 if hasattr(self, "forceLBA") and self.forceLBA:
128 retval += " --lba32"
129 if self.password != "":
130 retval += " --password=\"%s\"" % self.password
131 if self.md5pass != "":
132 retval += " --md5pass=\"%s\"" % self.md5pass
133 if self.upgrade:
134 retval += " --upgrade"
135 if len(self.driveorder) > 0:
136 retval += " --driveorder=\"%s\"" % ",".join(self.driveorder)
137 return retval
139 def _getParser(self):
140 op = FC3_Bootloader._getParser(self)
141 op.remove_option("--linear")
142 op.remove_option("--nolinear")
143 op.remove_option("--useLilo")
144 return op
146 def parse(self, args):
147 (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
148 self._setToSelf(self.op, opts)
149 return self
151 class F8_Bootloader(FC4_Bootloader):
152 removedKeywords = FC4_Bootloader.removedKeywords
153 removedAttrs = FC4_Bootloader.removedAttrs
155 def __init__(self, writePriority=10, *args, **kwargs):
156 FC4_Bootloader.__init__(self, writePriority, *args, **kwargs)
158 self.timeout = kwargs.get("timeout", None)
159 self.default = kwargs.get("default", "")
161 def _getArgsAsStr(self):
162 ret = FC4_Bootloader._getArgsAsStr(self)
164 if self.timeout is not None:
165 ret += " --timeout=%d" %(self.timeout,)
166 if self.default:
167 ret += " --default=%s" %(self.default,)
169 return ret
171 def _getParser(self):
172 op = FC4_Bootloader._getParser(self)
173 op.add_option("--timeout", dest="timeout", type="int")
174 op.add_option("--default", dest="default")
175 return op
177 class F12_Bootloader(F8_Bootloader):
178 removedKeywords = F8_Bootloader.removedKeywords
179 removedAttrs = F8_Bootloader.removedAttrs
181 def _getParser(self):
182 op = F8_Bootloader._getParser(self)
183 op.add_option("--lba32", dest="forceLBA", deprecated=1, action="store_true")
184 return op
186 class F14_Bootloader(F12_Bootloader):
187 removedKeywords = F12_Bootloader.removedKeywords + ["forceLBA"]
188 removedAttrs = F12_Bootloader.removedKeywords + ["forceLBA"]
190 def _getParser(self):
191 op = F12_Bootloader._getParser(self)
192 op.remove_option("--lba32")
193 return op
195 class F15_Bootloader(F14_Bootloader):
196 removedKeywords = F14_Bootloader.removedKeywords
197 removedAttrs = F14_Bootloader.removedAttrs
199 def __init__(self, writePriority=10, *args, **kwargs):
200 F14_Bootloader.__init__(self, writePriority, *args, **kwargs)
202 self.isCrypted = kwargs.get("isCrypted", False)
204 def _getArgsAsStr(self):
205 ret = F14_Bootloader._getArgsAsStr(self)
207 if self.isCrypted:
208 ret += " --iscrypted"
210 return ret
212 def _getParser(self):
213 def password_cb(option, opt_str, value, parser):
214 parser.values.isCrypted = True
215 parser.values.password = value
217 op = F14_Bootloader._getParser(self)
218 op.add_option("--iscrypted", dest="isCrypted", action="store_true", default=False)
219 op.add_option("--md5pass", action="callback", callback=password_cb, nargs=1, type="string")
220 return op
222 class F17_Bootloader(F15_Bootloader):
223 removedKeywords = F15_Bootloader.removedKeywords
224 removedAttrs = F15_Bootloader.removedAttrs
226 def __init__(self, writePriority=10, *args, **kwargs):
227 F15_Bootloader.__init__(self, writePriority, *args, **kwargs)
229 self.bootDrive = kwargs.get("bootDrive", "")
231 def _getArgsAsStr(self):
232 ret = F15_Bootloader._getArgsAsStr(self)
234 if self.bootDrive:
235 ret += " --boot-drive=%s" % self.bootDrive
237 return ret
239 def _getParser(self):
240 op = F15_Bootloader._getParser(self)
241 op.add_option("--boot-drive", dest="bootDrive", default="")
242 return op
244 def parse(self, args):
245 (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
247 if "," in opts.bootDrive:
248 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--boot-drive accepts only one argument")))
250 self._setToSelf(self.op, opts)
251 return self
253 class F18_Bootloader(F17_Bootloader):
254 removedKeywords = F17_Bootloader.removedKeywords
255 removedAttrs = F17_Bootloader.removedAttrs
257 def __init__(self, writePriority=10, *args, **kwargs):
258 F17_Bootloader.__init__(self, writePriority, *args, **kwargs)
260 self.leavebootorder = kwargs.get("leavebootorder", False)
262 def _getArgsAsStr(self):
263 ret = F17_Bootloader._getArgsAsStr(self)
265 if self.leavebootorder:
266 ret += " --leavebootorder"
268 return ret
270 def _getParser(self):
271 op = F17_Bootloader._getParser(self)
272 op.add_option("--leavebootorder", dest="leavebootorder", action="store_true", default=False)
273 return op
275 class RHEL5_Bootloader(FC4_Bootloader):
276 removedKeywords = FC4_Bootloader.removedKeywords
277 removedAttrs = FC4_Bootloader.removedAttrs
279 def __init__(self, writePriority=10, *args, **kwargs):
280 FC4_Bootloader.__init__(self, writePriority, *args, **kwargs)
282 self.hvArgs = kwargs.get("hvArgs", "")
284 def _getArgsAsStr(self):
285 ret = FC4_Bootloader._getArgsAsStr(self)
287 if self.hvArgs:
288 ret += " --hvargs=\"%s\"" %(self.hvArgs,)
290 return ret
292 def _getParser(self):
293 op = FC4_Bootloader._getParser(self)
294 op.add_option("--hvargs", dest="hvArgs", type="string")
295 return op
297 class RHEL6_Bootloader(F12_Bootloader):
298 removedKeywords = F12_Bootloader.removedKeywords
299 removedAttrs = F12_Bootloader.removedAttrs
301 def __init__(self, writePriority=10, *args, **kwargs):
302 F12_Bootloader.__init__(self, writePriority, *args, **kwargs)
304 self.isCrypted = kwargs.get("isCrypted", False)
306 def _getArgsAsStr(self):
307 ret = F12_Bootloader._getArgsAsStr(self)
309 if self.isCrypted:
310 ret += " --iscrypted"
312 return ret
314 def _getParser(self):
315 def password_cb(option, opt_str, value, parser):
316 parser.values.isCrypted = True
317 parser.values.password = value
319 op = F12_Bootloader._getParser(self)
320 op.add_option("--iscrypted", dest="isCrypted", action="store_true", default=False)
321 op.add_option("--md5pass", action="callback", callback=password_cb, nargs=1, type="string")
322 return op
324 class F19_Bootloader(F18_Bootloader):
325 removedKeywords = F18_Bootloader.removedKeywords
326 removedAttrs = F18_Bootloader.removedAttrs
328 def __init__(self, writePriority=10, *args, **kwargs):
329 F18_Bootloader.__init__(self, writePriority, *args, **kwargs)
331 self.extlinux = kwargs.get("extlinux", False)
333 def _getArgsAsStr(self):
334 ret = F18_Bootloader._getArgsAsStr(self)
336 if self.extlinux:
337 ret += " --extlinux"
339 return ret
341 def _getParser(self):
342 op = F18_Bootloader._getParser(self)
343 op.add_option("--extlinux", dest="extlinux", action="store_true",
344 default=False)
345 return op
347 class F21_Bootloader(F19_Bootloader):
348 removedKeywords = F19_Bootloader.removedKeywords
349 removedAttrs = F19_Bootloader.removedAttrs
351 def __init__(self, writePriority=10, *args, **kwargs):
352 F19_Bootloader.__init__(self, writePriority, *args, **kwargs)
354 self.disabled = kwargs.get("disabled", False)
356 def _getArgsAsStr(self):
357 if self.disabled:
358 return " --disabled"
359 else:
360 return F19_Bootloader._getArgsAsStr(self)
362 def _getParser(self):
363 op = F19_Bootloader._getParser(self)
364 op.add_option("--disabled", dest="disabled", action="store_true",
365 default=False)
366 return op