summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/3rdparty/pykickstart/commands/raid.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-08-24 15:31:34 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:56:03 +0100
commit9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch)
tree63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/3rdparty/pykickstart/commands/raid.py
parent53a1d9a788fd9f970af980da2ab975cca60685c4 (diff)
downloadpoky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.tar.gz
wic: Add mic w/pykickstart
This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/commands/raid.py')
-rw-r--r--scripts/lib/mic/3rdparty/pykickstart/commands/raid.py365
1 files changed, 365 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/raid.py b/scripts/lib/mic/3rdparty/pykickstart/commands/raid.py
new file mode 100644
index 0000000000..0f4c92a107
--- /dev/null
+++ b/scripts/lib/mic/3rdparty/pykickstart/commands/raid.py
@@ -0,0 +1,365 @@
1#
2# Chris Lumens <clumens@redhat.com>
3#
4# Copyright 2005, 2006, 2007, 2008, 2011 Red Hat, Inc.
5#
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.
12#
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.
19#
20from pykickstart.base import *
21from pykickstart.errors import *
22from pykickstart.options import *
23
24import gettext
25import warnings
26_ = lambda x: gettext.ldgettext("pykickstart", x)
27
28class FC3_RaidData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
31
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", [])
42
43 def __eq__(self, y):
44 return self.device == y.device
45
46 def _getArgsAsStr(self):
47 retval = ""
48
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"
61
62 return retval
63
64 def __str__(self):
65 retval = BaseData.__str__(self)
66 retval += "raid %s%s %s\n" % (self.mountpoint, self._getArgsAsStr(),
67 " ".join(self.members))
68 return retval
69
70class FC4_RaidData(FC3_RaidData):
71 removedKeywords = FC3_RaidData.removedKeywords
72 removedAttrs = FC3_RaidData.removedAttrs
73
74 def __init__(self, *args, **kwargs):
75 FC3_RaidData.__init__(self, *args, **kwargs)
76 self.fsopts = kwargs.get("fsopts", "")
77
78 def _getArgsAsStr(self):
79 retval = FC3_RaidData._getArgsAsStr(self)
80
81 if self.fsopts != "":
82 retval += " --fsoptions=\"%s\"" % self.fsopts
83
84 return retval
85
86class FC5_RaidData(FC4_RaidData):
87 removedKeywords = FC4_RaidData.removedKeywords
88 removedAttrs = FC4_RaidData.removedAttrs
89
90 def __init__(self, *args, **kwargs):
91 FC4_RaidData.__init__(self, *args, **kwargs)
92 self.bytesPerInode = kwargs.get("bytesPerInode", 4096)
93
94 def _getArgsAsStr(self):
95 retval = FC4_RaidData._getArgsAsStr(self)
96
97 if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0:
98 retval += " --bytes-per-inode=%d" % self.bytesPerInode
99
100 return retval
101
102class RHEL5_RaidData(FC5_RaidData):
103 removedKeywords = FC5_RaidData.removedKeywords
104 removedAttrs = FC5_RaidData.removedAttrs
105
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", "")
110
111 def _getArgsAsStr(self):
112 retval = FC5_RaidData._getArgsAsStr(self)
113
114 if self.encrypted:
115 retval += " --encrypted"
116
117 if self.passphrase != "":
118 retval += " --passphrase=\"%s\"" % self.passphrase
119
120 return retval
121
122F7_RaidData = FC5_RaidData
123
124class F9_RaidData(FC5_RaidData):
125 removedKeywords = FC5_RaidData.removedKeywords + ["bytesPerInode"]
126 removedAttrs = FC5_RaidData.removedAttrs + ["bytesPerInode"]
127
128 def __init__(self, *args, **kwargs):
129 FC5_RaidData.__init__(self, *args, **kwargs)
130 self.deleteRemovedAttrs()
131
132 self.fsprofile = kwargs.get("fsprofile", "")
133 self.encrypted = kwargs.get("encrypted", False)
134 self.passphrase = kwargs.get("passphrase", "")
135
136 def _getArgsAsStr(self):
137 retval = FC5_RaidData._getArgsAsStr(self)
138
139 if self.fsprofile != "":
140 retval += " --fsprofile=\"%s\"" % self.fsprofile
141 if self.encrypted:
142 retval += " --encrypted"
143
144 if self.passphrase != "":
145 retval += " --passphrase=\"%s\"" % self.passphrase
146
147 return retval
148
149class F12_RaidData(F9_RaidData):
150 removedKeywords = F9_RaidData.removedKeywords
151 removedAttrs = F9_RaidData.removedAttrs
152
153 def __init__(self, *args, **kwargs):
154 F9_RaidData.__init__(self, *args, **kwargs)
155 self.deleteRemovedAttrs()
156
157 self.escrowcert = kwargs.get("escrowcert", "")
158 self.backuppassphrase = kwargs.get("backuppassphrase", False)
159
160 def _getArgsAsStr(self):
161 retval = F9_RaidData._getArgsAsStr(self)
162
163 if self.encrypted and self.escrowcert != "":
164 retval += " --escrowcert=\"%s\"" % self.escrowcert
165
166 if self.backuppassphrase:
167 retval += " --backuppassphrase"
168 return retval
169
170F13_RaidData = F12_RaidData
171
172F14_RaidData = F13_RaidData
173
174class F15_RaidData(F14_RaidData):
175 removedKeywords = F14_RaidData.removedKeywords
176 removedAttrs = F14_RaidData.removedAttrs
177
178 def __init__(self, *args, **kwargs):
179 F14_RaidData.__init__(self, *args, **kwargs)
180 self.deleteRemovedAttrs()
181
182 self.label = kwargs.get("label", "")
183
184 def _getArgsAsStr(self):
185 retval = F14_RaidData._getArgsAsStr(self)
186
187 if self.label != "":
188 retval += " --label=%s" % self.label
189
190 return retval
191
192class FC3_Raid(KickstartCommand):
193 removedKeywords = KickstartCommand.removedKeywords
194 removedAttrs = KickstartCommand.removedAttrs
195
196 def __init__(self, writePriority=131, *args, **kwargs):
197 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
198 self.op = self._getParser()
199
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" }
207
208 self.raidList = kwargs.get("raidList", [])
209
210 def __str__(self):
211 retval = ""
212
213 for raid in self.raidList:
214 retval += raid.__str__()
215
216 return retval
217
218 def _getParser(self):
219 def raid_cb (option, opt_str, value, parser):
220 parser.values.format = False
221 parser.values.preexist = True
222
223 def device_cb (option, opt_str, value, parser):
224 if value[0:2] == "md":
225 parser.values.ensure_value(option.dest, value[2:])
226 else:
227 parser.values.ensure_value(option.dest, value)
228
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])
232
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",
242 nargs=1, default=0)
243 op.add_option("--useexisting", dest="preexist", action="store_true",
244 default=False)
245 return op
246
247 def parse(self, args):
248 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
249
250 if len(extra) == 0:
251 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "raid")
252 if len(extra) == 1:
253 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Partitions required for %s") % "raid")
254
255 rd = self.handler.RaidData()
256 self._setToObj(self.op, opts, rd)
257 rd.lineno = self.lineno
258
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
261 # it runs int().
262 rd.device = int(rd.device)
263 rd.mountpoint = extra[0]
264 rd.members = extra[1:]
265
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)
269
270 return rd
271
272 def dataList(self):
273 return self.raidList
274
275class FC4_Raid(FC3_Raid):
276 removedKeywords = FC3_Raid.removedKeywords
277 removedAttrs = FC3_Raid.removedAttrs
278
279 def _getParser(self):
280 op = FC3_Raid._getParser(self)
281 op.add_option("--fsoptions", dest="fsopts")
282 return op
283
284class FC5_Raid(FC4_Raid):
285 removedKeywords = FC4_Raid.removedKeywords
286 removedAttrs = FC4_Raid.removedAttrs
287
288 def _getParser(self):
289 op = FC4_Raid._getParser(self)
290 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
291 type="int", nargs=1)
292 return op
293
294class RHEL5_Raid(FC5_Raid):
295 removedKeywords = FC5_Raid.removedKeywords
296 removedAttrs = FC5_Raid.removedAttrs
297
298 def __init__(self, writePriority=131, *args, **kwargs):
299 FC5_Raid.__init__(self, writePriority, *args, **kwargs)
300
301 self.levelMap.update({"RAID10": "RAID10", "10": "RAID10"})
302
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")
307 return op
308
309class F7_Raid(FC5_Raid):
310 removedKeywords = FC5_Raid.removedKeywords
311 removedAttrs = FC5_Raid.removedAttrs
312
313 def __init__(self, writePriority=131, *args, **kwargs):
314 FC5_Raid.__init__(self, writePriority, *args, **kwargs)
315
316 self.levelMap.update({"RAID10": "RAID10", "10": "RAID10"})
317
318class F9_Raid(F7_Raid):
319 removedKeywords = F7_Raid.removedKeywords
320 removedAttrs = F7_Raid.removedAttrs
321
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")
328 return op
329
330class F12_Raid(F9_Raid):
331 removedKeywords = F9_Raid.removedKeywords
332 removedAttrs = F9_Raid.removedAttrs
333
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)
338 return op
339
340class F13_Raid(F12_Raid):
341 removedKeywords = F12_Raid.removedKeywords
342 removedAttrs = F12_Raid.removedAttrs
343
344 def __init__(self, writePriority=131, *args, **kwargs):
345 F12_Raid.__init__(self, writePriority, *args, **kwargs)
346
347 self.levelMap.update({"RAID4": "RAID4", "4": "RAID4"})
348
349class F14_Raid(F13_Raid):
350 removedKeywords = F13_Raid.removedKeywords
351 removedAttrs = F13_Raid.removedAttrs
352
353 def _getParser(self):
354 op = F13_Raid._getParser(self)
355 op.remove_option("--bytes-per-inode")
356 return op
357
358class F15_Raid(F14_Raid):
359 removedKeywords = F14_Raid.removedKeywords
360 removedAttrs = F14_Raid.removedAttrs
361
362 def _getParser(self):
363 op = F14_Raid._getParser(self)
364 op.add_option("--label")
365 return op