2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2012, 2013 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 BaseData
, KickstartCommand
21 from pykickstart
.errors
import KickstartParseError
, KickstartValueError
, formatErrorMsg
22 from pykickstart
.options
import KSOptionParser
26 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
28 class FC3_VolGroupData(BaseData
):
29 removedKeywords
= BaseData
.removedKeywords
30 removedAttrs
= BaseData
.removedAttrs
32 def __init__(self
, *args
, **kwargs
):
33 BaseData
.__init
__(self
, *args
, **kwargs
)
34 self
.format
= kwargs
.get("format", True)
35 self
.pesize
= kwargs
.get("pesize", 32768)
36 self
.preexist
= kwargs
.get("preexist", False)
37 self
.vgname
= kwargs
.get("vgname", "")
38 self
.physvols
= kwargs
.get("physvols", [])
44 return self
.vgname
== y
.vgname
49 def _getArgsAsStr(self
):
52 retval
+= " --noformat"
54 retval
+= " --pesize=%d" % self
.pesize
56 retval
+= " --useexisting"
61 retval
= BaseData
.__str
__(self
)
62 retval
+= "volgroup %s" % self
.vgname
63 retval
+= self
._getArgsAsStr
()
65 # Do not output the physical volumes list if --preexist was passed in.
66 # This would be invalid input according to the parse method.
68 retval
+= " " + " ".join(self
.physvols
)
70 return retval
.strip() + "\n"
72 class FC16_VolGroupData(FC3_VolGroupData
):
73 def __init__(self
, *args
, **kwargs
):
74 FC3_VolGroupData
.__init
__(self
, *args
, **kwargs
)
75 self
.reserved_space
= kwargs
.get("reserved-space", 0)
76 self
.reserved_percent
= kwargs
.get("reserved-percent", 0)
78 def _getArgsAsStr(self
):
79 retval
= FC3_VolGroupData
._getArgsAsStr
(self
)
80 if self
.reserved_space
> 0:
81 retval
+= " --reserved-space=%d" % self
.reserved_space
82 if self
.reserved_percent
> 0:
83 retval
+= " --reserved-percent=%d" % self
.reserved_percent
87 class F21_VolGroupData(FC16_VolGroupData
):
88 def __init__(self
, *args
, **kwargs
):
89 FC16_VolGroupData
.__init
__(self
, *args
, **kwargs
)
90 self
.pesize
= kwargs
.get("pesize", 0)
92 class FC3_VolGroup(KickstartCommand
):
93 removedKeywords
= KickstartCommand
.removedKeywords
94 removedAttrs
= KickstartCommand
.removedAttrs
96 def __init__(self
, writePriority
=132, *args
, **kwargs
):
97 KickstartCommand
.__init
__(self
, writePriority
, *args
, **kwargs
)
98 self
.op
= self
._getParser
()
100 self
.vgList
= kwargs
.get("vgList", [])
104 for vg
in self
.vgList
:
105 retval
+= vg
.__str
__()
109 def _getParser(self
):
110 # Have to be a little more complicated to set two values.
111 def vg_cb (option
, opt_str
, value
, parser
):
112 parser
.values
.format
= False
113 parser
.values
.preexist
= True
115 op
= KSOptionParser()
116 op
.add_option("--noformat", action
="callback", callback
=vg_cb
,
117 dest
="format", default
=True, nargs
=0)
118 op
.add_option("--pesize", dest
="pesize", type="int", nargs
=1,
120 op
.add_option("--useexisting", dest
="preexist", action
="store_true",
124 def parse(self
, args
):
125 (opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
126 vg
= self
.handler
.VolGroupData()
127 self
._setToObj
(self
.op
, opts
, vg
)
128 vg
.lineno
= self
.lineno
131 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=_("volgroup must be given a VG name")))
133 if len(extra
) == 1 and not opts
.preexist
:
134 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_("volgroup must be given a list of partitions")))
135 elif len(extra
) > 1 and opts
.preexist
:
136 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_("Members may not be specified for preexisting volgroup")))
141 vg
.physvols
= extra
[1:]
143 # Check for duplicates in the data list.
144 if vg
in self
.dataList():
145 warnings
.warn(_("A volgroup with the name %s has already been defined.") % vg
.vgname
)
152 class FC16_VolGroup(FC3_VolGroup
):
153 def _getParser(self
):
154 def space_cb(option
, opt_str
, value
, parser
):
156 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
="Volume group reserved space must be a positive integer."))
158 parser
.values
.reserved_space
= value
160 def percent_cb(option
, opt_str
, value
, parser
):
161 if not 0 < value
< 100:
162 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
="Volume group reserved space percentage must be between 1 and 99."))
164 parser
.values
.reserved_percent
= value
166 op
= FC3_VolGroup
._getParser
(self
)
167 op
.add_option("--reserved-space", action
="callback", callback
=space_cb
,
168 dest
="reserved_space", type="int", nargs
=1, default
=0)
169 op
.add_option("--reserved-percent", action
="callback", callback
=percent_cb
,
170 dest
="reserved_percent", type="int", nargs
=1, default
=0)
173 class RHEL6_VolGroup(FC3_VolGroup
):
174 def parse(self
, args
):
175 # first call the overriden method
176 retval
= FC3_VolGroup
.parse(self
, args
)
178 # the volgroup command can't be used together with the autopart command
179 # due to the hard to debug behavior their combination introduces
180 if self
.handler
.autopart
.seen
:
181 errorMsg
= _("The volgroup and autopart commands can't be used at the same time")
182 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))
186 class F20_VolGroup(FC16_VolGroup
):
187 def parse(self
, args
):
188 # first call the overriden method
189 retval
= FC16_VolGroup
.parse(self
, args
)
191 # the volgroup command can't be used together with the autopart command
192 # due to the hard to debug behavior their combination introduces
193 if self
.handler
.autopart
.seen
:
194 errorMsg
= _("The volgroup and autopart commands can't be used at the same time")
195 raise KickstartParseError(formatErrorMsg(self
.lineno
, msg
=errorMsg
))
199 class F21_VolGroup(F20_VolGroup
):
200 def _getParser(self
):
201 op
= F20_VolGroup
._getParser
(self
)
202 op
.add_option("--pesize", dest
="pesize", type="int", nargs
=1,