PageRenderTime 91ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/src/kickstart/kgen.py

https://github.com/rocksclusters/base
Python | 509 lines | 74 code | 19 blank | 416 comment | 14 complexity | b1a0d5086c0921f618781f12f80aa953 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, AGPL-1.0, GPL-2.0, LGPL-2.1, AGPL-3.0, CPL-1.0, BSD-3-Clause
  1. #! @PYTHON@
  2. #
  3. # $Id: kgen.py,v 1.25 2012/11/27 00:48:38 phil Exp $
  4. #
  5. # @Copyright@
  6. #
  7. # Rocks(r)
  8. # www.rocksclusters.org
  9. # version 6.2 (SideWinder)
  10. #
  11. # Copyright (c) 2000 - 2014 The Regents of the University of California.
  12. # All rights reserved.
  13. #
  14. # Redistribution and use in source and binary forms, with or without
  15. # modification, are permitted provided that the following conditions are
  16. # met:
  17. #
  18. # 1. Redistributions of source code must retain the above copyright
  19. # notice, this list of conditions and the following disclaimer.
  20. #
  21. # 2. Redistributions in binary form must reproduce the above copyright
  22. # notice unmodified and in its entirety, this list of conditions and the
  23. # following disclaimer in the documentation and/or other materials provided
  24. # with the distribution.
  25. #
  26. # 3. All advertising and press materials, printed or electronic, mentioning
  27. # features or use of this software must display the following acknowledgement:
  28. #
  29. # "This product includes software developed by the Rocks(r)
  30. # Cluster Group at the San Diego Supercomputer Center at the
  31. # University of California, San Diego and its contributors."
  32. #
  33. # 4. Except as permitted for the purposes of acknowledgment in paragraph 3,
  34. # neither the name or logo of this software nor the names of its
  35. # authors may be used to endorse or promote products derived from this
  36. # software without specific prior written permission. The name of the
  37. # software includes the following terms, and any derivatives thereof:
  38. # "Rocks", "Rocks Clusters", and "Avalanche Installer". For licensing of
  39. # the associated name, interested parties should contact Technology
  40. # Transfer & Intellectual Property Services, University of California,
  41. # San Diego, 9500 Gilman Drive, Mail Code 0910, La Jolla, CA 92093-0910,
  42. # Ph: (858) 534-5815, FAX: (858) 534-7345, E-MAIL:invent@ucsd.edu
  43. #
  44. # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
  45. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  46. # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  47. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
  48. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  49. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  50. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  51. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  52. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  53. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  54. # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55. #
  56. # @Copyright@
  57. #
  58. # $Log: kgen.py,v $
  59. # Revision 1.25 2012/11/27 00:48:38 phil
  60. # Copyright Storm for Emerald Boa
  61. #
  62. # Revision 1.24 2012/09/18 23:33:17 clem
  63. # I need to make kickstart.cgi loadable as a module (I need that in the EC2 roll)
  64. # then i fixed all the other classes in the pylib
  65. #
  66. # Revision 1.23 2012/05/06 05:48:44 phil
  67. # Copyright Storm for Mamba
  68. #
  69. # Revision 1.22 2011/07/23 02:30:47 phil
  70. # Viper Copyright
  71. #
  72. # Revision 1.21 2010/09/07 23:53:07 bruno
  73. # star power for gb
  74. #
  75. # Revision 1.20 2009/05/01 19:07:07 mjk
  76. # chimi con queso
  77. #
  78. # Revision 1.19 2009/04/27 18:03:33 bruno
  79. # remove dead setRCS* and getRCS* functions
  80. #
  81. # Revision 1.18 2008/10/18 00:56:01 mjk
  82. # copyright 5.1
  83. #
  84. # Revision 1.17 2008/03/06 23:41:43 mjk
  85. # copyright storm on
  86. #
  87. # Revision 1.16 2007/12/13 02:53:40 bruno
  88. # can now build a bootable kernel CD and build a physical frontend with V
  89. # on RHEL 5 update 1
  90. #
  91. # Revision 1.15 2007/12/10 21:28:35 bruno
  92. # the base roll now contains several elements from the HPC roll, thus
  93. # making the HPC roll optional.
  94. #
  95. # this also includes changes to help build and configure VMs for V.
  96. #
  97. # Revision 1.14 2007/08/14 20:24:34 anoop
  98. # Moved the generator class functions from kgen.py to pylib.
  99. # This allows us to simplify kgen, and make the functions
  100. # accessible to the command line as well.
  101. #
  102. # Revision 1.13 2007/06/23 04:03:23 mjk
  103. # mars hill copyright
  104. #
  105. # Revision 1.12 2006/09/11 22:47:16 mjk
  106. # monkey face copyright
  107. #
  108. # Revision 1.11 2006/08/10 00:09:37 mjk
  109. # 4.2 copyright
  110. #
  111. # Revision 1.10 2006/01/27 22:29:43 bruno
  112. # stable (mostly) after integration of new foundation and localization code
  113. #
  114. # Revision 1.9 2006/01/16 06:48:58 mjk
  115. # fix python path for source built foundation python
  116. #
  117. # Revision 1.8 2005/10/12 18:08:39 mjk
  118. # final copyright for 4.1
  119. #
  120. # Revision 1.7 2005/10/04 00:11:40 mjk
  121. # fixed order debug message now that descriptions tags are stripped
  122. #
  123. # Revision 1.6 2005/09/16 01:02:19 mjk
  124. # updated copyright
  125. #
  126. # Revision 1.5 2005/08/25 16:57:20 mjk
  127. # set arch by default
  128. #
  129. # Revision 1.4 2005/07/11 23:51:35 mjk
  130. # use rocks version of python
  131. #
  132. # Revision 1.3 2005/05/24 21:21:54 mjk
  133. # update copyright, release is not any closer
  134. #
  135. # Revision 1.2 2005/03/12 00:01:52 bruno
  136. # minor checkin
  137. #
  138. # Revision 1.1 2005/03/01 02:02:48 mjk
  139. # moved from core to base
  140. #
  141. # Revision 1.69 2005/02/14 20:10:34 mjk
  142. # fix arch check
  143. #
  144. # Revision 1.68 2005/02/11 23:38:16 mjk
  145. # - blow up the bridge
  146. # - kgen and kroll do actually work (but kroll is not complete)
  147. # - file,roll attrs added to all tags by kpp
  148. # - gen has generator,nodefilter base classes
  149. # - replaced rcs ci/co code with new stuff
  150. # - very close to adding rolls on the fly
  151. #
  152. # Revision 1.67 2004/12/11 00:26:43 fds
  153. # Fixed bug that would cause touched files with perms attributes to fail (such as in shepherd.xml).
  154. #
  155. # Revision 1.66 2004/11/24 20:30:55 bruno
  156. # this fixes the following problem:
  157. #
  158. # - someone creates a new appliance
  159. # - in the node XML for the new appliance, they include custom partitioning info
  160. # - when kickstart.cgi is run, it outputs:
  161. #
  162. # part <custom 1>
  163. # part <custom 2>
  164. # part <custom 3>
  165. # .
  166. # .
  167. # .
  168. # part
  169. #
  170. # the last 'part' tells the installer to add the default partitioning (this
  171. # came from auto-partition.xml), thus, the new appliance gets the custom
  172. # partitioning *and* the default partitioning.
  173. #
  174. # the fix: if custom partitioning is specified, then don't output 'part'. if
  175. # custom partitioning is not specified, then do output 'part'.
  176. #
  177. # Revision 1.65 2004/09/18 15:09:34 bruno
  178. # ok, i think i really got it now.
  179. #
  180. # backed out the change to kgen.py
  181. #
  182. # moved the 'disable' kernel package from node-thin to media-server
  183. #
  184. # and, make sure that a kickstarting host doesn't explictly call out the
  185. # kernel or kernel-smp packages
  186. #
  187. # Revision 1.64 2004/09/18 14:30:15 bruno
  188. # some tweaks to let anaconda decide which package to install (kernel or
  189. # kernel-smp) because if we explictly set it (e.g., kernel-smp), then
  190. # there is the case where the kernel-smp package is installed on an EM64T
  191. # node and only the 'kernel' package should be on it.
  192. #
  193. # Revision 1.63 2004/08/27 18:21:06 bruno
  194. # add a package to the "off" list when it is not in the "on" list.
  195. #
  196. # and, a package in the "on" list means it must not be in the "off" list.
  197. #
  198. # makes sense, yes?
  199. #
  200. # Revision 1.62 2004/04/27 17:18:59 fds
  201. # I respectfully submit the following changes. It is less code, more inline with
  202. # the strategies used in other parts of the kickstart generation, and has the
  203. # same behavior as before.
  204. #
  205. # Revision 1.61 2004/04/27 04:38:48 bruno
  206. # added ability to just print out 'pre' section.
  207. #
  208. # Revision 1.60 2004/03/25 03:15:41 bruno
  209. # touch 'em all!
  210. #
  211. # update version numbers to 3.2.0 and update copyrights
  212. #
  213. # Revision 1.59 2004/02/25 18:12:33 mjk
  214. # strip ws from packages
  215. #
  216. # Revision 1.58 2004/02/13 20:12:44 bruno
  217. # added support for LVM tags
  218. #
  219. # Revision 1.57 2004/02/07 00:10:07 fds
  220. # Rollback to version 1.55.
  221. #
  222. # Revision 1.55 2004/02/03 01:52:05 fds
  223. # More flexible yet. Can now call out multiple individual sections.
  224. #
  225. # Revision 1.54 2004/02/02 18:37:03 fds
  226. # Support for Wide Area installs. New wanKickstart() method in kcgi issues
  227. # a small ks file with external roll url followed by the installclass, and
  228. # thats it.
  229. #
  230. # Kgen now knows how to only output the installclass.
  231. #
  232. # I dont love this code, but it is the first step.
  233. #
  234. # Revision 1.53 2003/11/13 04:55:02 mjk
  235. # remove self.null for older python versions
  236. #
  237. # Revision 1.52 2003/11/06 01:00:00 mjk
  238. # use file tag for logging
  239. #
  240. # Revision 1.51 2003/10/16 22:14:14 fds
  241. # Cleaning up after mason. :)
  242. #
  243. # Revision 1.50 2003/10/16 21:31:17 mjk
  244. # arch attribute is now list based
  245. #
  246. # Revision 1.49 2003/10/15 22:19:47 bruno
  247. # fixes for taroon
  248. #
  249. # Revision 1.48 2003/09/16 18:08:35 fds
  250. # Using KickstartError in trinity. Errors go to stderr.
  251. #
  252. # Revision 1.47 2003/09/04 17:37:20 fds
  253. # Small change to error message
  254. #
  255. # Revision 1.46 2003/08/26 23:17:29 mjk
  256. # missing a newline in file output
  257. #
  258. # Revision 1.45 2003/08/26 22:44:20 mjk
  259. # - File tag now takes "expr" attribute (command evaluation)
  260. # - Conversion of old code to file tags
  261. # - Added media-server (used to be server)
  262. # - Killed replace-server on the hpc roll
  263. # - Updated Server database membership (now a media-server)
  264. # - Added Public field to the membership table
  265. # - Insert-ethers only allows a subset of memberships (Public ones) to be
  266. # inserted.
  267. # - Added getArch() to Application class
  268. # - Kickstart trinity (kcgi,kpp,kgen) all updated self.arch initial value
  269. #
  270. # Revision 1.44 2003/08/20 21:12:19 mjk
  271. # - run file tags in a subshell
  272. # - probe lsmod for keyboard type
  273. #
  274. # Revision 1.43 2003/08/15 22:34:46 mjk
  275. # 3.0.0 copyright
  276. #
  277. # Revision 1.42 2003/08/14 17:38:38 mjk
  278. # AW fixes
  279. #
  280. # Revision 1.41 2003/08/09 00:58:11 fds
  281. # Better and clearer exception handling.
  282. # Needed when kpp fails.
  283. #
  284. # Revision 1.40 2003/07/31 17:51:12 bruno
  285. # removed debug statements
  286. #
  287. # Revision 1.39 2003/07/31 17:50:49 bruno
  288. # one-liner that fixes updating the same configuration file
  289. #
  290. # Revision 1.38 2003/07/28 18:40:57 phil
  291. # updated checking in files to RCS
  292. #
  293. # Revision 1.37 2003/07/25 00:00:29 phil
  294. # Added putting config files into repository before changing
  295. # them.
  296. #
  297. # Revision 1.36 2003/07/22 21:30:19 fds
  298. # No extra newlines in file tag output.
  299. #
  300. # Revision 1.35 2003/07/21 19:37:57 fds
  301. # Simplified kgen (regular append) with support for owner,
  302. # perms, and vars=literal
  303. #
  304. # Revision 1.34 2003/07/21 19:17:29 fds
  305. # NOT USED - Fancy Append.
  306. #
  307. # Revision 1.32 2003/07/17 22:23:56 fds
  308. # Added 'owner' and 'perms' file attributes
  309. #
  310. # Revision 1.31 2003/07/16 20:56:20 fds
  311. # New append-once fileMode attribute to <file> tags.
  312. #
  313. # Revision 1.30 2003/07/07 20:16:52 bruno
  314. # updates for rolls
  315. #
  316. # Revision 1.29 2003/05/22 16:36:35 mjk
  317. # copyright
  318. #
  319. # Revision 1.28 2003/05/21 18:57:31 mjk
  320. # grid integration checkpoint
  321. #
  322. # Revision 1.27 2003/04/28 23:51:09 mjk
  323. # who knows
  324. #
  325. # Revision 1.26 2003/04/28 21:52:51 mjk
  326. # added order section
  327. #
  328. # Revision 1.25 2003/04/24 16:59:41 mjk
  329. # - add order tags
  330. # - edge and order tags can have children
  331. # This just make the graph look nicer, no functional change
  332. # - added include directory
  333. # - moved install class code into include directory
  334. # - dependecies enforced via topological sort
  335. # - weight attributes are dead
  336. # - long live order tags
  337. # - the 'gen' attribute is currently ignored. This will be used to support
  338. # other graph ordering requirements (e.g. testing, cfengine, ...)
  339. #
  340. # Revision 1.24 2003/02/17 18:43:04 bruno
  341. # updated copyright to 2003
  342. #
  343. # Revision 1.23 2002/11/07 18:13:44 mjk
  344. # ia64 changes
  345. #
  346. # Revision 1.22 2002/10/18 21:33:26 mjk
  347. # Rocks 2.3 Copyright
  348. #
  349. # Revision 1.21 2002/09/26 11:29:47 bruno
  350. # fixed a bug in the architecture processing
  351. #
  352. # Revision 1.20 2002/07/03 23:33:11 bruno
  353. # 7.3 fixes
  354. #
  355. # Revision 1.19 2002/06/28 18:18:49 mjk
  356. # checkpoint for XML vs SQL stuff
  357. # might even work
  358. #
  359. # Revision 1.18 2002/06/17 19:50:02 bruno
  360. # 7.3-isms
  361. #
  362. # Revision 1.17 2002/06/11 20:20:28 mjk
  363. # Added support for release tag
  364. #
  365. # Revision 1.16 2002/02/25 19:08:43 mjk
  366. # Negative package resolution for CDROM and CGI kickstart generation. I
  367. # lost a single line of python code in kpp that fixed this but it didn't
  368. # get checked in. Backed out of Greg's code and fixed my screw up.
  369. #
  370. # Revision 1.13 2002/02/15 23:44:23 mjk
  371. # - Added netscape to frontend
  372. # - Move package trimming
  373. #
  374. # Revision 1.12 2002/02/14 02:12:29 mjk
  375. # - Removed CD copy gui code from insert-ethers
  376. # - Added CD copy code back to install.xml (using rocks-dist)
  377. # - Added copycd command to rocks-dist
  378. # - Added '-' packages logic to kgen
  379. # - Other file changed to support above
  380. #
  381. # Revision 1.11 2002/02/12 23:48:51 mjk
  382. # - Broken (just a checkpoint)
  383. #
  384. # Revision 1.10 2002/02/06 21:22:44 bruno
  385. # all the little things that releases find ...
  386. #
  387. # Revision 1.9 2002/02/05 16:47:42 bruno
  388. # support for deselecting packages
  389. #
  390. # Revision 1.8 2002/01/18 23:27:58 bruno
  391. # updates for 7.2
  392. #
  393. # Revision 1.7 2001/12/03 21:27:59 bruno
  394. # added support to understand the 'partition' flag in the clearpart and part
  395. # tags.
  396. #
  397. # Revision 1.6 2001/11/09 23:50:53 mjk
  398. # - Post release ia64 changes
  399. #
  400. # Revision 1.5 2001/09/14 21:45:42 mjk
  401. # - Testing on ia32 compute nodes
  402. # - A CGI kickstart takes 5 seconds
  403. # - Working on ia64 compute nodes
  404. #
  405. # Revision 1.4 2001/09/10 18:26:38 mjk
  406. # *** empty log message ***
  407. #
  408. # Revision 1.3 2001/09/05 00:27:16 mjk
  409. # main and packages section is correct for compute nodes
  410. #
  411. # Revision 1.2 2001/08/21 01:52:39 mjk
  412. # - <module> tag now prevent multiple inclusion
  413. # - add dot support (ATT graph tool, just changed to GNU, we ship it now)
  414. # - moved kickstart.cgi from rocks-dist RPM over here (called kcgi.py)
  415. # - added <tree><node> tags
  416. #
  417. import os
  418. import sys
  419. import string
  420. import rocks.gen
  421. import rocks.file
  422. import rocks.gen
  423. import rocks.app
  424. from xml.sax._exceptions import SAXParseException
  425. from rocks.util import KickstartError
  426. class App(rocks.app.Application):
  427. def __init__(self, argv):
  428. rocks.app.Application.__init__(self, argv)
  429. self.usage_name = 'Kickstart Generator'
  430. self.usage_version = '@VERSION@'
  431. self.sections = []
  432. self.os = os.uname()[0].lower()
  433. osGenerator = getattr(rocks.gen, 'Generator_%s' % self.os)
  434. self.generator = osGenerator()
  435. self.generator.setArch(self.getArch())
  436. self.generator.setOS(self.os)
  437. self.getopt.s.extend([('a:', 'architecture')])
  438. self.getopt.l.extend([('arch=', 'architecture'),
  439. ('section=', 'name'),
  440. ('postonly', 'show post'),
  441. ])
  442. def usageTail(self):
  443. return ' [file]'
  444. def parseArg(self, c):
  445. if rocks.app.Application.parseArg(self, c):
  446. return 1
  447. elif c[0] in ('-a', '--arch'):
  448. self.generator.setArch(c[1])
  449. elif c[0] == '--section':
  450. self.sections += c[1].split()
  451. elif c[0] == '--postonly':
  452. self.sections.append('post')
  453. else:
  454. return 0
  455. return 1
  456. def run(self):
  457. if self.args:
  458. file = open(self.args[0], 'r')
  459. else:
  460. file = sys.stdin
  461. self.generator.parse(file.read())
  462. print '#'
  463. print '# %s version %s' % (self.usage_name, self.usage_version)
  464. print '#'
  465. sections = self.sections
  466. if not sections:
  467. sections = [
  468. 'order',
  469. 'debug',
  470. 'main',
  471. 'packages',
  472. 'pre',
  473. 'post',
  474. ]
  475. list = []
  476. for s in sections:
  477. list += self.generator.generate(s)
  478. for line in list:
  479. print line.rstrip()
  480. if __name__ == "__main__":
  481. app = App(sys.argv)
  482. app.parseArgs()
  483. try:
  484. app.run()
  485. except KickstartError, msg:
  486. sys.stderr.write("kgen error - %s\n" % msg)
  487. sys.exit(-1)
  488. except SAXParseException, msg:
  489. sys.stderr.write("kgen XML parse exception: %s\n" % msg)
  490. sys.exit(-1)