* pykickstart/commands/logvol.py (FC4_LogVol._setClassData): Fix
[pykickstart.git] / pykickstart / commands / logvol.py
blob8e398824dc09a7273d070aa5b95712ec2d9847e8
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007 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 *
21 from pykickstart.errors import *
22 from pykickstart.options import *
24 from rhpl.translate import _
25 import rhpl.translate as translate
27 translate.textdomain("pykickstart")
29 class FC3_LogVolData(BaseData):
30 def __init__(self, fstype="", grow=False, maxSizeMB=0, name="",
31 format=True, percent=0, recommended=False, size=None,
32 preexist=False, vgname="", mountpoint=""):
33 BaseData.__init__(self)
34 self.fstype = fstype
35 self.grow = grow
36 self.maxSizeMB = maxSizeMB
37 self.name = name
38 self.format = format
39 self.percent = percent
40 self.recommended = recommended
41 self.size = size
42 self.preexist = preexist
43 self.vgname = vgname
44 self.mountpoint = mountpoint
46 def _getArgsAsStr(self):
47 retval = ""
49 if self.fstype != "":
50 retval += " --fstype=\"%s\"" % self.fstype
51 if self.grow:
52 retval += " --grow"
53 if self.maxSizeMB > 0:
54 retval += " --maxsize=%d" % self.maxSizeMB
55 if not self.format:
56 retval += " --noformat"
57 if self.percent > 0:
58 retval += " --percent=%d" % self.percent
59 if self.recommended:
60 retval += " --recommended"
61 if self.size > 0:
62 retval += " --size=%d" % self.size
63 if self.preexist:
64 retval += " --useexisting"
66 return retval
68 def __str__(self):
69 return "logvol %s %s --name=%s --vgname=%s\n" % (self.mountpoint, self._getArgsAsStr(), self.name, self.vgname)
71 class FC4_LogVolData(FC3_LogVolData):
72 def __init__(self, bytesPerInode=4096, fsopts="", fstype="", grow=False,
73 maxSizeMB=0, name="", format=True, percent=0,
74 recommended=False, size=None, preexist=False, vgname="",
75 mountpoint=""):
76 FC3_LogVolData.__init__(self, fstype=fstype, grow=grow,
77 maxSizeMB=maxSizeMB, name=name,
78 format=format, percent=percent,
79 recommended=recommended, size=size,
80 preexist=preexist, vgname=vgname,
81 mountpoint=mountpoint)
82 self.bytesPerInode = bytesPerInode
83 self.fsopts = fsopts
85 def _getArgsAsStr(self):
86 retval = FC3_LogVolData._getArgsAsStr(self)
88 if self.bytesPerInode > 0:
89 retval += " --bytes-per-inode=%d" % self.bytesPerInode
90 if self.fsopts != "":
91 retval += " --fsoptions=\"%s\"" % self.fsopts
93 return retval
95 class FC3_LogVol(KickstartCommand):
96 def __init__(self, writePriority=132, lvList=None):
97 KickstartCommand.__init__(self, writePriority)
98 self._setClassData()
100 if lvList == None:
101 lvList = []
103 self.lvList = lvList
105 def __str__(self):
106 retval = ""
108 for part in self.lvList:
109 retval += part.__str__()
111 return retval
113 def _setClassData(self):
114 self.dataType = FC3_LogVolData
116 def _getParser(self):
117 def lv_cb (option, opt_str, value, parser):
118 parser.values.format = False
119 parser.values.preexist = True
121 op = KSOptionParser(lineno=self.lineno)
122 op.add_option("--fstype", dest="fstype")
123 op.add_option("--grow", dest="grow", action="store_true",
124 default=False)
125 op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int",
126 nargs=1)
127 op.add_option("--name", dest="name", required=1)
128 op.add_option("--noformat", action="callback", callback=lv_cb,
129 dest="format", default=True, nargs=0)
130 op.add_option("--percent", dest="percent", action="store", type="int",
131 nargs=1)
132 op.add_option("--recommended", dest="recommended", action="store_true",
133 default=False)
134 op.add_option("--size", dest="size", action="store", type="int",
135 nargs=1)
136 op.add_option("--useexisting", dest="preexist", action="store_true",
137 default=False)
138 op.add_option("--vgname", dest="vgname", required=1)
139 return op
141 def parse(self, args):
142 op = self._getParser()
143 (opts, extra) = op.parse_args(args=args)
145 if len(extra) == 0:
146 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "logvol")
148 lvd = self.dataType()
149 self._setToObj(op, opts, lvd)
150 lvd.mountpoint=extra[0]
151 self.add(lvd)
153 def add(self, newObj):
154 self.lvList.append(newObj)
156 class FC4_LogVol(FC3_LogVol):
157 def __init__(self, writePriority=132, lvList=None):
158 FC3_LogVol.__init__(self, writePriority, lvList)
160 def _getParser(self):
161 op = FC3_LogVol._getParser(self)
162 op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store",
163 type="int", nargs=1)
164 op.add_option("--fsoptions", dest="fsopts")
165 return op
167 def _setClassData(self):
168 self.dataType = FC4_LogVolData