diff options
author | Tom Zanussi <tom.zanussi@linux.intel.com> | 2013-08-24 15:31:34 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-10-01 22:56:03 +0100 |
commit | 9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch) | |
tree | 63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/3rdparty/pykickstart/commands/network.py | |
parent | 53a1d9a788fd9f970af980da2ab975cca60685c4 (diff) | |
download | poky-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/network.py')
-rw-r--r-- | scripts/lib/mic/3rdparty/pykickstart/commands/network.py | 363 |
1 files changed, 363 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/network.py b/scripts/lib/mic/3rdparty/pykickstart/commands/network.py new file mode 100644 index 0000000000..9b67f92831 --- /dev/null +++ b/scripts/lib/mic/3rdparty/pykickstart/commands/network.py | |||
@@ -0,0 +1,363 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2005, 2006, 2007, 2008 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 | # | ||
20 | from pykickstart.base import * | ||
21 | from pykickstart.constants import * | ||
22 | from pykickstart.errors import * | ||
23 | from pykickstart.options import * | ||
24 | |||
25 | import gettext | ||
26 | import warnings | ||
27 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
28 | |||
29 | class FC3_NetworkData(BaseData): | ||
30 | removedKeywords = BaseData.removedKeywords | ||
31 | removedAttrs = BaseData.removedAttrs | ||
32 | |||
33 | def __init__(self, *args, **kwargs): | ||
34 | BaseData.__init__(self, *args, **kwargs) | ||
35 | self.bootProto = kwargs.get("bootProto", BOOTPROTO_DHCP) | ||
36 | self.dhcpclass = kwargs.get("dhcpclass", "") | ||
37 | self.device = kwargs.get("device", "") | ||
38 | self.essid = kwargs.get("essid", "") | ||
39 | self.ethtool = kwargs.get("ethtool", "") | ||
40 | self.gateway = kwargs.get("gateway", "") | ||
41 | self.hostname = kwargs.get("hostname", "") | ||
42 | self.ip = kwargs.get("ip", "") | ||
43 | self.mtu = kwargs.get("mtu", "") | ||
44 | self.nameserver = kwargs.get("nameserver", "") | ||
45 | self.netmask = kwargs.get("netmask", "") | ||
46 | self.nodns = kwargs.get("nodns", False) | ||
47 | self.onboot = kwargs.get("onboot", True) | ||
48 | self.wepkey = kwargs.get("wepkey", "") | ||
49 | |||
50 | def __eq__(self, y): | ||
51 | return self.device and self.device == y.device | ||
52 | |||
53 | def _getArgsAsStr(self): | ||
54 | retval = "" | ||
55 | |||
56 | if self.bootProto != "": | ||
57 | retval += " --bootproto=%s" % self.bootProto | ||
58 | if self.dhcpclass != "": | ||
59 | retval += " --dhcpclass=%s" % self.dhcpclass | ||
60 | if self.device != "": | ||
61 | retval += " --device=%s" % self.device | ||
62 | if self.essid != "": | ||
63 | retval += " --essid=\"%s\"" % self.essid | ||
64 | if self.ethtool != "": | ||
65 | retval += " --ethtool=\"%s\"" % self.ethtool | ||
66 | if self.gateway != "": | ||
67 | retval += " --gateway=%s" % self.gateway | ||
68 | if self.hostname != "": | ||
69 | retval += " --hostname=%s" % self.hostname | ||
70 | if self.ip != "": | ||
71 | retval += " --ip=%s" % self.ip | ||
72 | if self.mtu != "": | ||
73 | retval += " --mtu=%s" % self.mtu | ||
74 | if self.nameserver != "": | ||
75 | retval += " --nameserver=%s" % self.nameserver | ||
76 | if self.netmask != "": | ||
77 | retval += " --netmask=%s" % self.netmask | ||
78 | if self.nodns: | ||
79 | retval += " --nodns" | ||
80 | if not self.onboot: | ||
81 | retval += " --onboot=off" | ||
82 | if self.wepkey != "": | ||
83 | retval += " --wepkey=%s" % self.wepkey | ||
84 | |||
85 | return retval | ||
86 | |||
87 | def __str__(self): | ||
88 | retval = BaseData.__str__(self) | ||
89 | retval += "network %s\n" % self._getArgsAsStr() | ||
90 | return retval | ||
91 | |||
92 | class FC4_NetworkData(FC3_NetworkData): | ||
93 | removedKeywords = FC3_NetworkData.removedKeywords | ||
94 | removedAttrs = FC3_NetworkData.removedAttrs | ||
95 | |||
96 | def __init__(self, *args, **kwargs): | ||
97 | FC3_NetworkData.__init__(self, *args, **kwargs) | ||
98 | self.notksdevice = kwargs.get("notksdevice", False) | ||
99 | |||
100 | def _getArgsAsStr(self): | ||
101 | retval = FC3_NetworkData._getArgsAsStr(self) | ||
102 | |||
103 | if self.notksdevice: | ||
104 | retval += " --notksdevice" | ||
105 | |||
106 | return retval | ||
107 | |||
108 | class FC6_NetworkData(FC4_NetworkData): | ||
109 | removedKeywords = FC4_NetworkData.removedKeywords | ||
110 | removedAttrs = FC4_NetworkData.removedAttrs | ||
111 | |||
112 | def __init__(self, *args, **kwargs): | ||
113 | FC4_NetworkData.__init__(self, *args, **kwargs) | ||
114 | self.noipv4 = kwargs.get("noipv4", False) | ||
115 | self.noipv6 = kwargs.get("noipv6", False) | ||
116 | |||
117 | def _getArgsAsStr(self): | ||
118 | retval = FC4_NetworkData._getArgsAsStr(self) | ||
119 | |||
120 | if self.noipv4: | ||
121 | retval += " --noipv4" | ||
122 | if self.noipv6: | ||
123 | retval += " --noipv6" | ||
124 | |||
125 | return retval | ||
126 | |||
127 | class F8_NetworkData(FC6_NetworkData): | ||
128 | removedKeywords = FC6_NetworkData.removedKeywords | ||
129 | removedAttrs = FC6_NetworkData.removedAttrs | ||
130 | |||
131 | def __init__(self, *args, **kwargs): | ||
132 | FC6_NetworkData.__init__(self, *args, **kwargs) | ||
133 | self.ipv6 = kwargs.get("ipv6", "") | ||
134 | |||
135 | def _getArgsAsStr(self): | ||
136 | retval = FC6_NetworkData._getArgsAsStr(self) | ||
137 | |||
138 | if self.ipv6 != "": | ||
139 | retval += " --ipv6" % self.ipv6 | ||
140 | |||
141 | return retval | ||
142 | |||
143 | class F16_NetworkData(F8_NetworkData): | ||
144 | removedKeywords = F8_NetworkData.removedKeywords | ||
145 | removedAttrs = F8_NetworkData.removedAttrs | ||
146 | |||
147 | def __init__(self, *args, **kwargs): | ||
148 | F8_NetworkData.__init__(self, *args, **kwargs) | ||
149 | self.activate = kwargs.get("activate", False) | ||
150 | self.nodefroute = kwargs.get("nodefroute", False) | ||
151 | self.wpakey = kwargs.get("wpakey", "") | ||
152 | |||
153 | def _getArgsAsStr(self): | ||
154 | retval = F8_NetworkData._getArgsAsStr(self) | ||
155 | |||
156 | if self.activate: | ||
157 | retval += " --activate" | ||
158 | if self.nodefroute: | ||
159 | retval += " --nodefroute" | ||
160 | if self.wpakey != "": | ||
161 | retval += "--wpakey=%s" % self.wpakey | ||
162 | |||
163 | return retval | ||
164 | |||
165 | class RHEL4_NetworkData(FC3_NetworkData): | ||
166 | removedKeywords = FC3_NetworkData.removedKeywords | ||
167 | removedAttrs = FC3_NetworkData.removedAttrs | ||
168 | |||
169 | def __init__(self, *args, **kwargs): | ||
170 | FC3_NetworkData.__init__(self, *args, **kwargs) | ||
171 | self.notksdevice = kwargs.get("notksdevice", False) | ||
172 | |||
173 | def _getArgsAsStr(self): | ||
174 | retval = FC3_NetworkData._getArgsAsStr(self) | ||
175 | |||
176 | if self.notksdevice: | ||
177 | retval += " --notksdevice" | ||
178 | |||
179 | return retval | ||
180 | |||
181 | class RHEL6_NetworkData(F8_NetworkData): | ||
182 | removedKeywords = F8_NetworkData.removedKeywords | ||
183 | removedAttrs = F8_NetworkData.removedAttrs | ||
184 | |||
185 | def __init__(self, *args, **kwargs): | ||
186 | F8_NetworkData.__init__(self, *args, **kwargs) | ||
187 | self.activate = kwargs.get("activate", False) | ||
188 | self.nodefroute = kwargs.get("nodefroute", False) | ||
189 | |||
190 | def _getArgsAsStr(self): | ||
191 | retval = F8_NetworkData._getArgsAsStr(self) | ||
192 | |||
193 | if self.activate: | ||
194 | retval += " --activate" | ||
195 | if self.nodefroute: | ||
196 | retval += " --nodefroute" | ||
197 | |||
198 | return retval | ||
199 | |||
200 | class FC3_Network(KickstartCommand): | ||
201 | removedKeywords = KickstartCommand.removedKeywords | ||
202 | removedAttrs = KickstartCommand.removedAttrs | ||
203 | |||
204 | def __init__(self, writePriority=0, *args, **kwargs): | ||
205 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
206 | self.bootprotoList = [BOOTPROTO_DHCP, BOOTPROTO_BOOTP, | ||
207 | BOOTPROTO_STATIC] | ||
208 | |||
209 | self.op = self._getParser() | ||
210 | |||
211 | self.network = kwargs.get("network", []) | ||
212 | |||
213 | def __str__(self): | ||
214 | retval = "" | ||
215 | |||
216 | for nic in self.network: | ||
217 | retval += nic.__str__() | ||
218 | |||
219 | if retval != "": | ||
220 | return "# Network information\n" + retval | ||
221 | else: | ||
222 | return "" | ||
223 | |||
224 | def _getParser(self): | ||
225 | op = KSOptionParser() | ||
226 | op.add_option("--bootproto", dest="bootProto", | ||
227 | default=BOOTPROTO_DHCP, | ||
228 | choices=self.bootprotoList) | ||
229 | op.add_option("--dhcpclass", dest="dhcpclass") | ||
230 | op.add_option("--device", dest="device") | ||
231 | op.add_option("--essid", dest="essid") | ||
232 | op.add_option("--ethtool", dest="ethtool") | ||
233 | op.add_option("--gateway", dest="gateway") | ||
234 | op.add_option("--hostname", dest="hostname") | ||
235 | op.add_option("--ip", dest="ip") | ||
236 | op.add_option("--mtu", dest="mtu") | ||
237 | op.add_option("--nameserver", dest="nameserver") | ||
238 | op.add_option("--netmask", dest="netmask") | ||
239 | op.add_option("--nodns", dest="nodns", action="store_true", | ||
240 | default=False) | ||
241 | op.add_option("--onboot", dest="onboot", action="store", | ||
242 | type="ksboolean") | ||
243 | op.add_option("--wepkey", dest="wepkey") | ||
244 | return op | ||
245 | |||
246 | def parse(self, args): | ||
247 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
248 | nd = self.handler.NetworkData() | ||
249 | self._setToObj(self.op, opts, nd) | ||
250 | nd.lineno = self.lineno | ||
251 | |||
252 | # Check for duplicates in the data list. | ||
253 | if nd in self.dataList(): | ||
254 | warnings.warn(_("A network device with the name %s has already been defined.") % nd.device) | ||
255 | |||
256 | return nd | ||
257 | |||
258 | def dataList(self): | ||
259 | return self.network | ||
260 | |||
261 | class FC4_Network(FC3_Network): | ||
262 | removedKeywords = FC3_Network.removedKeywords | ||
263 | removedAttrs = FC3_Network.removedAttrs | ||
264 | |||
265 | def _getParser(self): | ||
266 | op = FC3_Network._getParser(self) | ||
267 | op.add_option("--notksdevice", dest="notksdevice", action="store_true", | ||
268 | default=False) | ||
269 | return op | ||
270 | |||
271 | class FC6_Network(FC4_Network): | ||
272 | removedKeywords = FC4_Network.removedKeywords | ||
273 | removedAttrs = FC4_Network.removedAttrs | ||
274 | |||
275 | def _getParser(self): | ||
276 | op = FC4_Network._getParser(self) | ||
277 | op.add_option("--noipv4", dest="noipv4", action="store_true", | ||
278 | default=False) | ||
279 | op.add_option("--noipv6", dest="noipv6", action="store_true", | ||
280 | default=False) | ||
281 | return op | ||
282 | |||
283 | class F8_Network(FC6_Network): | ||
284 | removedKeywords = FC6_Network.removedKeywords | ||
285 | removedAttrs = FC6_Network.removedAttrs | ||
286 | |||
287 | def _getParser(self): | ||
288 | op = FC6_Network._getParser(self) | ||
289 | op.add_option("--ipv6", dest="ipv6") | ||
290 | return op | ||
291 | |||
292 | class F9_Network(F8_Network): | ||
293 | removedKeywords = F8_Network.removedKeywords | ||
294 | removedAttrs = F8_Network.removedAttrs | ||
295 | |||
296 | def __init__(self, writePriority=0, *args, **kwargs): | ||
297 | F8_Network.__init__(self, writePriority, *args, **kwargs) | ||
298 | self.bootprotoList.append(BOOTPROTO_QUERY) | ||
299 | |||
300 | def _getParser(self): | ||
301 | op = F8_Network._getParser(self) | ||
302 | op.add_option("--bootproto", dest="bootProto", | ||
303 | default=BOOTPROTO_DHCP, | ||
304 | choices=self.bootprotoList) | ||
305 | return op | ||
306 | |||
307 | class F16_Network(F9_Network): | ||
308 | removedKeywords = F9_Network.removedKeywords | ||
309 | removedAttrs = F9_Network.removedAttrs | ||
310 | |||
311 | def __init__(self, writePriority=0, *args, **kwargs): | ||
312 | F9_Network.__init__(self, writePriority, *args, **kwargs) | ||
313 | self.bootprotoList.append(BOOTPROTO_IBFT) | ||
314 | |||
315 | def _getParser(self): | ||
316 | op = F9_Network._getParser(self) | ||
317 | op.add_option("--activate", dest="activate", action="store_true", | ||
318 | default=False) | ||
319 | op.add_option("--nodefroute", dest="nodefroute", action="store_true", | ||
320 | default=False) | ||
321 | op.add_option("--wpakey", dest="wpakey", action="store", default="") | ||
322 | return op | ||
323 | |||
324 | class RHEL4_Network(FC3_Network): | ||
325 | removedKeywords = FC3_Network.removedKeywords | ||
326 | removedAttrs = FC3_Network.removedAttrs | ||
327 | |||
328 | def _getParser(self): | ||
329 | op = FC3_Network._getParser(self) | ||
330 | op.add_option("--notksdevice", dest="notksdevice", action="store_true", | ||
331 | default=False) | ||
332 | return op | ||
333 | |||
334 | class RHEL5_Network(FC6_Network): | ||
335 | removedKeywords = FC6_Network.removedKeywords | ||
336 | removedAttrs = FC6_Network.removedAttrs | ||
337 | |||
338 | def __init__(self, writePriority=0, *args, **kwargs): | ||
339 | FC6_Network.__init__(self, writePriority, *args, **kwargs) | ||
340 | self.bootprotoList.append(BOOTPROTO_QUERY) | ||
341 | |||
342 | def _getParser(self): | ||
343 | op = FC6_Network._getParser(self) | ||
344 | op.add_option("--bootproto", dest="bootProto", | ||
345 | default=BOOTPROTO_DHCP, | ||
346 | choices=self.bootprotoList) | ||
347 | return op | ||
348 | |||
349 | class RHEL6_Network(F9_Network): | ||
350 | removedKeywords = F9_Network.removedKeywords | ||
351 | removedAttrs = F9_Network.removedAttrs | ||
352 | |||
353 | def __init__(self, writePriority=0, *args, **kwargs): | ||
354 | F9_Network.__init__(self, writePriority, *args, **kwargs) | ||
355 | self.bootprotoList.append(BOOTPROTO_IBFT) | ||
356 | |||
357 | def _getParser(self): | ||
358 | op = F9_Network._getParser(self) | ||
359 | op.add_option("--activate", dest="activate", action="store_true", | ||
360 | default=False) | ||
361 | op.add_option("--nodefroute", dest="nodefroute", action="store_true", | ||
362 | default=False) | ||
363 | return op | ||