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.
22 from imgcreate
.pykickstart
.base
import *
23 from imgcreate
.pykickstart
.errors
import *
24 from imgcreate
.pykickstart
.options
import *
27 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
29 class FC3_RaidData(BaseData
):
30 def __init__(self
, device
=None, fstype
="", level
="", format
=True,
31 spares
=0, preexist
=False, mountpoint
="", members
=None):
32 BaseData
.__init
__(self
)
38 self
.preexist
= preexist
39 self
.mountpoint
= mountpoint
44 self
.members
= members
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 return "raid %s %s %s\n" % (self
.mountpoint
, self
._getArgsAsStr
(),
66 string
.join(self
.members
))
68 class FC4_RaidData(FC3_RaidData
):
69 def __init__(self
, device
=None, fsopts
="", fstype
="", level
="",
70 format
=True, spares
=0, preexist
=False, mountpoint
="",
72 FC3_RaidData
.__init
__(self
, device
=device
, fstype
=fstype
,
73 level
=level
, format
=format
,
74 spares
=spares
, preexist
=preexist
,
75 mountpoint
=mountpoint
,
79 def _getArgsAsStr(self
):
80 retval
= FC3_RaidData
._getArgsAsStr
(self
)
83 retval
+= " --fsoptions=\"%s\"" % self
.fsopts
87 class FC5_RaidData(FC4_RaidData
):
88 def __init__(self
, device
=None, fsopts
="", fstype
="", level
="",
89 format
=True, spares
=0, preexist
=False, mountpoint
="",
90 members
=None, bytesPerInode
=4096):
91 FC4_RaidData
.__init
__(self
, device
=device
, fsopts
=fsopts
,
92 fstype
=fstype
, level
=level
,
93 format
=format
, spares
=spares
,
95 mountpoint
=mountpoint
, members
=members
)
96 self
.bytesPerInode
= bytesPerInode
98 def _getArgsAsStr(self
):
99 retval
= FC4_RaidData
._getArgsAsStr
(self
)
101 if self
.bytesPerInode
!= 0:
102 retval
+= " --bytes-per-inode=%d" % self
.bytesPerInode
106 class RHEL5_RaidData(FC5_RaidData
):
107 def __init__(self
, device
=None, fsopts
="", fstype
="", level
="",
108 format
=True, spares
=0, preexist
=False, mountpoint
="",
109 members
=None, encrypted
=False, passphrase
="",
111 FC5_RaidData
.__init
__(self
, device
=device
, fsopts
=fsopts
,
112 fstype
=fstype
, level
=level
,
113 format
=format
, spares
=spares
,
115 bytesPerInode
=bytesPerInode
,
116 mountpoint
=mountpoint
, members
=members
)
117 self
.encrypted
= encrypted
118 self
.passphrase
= passphrase
120 def _getArgsAsStr(self
):
121 retval
= FC5_RaidData
._getArgsAsStr
(self
)
124 retval
+= " --encrypted"
126 if self
.passphrase
!= "":
127 retval
+= " --passphrase=\"%s\"" % self
.passphrase
131 F7_RaidData
= FC5_RaidData
133 class F9_RaidData(FC5_RaidData
):
134 def __init__(self
, device
=None, fsopts
="", fstype
="", level
="",
135 format
=True, spares
=0, preexist
=False, mountpoint
="",
136 members
=None, fsprofile
="", encrypted
=False, passphrase
=""):
137 FC5_RaidData
.__init
__(self
, device
=device
, fsopts
=fsopts
,
138 fstype
=fstype
, level
=level
,
139 format
=format
, spares
=spares
,
141 mountpoint
=mountpoint
, members
=members
)
142 self
.fsprofile
= fsprofile
143 self
.encrypted
= encrypted
144 self
.passphrase
= passphrase
146 def _getArgsAsStr(self
):
147 retval
= FC5_RaidData
._getArgsAsStr
(self
)
149 if self
.fsprofile
!= "":
150 retval
+= " --fsprofile=\"%s\"" % self
.fsprofile
152 retval
+= " --encrypted"
154 if self
.passphrase
!= "":
155 retval
+= " --passphrase=\"%s\"" % self
.passphrase
159 class FC3_Raid(KickstartCommand
):
160 def __init__(self
, writePriority
=131, raidList
=None):
161 KickstartCommand
.__init
__(self
, writePriority
)
162 self
.op
= self
._getParser
()
164 # A dict of all the RAID levels we support. This means that if we
165 # support more levels in the future, subclasses don't have to
166 # duplicate too much.
167 self
.levelMap
= { "RAID0": "RAID0", "0": "RAID0",
168 "RAID1": "RAID1", "1": "RAID1",
169 "RAID5": "RAID5", "5": "RAID5",
170 "RAID6": "RAID6", "6": "RAID6" }
175 self
.raidList
= raidList
180 for raid
in self
.raidList
:
181 retval
+= raid
.__str
__()
185 def _getParser(self
):
186 def raid_cb (option
, opt_str
, value
, parser
):
187 parser
.values
.format
= False
188 parser
.values
.preexist
= True
190 def device_cb (option
, opt_str
, value
, parser
):
191 if value
[0:2] == "md":
192 parser
.values
.ensure_value(option
.dest
, value
[2:])
194 parser
.values
.ensure_value(option
.dest
, value
)
196 def level_cb (option
, opt_str
, value
, parser
):
197 if self
.levelMap
.has_key(value
):
198 parser
.values
.ensure_value(option
.dest
, self
.levelMap
[value
])
200 op
= KSOptionParser(lineno
=self
.lineno
)
201 op
.add_option("--device", action
="callback", callback
=device_cb
,
202 dest
="device", type="string", nargs
=1, required
=1)
203 op
.add_option("--fstype", dest
="fstype")
204 op
.add_option("--level", dest
="level", action
="callback",
205 callback
=level_cb
, type="string", nargs
=1)
206 op
.add_option("--noformat", action
="callback", callback
=raid_cb
,
207 dest
="format", default
=True, nargs
=0)
208 op
.add_option("--spares", dest
="spares", action
="store", type="int",
210 op
.add_option("--useexisting", dest
="preexist", action
="store_true",
214 def parse(self
, args
):
215 (opts
, extra
) = self
.op
.parse_args(args
=args
)
218 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Mount point required for %s") % "raid")
220 rd
= self
.handler
.RaidData()
221 self
._setToObj
(self
.op
, opts
, rd
)
223 # --device can't just take an int in the callback above, because it
224 # could be specificed as "mdX", which causes optparse to error when
226 rd
.device
= int(rd
.device
)
227 rd
.mountpoint
= extra
[0]
228 rd
.members
= extra
[1:]
231 def add(self
, newObj
):
232 self
.raidList
.append(newObj
)
234 class FC4_Raid(FC3_Raid
):
235 def __init__(self
, writePriority
=131, raidList
=None):
236 FC3_Raid
.__init
__(self
, writePriority
, raidList
)
238 def _getParser(self
):
239 op
= FC3_Raid
._getParser
(self
)
240 op
.add_option("--fsoptions", dest
="fsopts")
243 class FC5_Raid(FC4_Raid
):
244 def __init__(self
, writePriority
=131, raidList
=None):
245 FC4_Raid
.__init
__(self
, writePriority
, raidList
)
247 def _getParser(self
):
248 op
= FC4_Raid
._getParser
(self
)
249 op
.add_option("--bytes-per-inode", dest
="bytesPerInode", action
="store",
253 class RHEL5_Raid(FC5_Raid
):
254 def __init__(self
, writePriority
=131, raidList
=None):
255 FC5_Raid
.__init
__(self
, writePriority
, raidList
)
257 def _getParser(self
):
258 op
= FC5_Raid
._getParser
(self
)
259 op
.add_option("--encrypted", action
="store_true", default
=False)
260 op
.add_option("--passphrase")
263 class F7_Raid(FC5_Raid
):
264 def __init__(self
, writePriority
=131, raidList
=None):
265 FC5_Raid
.__init
__(self
, writePriority
, raidList
)
267 self
.levelMap
.update({"RAID10": "RAID10", "10": "RAID10"})
269 class F9_Raid(F7_Raid
):
270 def __init__(self
, writePriority
=131, raidList
=None):
271 F7_Raid
.__init
__(self
, writePriority
, raidList
)
273 def _getParser(self
):
274 op
= F7_Raid
._getParser
(self
)
275 op
.add_option("--bytes-per-inode", deprecated
=1)
276 op
.add_option("--fsprofile")
277 op
.add_option("--encrypted", action
="store_true", default
=False)
278 op
.add_option("--passphrase")