Add new RHEL7 logvol objects to master
[pykickstart.git] / pykickstart / commands / ignoredisk.py
blob09ede314c6d7d0d89859acda5e7ae9e3ca254d78
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2009 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 from pykickstart.base import KickstartCommand
21 from pykickstart.errors import KickstartValueError, formatErrorMsg
22 from pykickstart.options import KSOptionParser
24 import gettext
25 _ = lambda x: gettext.ldgettext("pykickstart", x)
27 class FC3_IgnoreDisk(KickstartCommand):
28 removedKeywords = KickstartCommand.removedKeywords
29 removedAttrs = KickstartCommand.removedAttrs
31 def __init__(self, writePriority=0, *args, **kwargs):
32 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
33 self.op = self._getParser()
35 self.ignoredisk = kwargs.get("ignoredisk", [])
37 def __str__(self):
38 retval = KickstartCommand.__str__(self)
40 if len(self.ignoredisk) > 0:
41 retval += "ignoredisk --drives=%s\n" % ",".join(self.ignoredisk)
43 return retval
45 def _getParser(self):
46 def drive_cb (option, opt_str, value, parser):
47 for d in value.split(','):
48 parser.values.ensure_value(option.dest, []).append(d)
50 op = KSOptionParser()
51 op.add_option("--drives", dest="ignoredisk", action="callback",
52 callback=drive_cb, nargs=1, type="string", required=1)
53 return op
55 def parse(self, args):
56 (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
57 self._setToSelf(self.op, opts)
58 return self
60 class F8_IgnoreDisk(FC3_IgnoreDisk):
61 removedKeywords = FC3_IgnoreDisk.removedKeywords
62 removedAttrs = FC3_IgnoreDisk.removedAttrs
64 def __init__(self, writePriority=0, *args, **kwargs):
65 FC3_IgnoreDisk.__init__(self, writePriority, *args, **kwargs)
67 self.onlyuse = kwargs.get("onlyuse", [])
69 def __str__(self):
70 retval = KickstartCommand.__str__(self)
72 if len(self.ignoredisk) > 0:
73 retval += "ignoredisk --drives=%s\n" % ",".join(self.ignoredisk)
74 elif len(self.onlyuse) > 0:
75 retval += "ignoredisk --only-use=%s\n" % ",".join(self.onlyuse)
77 return retval
79 def parse(self, args, errorCheck=True):
80 retval = FC3_IgnoreDisk.parse(self, args)
82 if errorCheck:
83 if (len(self.ignoredisk) == 0 and len(self.onlyuse) == 0) or (len(self.ignoredisk) > 0 and (len(self.onlyuse) > 0)):
84 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --drives or --only-use must be specified for ignoredisk command.")))
86 return retval
88 def _getParser(self):
89 def drive_cb (option, opt_str, value, parser):
90 for d in value.split(','):
91 parser.values.ensure_value(option.dest, []).append(d)
93 op = FC3_IgnoreDisk._getParser(self)
94 op.add_option("--drives", dest="ignoredisk", action="callback",
95 callback=drive_cb, nargs=1, type="string")
96 op.add_option("--only-use", dest="onlyuse", action="callback",
97 callback=drive_cb, nargs=1, type="string")
98 return op
100 class RHEL6_IgnoreDisk(F8_IgnoreDisk):
101 removedKeywords = F8_IgnoreDisk.removedKeywords
102 removedAttrs = F8_IgnoreDisk.removedAttrs
104 def __init__(self, writePriority=0, *args, **kwargs):
105 F8_IgnoreDisk.__init__(self, writePriority, *args, **kwargs)
107 self.interactive = kwargs.get("interactive", False)
108 if self.interactive:
109 self.ignoredisk = []
111 def __str__(self):
112 retval = F8_IgnoreDisk.__str__(self)
114 if self.interactive:
115 retval = "ignoredisk --interactive\n"
117 return retval
119 def parse(self, args):
120 retval = F8_IgnoreDisk.parse(self, args, errorCheck=False)
122 howmany = 0
123 if len(self.ignoredisk) > 0:
124 howmany += 1
125 if len(self.onlyuse) > 0:
126 howmany += 1
127 if self.interactive:
128 howmany += 1
129 if howmany != 1:
130 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --drives , --only-use , or --interactive must be specified for ignoredisk command.")))
132 return retval
134 def _getParser(self):
135 op = F8_IgnoreDisk._getParser(self)
136 op.add_option("--interactive", dest="interactive", action="store_true",
137 default=False)
138 return op
140 F14_IgnoreDisk = RHEL6_IgnoreDisk