move pykickstart -> imgcreate.pykickstart
[pykickstart/EL-5.git] / pykickstart / commands / raid.py
blobb8b07a54f95e51efd9c8553afd9aa800ed57f1d5
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 import string
22 from imgcreate.pykickstart.base import *
23 from imgcreate.pykickstart.errors import *
24 from imgcreate.pykickstart.options import *
26 import gettext
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)
33 self.device = device
34 self.fstype = fstype
35 self.level = level
36 self.format = format
37 self.spares = spares
38 self.preexist = preexist
39 self.mountpoint = mountpoint
41 if members == None:
42 members = []
44 self.members = members
46 def _getArgsAsStr(self):
47 retval = ""
49 if self.device != "":
50 retval += " --device=%s" % self.device
51 if self.fstype != "":
52 retval += " --fstype=\"%s\"" % self.fstype
53 if self.level != "":
54 retval += " --level=%s" % self.level
55 if not self.format:
56 retval += " --noformat"
57 if self.spares != 0:
58 retval += " --spares=%d" % self.spares
59 if self.preexist:
60 retval += " --useexisting"
62 return retval
64 def __str__(self):
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="",
71 members=None):
72 FC3_RaidData.__init__(self, device=device, fstype=fstype,
73 level=level, format=format,
74 spares=spares, preexist=preexist,
75 mountpoint=mountpoint,
76 members=members)
77 self.fsopts = fsopts
79 def _getArgsAsStr(self):
80 retval = FC3_RaidData._getArgsAsStr(self)
82 if self.fsopts != "":
83 retval += " --fsoptions=\"%s\"" % self.fsopts
85 return retval
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,
94 preexist=preexist,
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
104 return retval
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="",
110 bytesPerInode=4096):
111 FC5_RaidData.__init__(self, device=device, fsopts=fsopts,
112 fstype=fstype, level=level,
113 format=format, spares=spares,
114 preexist=preexist,
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)
123 if self.encrypted:
124 retval += " --encrypted"
126 if self.passphrase != "":
127 retval += " --passphrase=\"%s\"" % self.passphrase
129 return retval
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,
140 preexist=preexist,
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
151 if self.encrypted:
152 retval += " --encrypted"
154 if self.passphrase != "":
155 retval += " --passphrase=\"%s\"" % self.passphrase
157 return retval
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" }
172 if raidList == None:
173 raidList = []
175 self.raidList = raidList
177 def __str__(self):
178 retval = ""
180 for raid in self.raidList:
181 retval += raid.__str__()
183 return retval
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:])
193 else:
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",
209 nargs=1, default=0)
210 op.add_option("--useexisting", dest="preexist", action="store_true",
211 default=False)
212 return op
214 def parse(self, args):
215 (opts, extra) = self.op.parse_args(args=args)
217 if len(extra) == 0:
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
225 # it runs int().
226 rd.device = int(rd.device)
227 rd.mountpoint = extra[0]
228 rd.members = extra[1:]
229 self.add(rd)
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")
241 return op
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",
250 type="int", nargs=1)
251 return op
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")
261 return op
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")
279 return op