2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2008, 2011 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_RaidData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
32 def __init__(self, *args, **kwargs):
33 BaseData.__init__(self, *args, **kwargs)
34 self.device = kwargs.get("device", None)
35 self.fstype = kwargs.get("fstype", "")
36 self.level = kwargs.get("level", "")
37 self.format = kwargs.get("format", True)
38 self.spares = kwargs.get("spares", 0)
39 self.preexist = kwargs.get("preexist", False)
40 self.mountpoint = kwargs.get("mountpoint", "")
41 self.members = kwargs.get("members", [])
44 return self.device == y.device
46 def _getArgsAsStr(self):
50 retval += " --device=%s" % self.device
52 retval += " --fstype=\"%s\"" % self.fstype
54 retval += " --level=%s" % self.level
56 retval += " --noformat"
58 retval += " --spares=%d" % self.spares
60 retval += " --useexisting"
65 retval = BaseData.__str__(self)
66 retval += "raid %s%s %s\n" % (self.mountpoint, self._getArgsAsStr(),
67 " ".join(self.members))
70 class FC4_RaidData(FC3_RaidData):
71 removedKeywords = FC3_RaidData.removedKeywords
72 removedAttrs = FC3_RaidData.removedAttrs
74 def __init__(self, *args, **kwargs):
75 FC3_RaidData.__init__(self, *args, **kwargs)
76 self.fsopts = kwargs.get("fsopts", "")
78 def _getArgsAsStr(self):
79 retval = FC3_RaidData._getArgsAsStr(self)
82 retval += " --fsoptions=\"%s\"" % self.fsopts
86 class FC5_RaidData(FC4_RaidData):
87 removedKeywords = FC4_RaidData.removedKeywords
88 removedAttrs = FC4_RaidData.removedAttrs
90 def __init__(self, *args, **kwargs):
91 FC4_RaidData.__init__(self, *args, **kwargs)
92 self.bytesPerInode = kwargs.get("bytesPerInode", 4096)
94 def _getArgsAsStr(self):
95 retval = FC4_RaidData._getArgsAsStr(self)
97 if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0:
98 retval += " --bytes-per-inode=%d" % self.bytesPerInode
102 class RHEL5_RaidData(FC5_RaidData):
103 removedKeywords = FC5_RaidData.removedKeywords
104 removedAttrs = FC5_RaidData.removedAttrs
106 def __init__(self, *args, **kwargs):
107 FC5_RaidData.__init__(self, *args, **kwargs)
108 self.encrypted = kwargs.get("encrypted", False)
109 self.passphrase = kwargs.get("passphrase", "")
111 def _getArgsAsStr(self):
112 retval = FC5_RaidData._getArgsAsStr(self)
115 retval += " --encrypted"
117 if self.passphrase != "":
118 retval += " --passphrase=\"%s\"" % self.passphrase
122 F7_RaidData = FC5_RaidData
124 class F9_RaidData(FC5_RaidData):
125 removedKeywords = FC5_RaidData.removedKeywords + ["bytesPerInode"]
126 removedAttrs = FC5_RaidData.removedAttrs + ["bytesPerInode"]
128 def __init__(self, *args, **kwargs):
129 FC5_RaidData.__init__(self, *args, **kwargs)
130 self.deleteRemovedAttrs()
132 self.fsprofile = kwargs.get("fsprofile", "")
133 self.encrypted = kwargs.get("encrypted", False)
134 self.passphrase = kwargs.get("passphrase", "")
136 def _getArgsAsStr(self):
137 retval = FC5_RaidData._getArgsAsStr(self)
139 if self.fsprofile != "":
140 retval += " --fsprofile=\"%s\"" % self.fsprofile
142 retval += " --encrypted"
144 if self.passphrase != "":
145 retval += " --passphrase=\"%s\"" % self.passphrase
149 class F12_RaidData(F9_RaidData):
150 removedKeywords = F9_RaidData.removedKeywords
151 removedAttrs = F9_RaidData.removedAttrs
153 def __init__(self, *args, **kwargs):
154 F9_RaidData.__init__(self, *args, **kwargs)
155 self.deleteRemovedAttrs()
157 self.escrowcert = kwargs.get("escrowcert", "")
158 self.backuppassphrase = kwargs.get("backuppassphrase", False)
160 def _getArgsAsStr(self):
161 retval = F9_RaidData._getArgsAsStr(self)
163 if self.encrypted and self.escrowcert != "":
164 retval += " --escrowcert=\"%s\"" % self.escrowcert
166 if self.backuppassphrase:
167 retval += " --backuppassphrase"
170 F13_RaidData = F12_RaidData
172 F14_RaidData = F13_RaidData
174 class F15_RaidData(F14_RaidData):
175 removedKeywords = F14_RaidData.removedKeywords
176 removedAttrs = F14_RaidData.removedAttrs
178 def __init__(self, *args, **kwargs):
179 F14_RaidData.__init__(self, *args, **kwargs)
180 self.deleteRemovedAttrs()
182 self.label = kwargs.get("label", "")
184 def _getArgsAsStr(self):
185 retval = F14_RaidData._getArgsAsStr(self)
188 retval += " --label=%s" % self.label
192 class FC3_Raid(KickstartCommand):
193 removedKeywords = KickstartCommand.removedKeywords
194 removedAttrs = KickstartCommand.removedAttrs
196 def __init__(self, writePriority=131, *args, **kwargs):
197 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
198 self.op = self._getParser()
200 # A dict of all the RAID levels we support. This means that if we
201 # support more levels in the future, subclasses don't have to
202 # duplicate too much.
203 self.levelMap = { "RAID0": "RAID0", "0": "RAID0",
204 "RAID1": "RAID1", "1": "RAID1",
205 "RAID5": "RAID5", "5": "RAID5",
206 "RAID6": "RAID6", "6": "RAID6" }
208 self.raidList = kwargs.get("raidList", [])
213 for raid in self.raidList:
214 retval += raid.__str__()
218 def _getParser(self):
219 def raid_cb (option, opt_str, value, parser):
220 parser.values.format = False
221 parser.values.preexist = True
223 def device_cb (option, opt_str, value, parser):
224 if value[0:2] == "md":
225 parser.values.ensure_value(option.dest, value[2:])
227 parser.values.ensure_value(option.dest, value)
229 def level_cb (option, opt_str, value, parser):
230 if self.levelMap.has_key(value):
231 parser.values.ensure_value(option.dest, self.levelMap[value])
233 op = KSOptionParser()
234 op.add_option("--device", action="callback", callback=device_cb,
235 dest="device", type="string", nargs=1, required=1)
236 op.add_option("--fstype", dest="fstype")
237 op.add_option("--level", dest="level", action="callback",
238 callback=level_cb, type="string", nargs=1)
239 op.add_option("--noformat", action="callback", callback=raid_cb,
240 dest="format", default=True, nargs=0)
241 op.add_option("--spares", dest="spares", action="store", type="int",
243 op.add_option("--useexisting", dest="preexist", action="store_true",
247 def parse(self, args):
248 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
251 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "raid")
253 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Partitions required for %s") % "raid")
255 rd = self.handler.RaidData()
256 self._setToObj(self.op, opts, rd)
257 rd.lineno = self.lineno
259 # --device can't just take an int in the callback above, because it
260 # could be specificed as "mdX", which causes optparse to error when
262 rd.device = int(rd.device)
263 rd.mountpoint = extra[0]
264 rd.members = extra[1:]
266 # Check for duplicates in the data list.
267 if rd in self.dataList():
268 warnings.warn(_("A RAID device with the name %s has already been defined.") % rd.device)
275 class FC4_Raid(FC3_Raid):
276 removedKeywords = FC3_Raid.removedKeywords
277 removedAttrs = FC3_Raid.removedAttrs
279 def _getParser(self):
280 op = FC3_Raid._getParser(self)
281 op.add_option("--fsoptions", dest="fsopts")
284 class FC5_Raid(FC4_Raid):
285 removedKeywords = FC4_Raid.removedKeywords
286 removedAttrs = FC4_Raid.removedAttrs
288 def _getParser(self):
289 op = FC4_Raid._getParser(self)
290 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
294 class RHEL5_Raid(FC5_Raid):
295 removedKeywords = FC5_Raid.removedKeywords
296 removedAttrs = FC5_Raid.removedAttrs
298 def __init__(self, writePriority=131, *args, **kwargs):
299 FC5_Raid.__init__(self, writePriority, *args, **kwargs)
301 self.levelMap.update({"RAID10": "RAID10", "10": "RAID10"})
303 def _getParser(self):
304 op = FC5_Raid._getParser(self)
305 op.add_option("--encrypted", action="store_true", default=False)
306 op.add_option("--passphrase")
309 class F7_Raid(FC5_Raid):
310 removedKeywords = FC5_Raid.removedKeywords
311 removedAttrs = FC5_Raid.removedAttrs
313 def __init__(self, writePriority=131, *args, **kwargs):
314 FC5_Raid.__init__(self, writePriority, *args, **kwargs)
316 self.levelMap.update({"RAID10": "RAID10", "10": "RAID10"})
318 class F9_Raid(F7_Raid):
319 removedKeywords = F7_Raid.removedKeywords
320 removedAttrs = F7_Raid.removedAttrs
322 def _getParser(self):
323 op = F7_Raid._getParser(self)
324 op.add_option("--bytes-per-inode", deprecated=1)
325 op.add_option("--fsprofile")
326 op.add_option("--encrypted", action="store_true", default=False)
327 op.add_option("--passphrase")
330 class F12_Raid(F9_Raid):
331 removedKeywords = F9_Raid.removedKeywords
332 removedAttrs = F9_Raid.removedAttrs
334 def _getParser(self):
335 op = F9_Raid._getParser(self)
336 op.add_option("--escrowcert")
337 op.add_option("--backuppassphrase", action="store_true", default=False)
340 class F13_Raid(F12_Raid):
341 removedKeywords = F12_Raid.removedKeywords
342 removedAttrs = F12_Raid.removedAttrs
344 def __init__(self, writePriority=131, *args, **kwargs):
345 F12_Raid.__init__(self, writePriority, *args, **kwargs)
347 self.levelMap.update({"RAID4": "RAID4", "4": "RAID4"})
349 class F14_Raid(F13_Raid):
350 removedKeywords = F13_Raid.removedKeywords
351 removedAttrs = F13_Raid.removedAttrs
353 def _getParser(self):
354 op = F13_Raid._getParser(self)
355 op.remove_option("--bytes-per-inode")
358 class F15_Raid(F14_Raid):
359 removedKeywords = F14_Raid.removedKeywords
360 removedAttrs = F14_Raid.removedAttrs
362 def _getParser(self):
363 op = F14_Raid._getParser(self)
364 op.add_option("--label")