7cfb27f10462d5274c1a9781d7785af3638be01e
[tools/mic.git] / mic / kickstart / custom_commands / installerfw.py
1 #!/usr/bin/python -tt
2 #
3 # Copyright (c) 2013 Intel, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 # for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 from pykickstart.base import *
19 from pykickstart.options import *
20 from mic import msger
21
22 class Mic_installerfw(KickstartCommand):
23     """ This class implements the "installerfw_plugins" KS option. The argument
24     of the option is a comman-separated list of MIC features which have to be
25     disabled and instead, will be done in the installer. For example,
26     "installerfw_plugins=bootloader" disables all the MIC code which installs
27     the bootloader to the target images, and instead, the bootlodaer will be
28     installed by the installer framework plugin.
29
30     The plugin is a program which is external to MIC, it comes from the
31     installation repositories and can be executed by MIC in order to perform
32     various configuration actions. The main point here is to make sure MIC has
33     no hard-wired knoledge about the target OS configuration. """
34
35     removedKeywords = KickstartCommand.removedKeywords
36     removedAttrs = KickstartCommand.removedAttrs
37
38     def __init__(self, *args, **kwargs):
39         KickstartCommand.__init__(self, *args, **kwargs)
40         self.op = self._getParser()
41
42     def __str__(self):
43         retval = KickstartCommand.__str__(self)
44
45         if self.features:
46             retval += "# Enable installer framework plugins\ninstallerfw_plugins\n"
47
48         return retval
49
50     def _getParser(self):
51         op = KSOptionParser()
52         return op
53
54     def parse(self, args):
55         if self.currentCmd == "installerfw":
56             msger.warning("please, use 'installerfw_plugins' instead of " \
57                           "'installerfw', the latter is obsolete and will be " \
58                           "removed in future releases")
59
60         (_, extra) = self.op.parse_args(args=args, lineno=self.lineno)
61
62         if len(extra) != 1:
63             msg = "Kickstart command \"%s\" requires one " \
64                   "argumet - a list of legacy features to disable" % self.currentCmd
65             raise KickstartValueError, formatErrorMsg(self.lineno, msg = msg)
66
67         self.features = extra[0].split(",")
68
69         if "extlinux" in self.features:
70             msger.warning("please, use 'bootloader' installer framework " \
71                           "plugin name instead of 'extlinux', the latter " \
72                           "is obsolete and will be removed in future releases")
73             # Rename all occurances of "extlinux" to "bootloader"
74             self.features = [ "bootloader" if x == "extlinux" else x
75                               for x in self.features ]
76
77         return self