2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007 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.options import *
23 class FC3_Bootloader(KickstartCommand):
24 removedKeywords = KickstartCommand.removedKeywords
25 removedAttrs = KickstartCommand.removedAttrs
27 def __init__(self, writePriority=10, *args, **kwargs):
28 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
29 self.op = self._getParser()
31 self.driveorder = kwargs.get("driveorder", [])
32 self.appendLine = kwargs.get("appendLine", "")
33 self.forceLBA = kwargs.get("forceLBA", False)
34 self.linear = kwargs.get("linear", True)
35 self.location = kwargs.get("location", "")
36 self.md5pass = kwargs.get("md5pass", "")
37 self.password = kwargs.get("password", "")
38 self.upgrade = kwargs.get("upgrade", False)
39 self.useLilo = kwargs.get("useLilo", False)
41 self.deleteRemovedAttrs()
43 def _getArgsAsStr(self):
46 if self.appendLine != "":
47 retval += " --append=\"%s\"" % self.appendLine
51 retval += " --location=%s" % self.location
52 if hasattr(self, "forceLBA") and self.forceLBA:
54 if self.password != "":
55 retval += " --password=\"%s\"" % self.password
56 if self.md5pass != "":
57 retval += " --md5pass=\"%s\"" % self.md5pass
59 retval += " --upgrade"
61 retval += " --useLilo"
62 if len(self.driveorder) > 0:
63 retval += " --driveorder=\"%s\"" % ",".join(self.driveorder)
68 retval = KickstartCommand.__str__(self)
70 if self.location != "":
71 retval += "# System bootloader configuration\nbootloader"
72 retval += self._getArgsAsStr() + "\n"
77 def driveorder_cb (option, opt_str, value, parser):
78 for d in value.split(','):
79 parser.values.ensure_value(option.dest, []).append(d)
82 op.add_option("--append", dest="appendLine")
83 op.add_option("--linear", dest="linear", action="store_true",
85 op.add_option("--nolinear", dest="linear", action="store_false")
86 op.add_option("--location", dest="location", type="choice",
88 choices=["mbr", "partition", "none", "boot"])
89 op.add_option("--lba32", dest="forceLBA", action="store_true",
91 op.add_option("--password", dest="password", default="")
92 op.add_option("--md5pass", dest="md5pass", default="")
93 op.add_option("--upgrade", dest="upgrade", action="store_true",
95 op.add_option("--useLilo", dest="useLilo", action="store_true",
97 op.add_option("--driveorder", dest="driveorder", action="callback",
98 callback=driveorder_cb, nargs=1, type="string")
101 def parse(self, args):
102 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
103 self._setToSelf(self.op, opts)
105 if self.currentCmd == "lilo":
110 class FC4_Bootloader(FC3_Bootloader):
111 removedKeywords = FC3_Bootloader.removedKeywords + ["linear", "useLilo"]
112 removedAttrs = FC3_Bootloader.removedAttrs + ["linear", "useLilo"]
114 def __init__(self, writePriority=10, *args, **kwargs):
115 FC3_Bootloader.__init__(self, writePriority, *args, **kwargs)
117 def _getArgsAsStr(self):
119 if self.appendLine != "":
120 retval += " --append=\"%s\"" % self.appendLine
122 retval += " --location=%s" % self.location
123 if hasattr(self, "forceLBA") and self.forceLBA:
125 if self.password != "":
126 retval += " --password=\"%s\"" % self.password
127 if self.md5pass != "":
128 retval += " --md5pass=\"%s\"" % self.md5pass
130 retval += " --upgrade"
131 if len(self.driveorder) > 0:
132 retval += " --driveorder=\"%s\"" % ",".join(self.driveorder)
135 def _getParser(self):
136 op = FC3_Bootloader._getParser(self)
137 op.remove_option("--linear")
138 op.remove_option("--nolinear")
139 op.remove_option("--useLilo")
142 def parse(self, args):
143 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
144 self._setToSelf(self.op, opts)
147 class F8_Bootloader(FC4_Bootloader):
148 removedKeywords = FC4_Bootloader.removedKeywords
149 removedAttrs = FC4_Bootloader.removedAttrs
151 def __init__(self, writePriority=10, *args, **kwargs):
152 FC4_Bootloader.__init__(self, writePriority, *args, **kwargs)
154 self.timeout = kwargs.get("timeout", None)
155 self.default = kwargs.get("default", "")
157 def _getArgsAsStr(self):
158 ret = FC4_Bootloader._getArgsAsStr(self)
160 if self.timeout is not None:
161 ret += " --timeout=%d" %(self.timeout,)
163 ret += " --default=%s" %(self.default,)
167 def _getParser(self):
168 op = FC4_Bootloader._getParser(self)
169 op.add_option("--timeout", dest="timeout", type="int")
170 op.add_option("--default", dest="default")
173 class F12_Bootloader(F8_Bootloader):
174 removedKeywords = F8_Bootloader.removedKeywords
175 removedAttrs = F8_Bootloader.removedAttrs
177 def _getParser(self):
178 op = F8_Bootloader._getParser(self)
179 op.add_option("--lba32", dest="forceLBA", deprecated=1, action="store_true")
182 class F14_Bootloader(F12_Bootloader):
183 removedKeywords = F12_Bootloader.removedKeywords + ["forceLBA"]
184 removedAttrs = F12_Bootloader.removedKeywords + ["forceLBA"]
186 def _getParser(self):
187 op = F12_Bootloader._getParser(self)
188 op.remove_option("--lba32")
191 class F15_Bootloader(F14_Bootloader):
192 removedKeywords = F14_Bootloader.removedKeywords
193 removedAttrs = F14_Bootloader.removedAttrs
195 def __init__(self, writePriority=10, *args, **kwargs):
196 F14_Bootloader.__init__(self, writePriority, *args, **kwargs)
198 self.isCrypted = kwargs.get("isCrypted", False)
200 def _getArgsAsStr(self):
201 ret = F14_Bootloader._getArgsAsStr(self)
204 ret += " --iscrypted"
208 def _getParser(self):
209 def password_cb(option, opt_str, value, parser):
210 parser.values.isCrypted = True
211 parser.values.password = value
213 op = F14_Bootloader._getParser(self)
214 op.add_option("--iscrypted", dest="isCrypted", action="store_true", default=False)
215 op.add_option("--md5pass", action="callback", callback=password_cb, nargs=1, type="string")
218 class RHEL5_Bootloader(FC4_Bootloader):
219 removedKeywords = FC4_Bootloader.removedKeywords
220 removedAttrs = FC4_Bootloader.removedAttrs
222 def __init__(self, writePriority=10, *args, **kwargs):
223 FC4_Bootloader.__init__(self, writePriority, *args, **kwargs)
225 self.hvArgs = kwargs.get("hvArgs", "")
227 def _getArgsAsStr(self):
228 ret = FC4_Bootloader._getArgsAsStr(self)
231 ret += " --hvargs=\"%s\"" %(self.hvArgs,)
235 def _getParser(self):
236 op = FC4_Bootloader._getParser(self)
237 op.add_option("--hvargs", dest="hvArgs", type="string")
240 class RHEL6_Bootloader(F12_Bootloader):
241 removedKeywords = F12_Bootloader.removedKeywords
242 removedAttrs = F12_Bootloader.removedAttrs
244 def __init__(self, writePriority=10, *args, **kwargs):
245 F12_Bootloader.__init__(self, writePriority, *args, **kwargs)
247 self.isCrypted = kwargs.get("isCrypted", False)
249 def _getArgsAsStr(self):
250 ret = F12_Bootloader._getArgsAsStr(self)
253 ret += " --iscrypted"
257 def _getParser(self):
258 def password_cb(option, opt_str, value, parser):
259 parser.values.isCrypted = True
260 parser.values.password = value
262 op = F12_Bootloader._getParser(self)
263 op.add_option("--iscrypted", dest="isCrypted", action="store_true", default=False)
264 op.add_option("--md5pass", action="callback", callback=password_cb, nargs=1, type="string")