diff options
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/commands/logvol.py')
| -rw-r--r-- | scripts/lib/mic/3rdparty/pykickstart/commands/logvol.py | 304 |
1 files changed, 304 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/logvol.py b/scripts/lib/mic/3rdparty/pykickstart/commands/logvol.py new file mode 100644 index 0000000000..c1b9cc3a61 --- /dev/null +++ b/scripts/lib/mic/3rdparty/pykickstart/commands/logvol.py | |||
| @@ -0,0 +1,304 @@ | |||
| 1 | # | ||
| 2 | # Chris Lumens <clumens@redhat.com> | ||
| 3 | # | ||
| 4 | # Copyright 2005, 2006, 2007, 2008 Red Hat, Inc. | ||
| 5 | # | ||
| 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. | ||
| 12 | # | ||
| 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. | ||
| 19 | # | ||
| 20 | from pykickstart.base import * | ||
| 21 | from pykickstart.errors import * | ||
| 22 | from pykickstart.options import * | ||
| 23 | |||
| 24 | import gettext | ||
| 25 | import warnings | ||
| 26 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
| 27 | |||
| 28 | class FC3_LogVolData(BaseData): | ||
| 29 | removedKeywords = BaseData.removedKeywords | ||
| 30 | removedAttrs = BaseData.removedAttrs | ||
| 31 | |||
| 32 | def __init__(self, *args, **kwargs): | ||
| 33 | BaseData.__init__(self, *args, **kwargs) | ||
| 34 | self.fstype = kwargs.get("fstype", "") | ||
| 35 | self.grow = kwargs.get("grow", False) | ||
| 36 | self.maxSizeMB = kwargs.get("maxSizeMB", 0) | ||
| 37 | self.name = kwargs.get("name", "") | ||
| 38 | self.format = kwargs.get("format", True) | ||
| 39 | self.percent = kwargs.get("percent", 0) | ||
| 40 | self.recommended = kwargs.get("recommended", False) | ||
| 41 | self.size = kwargs.get("size", None) | ||
| 42 | self.preexist = kwargs.get("preexist", False) | ||
| 43 | self.vgname = kwargs.get("vgname", "") | ||
| 44 | self.mountpoint = kwargs.get("mountpoint", "") | ||
| 45 | |||
| 46 | def __eq__(self, y): | ||
| 47 | return self.vgname == y.vgname and self.name == y.name | ||
| 48 | |||
| 49 | def _getArgsAsStr(self): | ||
| 50 | retval = "" | ||
| 51 | |||
| 52 | if self.fstype != "": | ||
| 53 | retval += " --fstype=\"%s\"" % self.fstype | ||
| 54 | if self.grow: | ||
| 55 | retval += " --grow" | ||
| 56 | if self.maxSizeMB > 0: | ||
| 57 | retval += " --maxsize=%d" % self.maxSizeMB | ||
| 58 | if not self.format: | ||
| 59 | retval += " --noformat" | ||
| 60 | if self.percent > 0: | ||
| 61 | retval += " --percent=%d" % self.percent | ||
| 62 | if self.recommended: | ||
| 63 | retval += " --recommended" | ||
| 64 | if self.size > 0: | ||
| 65 | retval += " --size=%d" % self.size | ||
| 66 | if self.preexist: | ||
| 67 | retval += " --useexisting" | ||
| 68 | |||
| 69 | return retval | ||
| 70 | |||
| 71 | def __str__(self): | ||
| 72 | retval = BaseData.__str__(self) | ||
| 73 | retval += "logvol %s %s --name=%s --vgname=%s\n" % (self.mountpoint, self._getArgsAsStr(), self.name, self.vgname) | ||
| 74 | return retval | ||
| 75 | |||
| 76 | class FC4_LogVolData(FC3_LogVolData): | ||
| 77 | removedKeywords = FC3_LogVolData.removedKeywords | ||
| 78 | removedAttrs = FC3_LogVolData.removedAttrs | ||
| 79 | |||
| 80 | def __init__(self, *args, **kwargs): | ||
| 81 | FC3_LogVolData.__init__(self, *args, **kwargs) | ||
| 82 | self.bytesPerInode = kwargs.get("bytesPerInode", 4096) | ||
| 83 | self.fsopts = kwargs.get("fsopts", "") | ||
| 84 | |||
| 85 | def _getArgsAsStr(self): | ||
| 86 | retval = FC3_LogVolData._getArgsAsStr(self) | ||
| 87 | |||
| 88 | if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0: | ||
| 89 | retval += " --bytes-per-inode=%d" % self.bytesPerInode | ||
| 90 | if self.fsopts != "": | ||
| 91 | retval += " --fsoptions=\"%s\"" % self.fsopts | ||
| 92 | |||
| 93 | return retval | ||
| 94 | |||
| 95 | class RHEL5_LogVolData(FC4_LogVolData): | ||
| 96 | removedKeywords = FC4_LogVolData.removedKeywords | ||
| 97 | removedAttrs = FC4_LogVolData.removedAttrs | ||
| 98 | |||
| 99 | def __init__(self, *args, **kwargs): | ||
| 100 | FC4_LogVolData.__init__(self, *args, **kwargs) | ||
| 101 | self.encrypted = kwargs.get("encrypted", False) | ||
| 102 | self.passphrase = kwargs.get("passphrase", "") | ||
| 103 | |||
| 104 | def _getArgsAsStr(self): | ||
| 105 | retval = FC4_LogVolData._getArgsAsStr(self) | ||
| 106 | |||
| 107 | if self.encrypted: | ||
| 108 | retval += " --encrypted" | ||
| 109 | |||
| 110 | if self.passphrase != "": | ||
| 111 | retval += " --passphrase=\"%s\"" % self.passphrase | ||
| 112 | |||
| 113 | return retval | ||
| 114 | |||
| 115 | class F9_LogVolData(FC4_LogVolData): | ||
| 116 | removedKeywords = FC4_LogVolData.removedKeywords + ["bytesPerInode"] | ||
| 117 | removedAttrs = FC4_LogVolData.removedAttrs + ["bytesPerInode"] | ||
| 118 | |||
| 119 | def __init__(self, *args, **kwargs): | ||
| 120 | FC4_LogVolData.__init__(self, *args, **kwargs) | ||
| 121 | self.deleteRemovedAttrs() | ||
| 122 | |||
| 123 | self.fsopts = kwargs.get("fsopts", "") | ||
| 124 | self.fsprofile = kwargs.get("fsprofile", "") | ||
| 125 | self.encrypted = kwargs.get("encrypted", False) | ||
| 126 | self.passphrase = kwargs.get("passphrase", "") | ||
| 127 | |||
| 128 | def _getArgsAsStr(self): | ||
| 129 | retval = FC4_LogVolData._getArgsAsStr(self) | ||
| 130 | |||
| 131 | if self.fsprofile != "": | ||
| 132 | retval += " --fsprofile=\"%s\"" % self.fsprofile | ||
| 133 | if self.encrypted: | ||
| 134 | retval += " --encrypted" | ||
| 135 | |||
| 136 | if self.passphrase != "": | ||
| 137 | retval += " --passphrase=\"%s\"" % self.passphrase | ||
| 138 | |||
| 139 | return retval | ||
| 140 | |||
| 141 | class F12_LogVolData(F9_LogVolData): | ||
| 142 | removedKeywords = F9_LogVolData.removedKeywords | ||
| 143 | removedAttrs = F9_LogVolData.removedAttrs | ||
| 144 | |||
| 145 | def __init__(self, *args, **kwargs): | ||
| 146 | F9_LogVolData.__init__(self, *args, **kwargs) | ||
| 147 | self.deleteRemovedAttrs() | ||
| 148 | |||
| 149 | self.escrowcert = kwargs.get("escrowcert", "") | ||
| 150 | self.backuppassphrase = kwargs.get("backuppassphrase", False) | ||
| 151 | |||
| 152 | def _getArgsAsStr(self): | ||
| 153 | retval = F9_LogVolData._getArgsAsStr(self) | ||
| 154 | |||
| 155 | if self.encrypted and self.escrowcert != "": | ||
| 156 | retval += " --escrowcert=\"%s\"" % self.escrowcert | ||
| 157 | |||
| 158 | if self.backuppassphrase: | ||
| 159 | retval += " --backuppassphrase" | ||
| 160 | |||
| 161 | return retval | ||
| 162 | |||
| 163 | F14_LogVolData = F12_LogVolData | ||
| 164 | |||
| 165 | class F15_LogVolData(F14_LogVolData): | ||
| 166 | removedKeywords = F14_LogVolData.removedKeywords | ||
| 167 | removedAttrs = F14_LogVolData.removedAttrs | ||
| 168 | |||
| 169 | def __init__(self, *args, **kwargs): | ||
| 170 | F14_LogVolData.__init__(self, *args, **kwargs) | ||
| 171 | self.label = kwargs.get("label", "") | ||
| 172 | |||
| 173 | def _getArgsAsStr(self): | ||
| 174 | retval = F14_LogVolData._getArgsAsStr(self) | ||
| 175 | |||
| 176 | if self.label != "": | ||
| 177 | retval += " --label=\"%s\"" % self.label | ||
| 178 | |||
| 179 | return retval | ||
| 180 | |||
| 181 | class FC3_LogVol(KickstartCommand): | ||
| 182 | removedKeywords = KickstartCommand.removedKeywords | ||
| 183 | removedAttrs = KickstartCommand.removedAttrs | ||
| 184 | |||
| 185 | def __init__(self, writePriority=133, *args, **kwargs): | ||
| 186 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
| 187 | self.op = self._getParser() | ||
| 188 | |||
| 189 | self.lvList = kwargs.get("lvList", []) | ||
| 190 | |||
| 191 | def __str__(self): | ||
| 192 | retval = "" | ||
| 193 | |||
| 194 | for part in self.lvList: | ||
| 195 | retval += part.__str__() | ||
| 196 | |||
| 197 | return retval | ||
| 198 | |||
| 199 | def _getParser(self): | ||
| 200 | def lv_cb (option, opt_str, value, parser): | ||
| 201 | parser.values.format = False | ||
| 202 | parser.values.preexist = True | ||
| 203 | |||
| 204 | op = KSOptionParser() | ||
| 205 | op.add_option("--fstype", dest="fstype") | ||
| 206 | op.add_option("--grow", dest="grow", action="store_true", | ||
| 207 | default=False) | ||
| 208 | op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int", | ||
| 209 | nargs=1) | ||
| 210 | op.add_option("--name", dest="name", required=1) | ||
| 211 | op.add_option("--noformat", action="callback", callback=lv_cb, | ||
| 212 | dest="format", default=True, nargs=0) | ||
| 213 | op.add_option("--percent", dest="percent", action="store", type="int", | ||
| 214 | nargs=1) | ||
| 215 | op.add_option("--recommended", dest="recommended", action="store_true", | ||
| 216 | default=False) | ||
| 217 | op.add_option("--size", dest="size", action="store", type="int", | ||
| 218 | nargs=1) | ||
| 219 | op.add_option("--useexisting", dest="preexist", action="store_true", | ||
| 220 | default=False) | ||
| 221 | op.add_option("--vgname", dest="vgname", required=1) | ||
| 222 | return op | ||
| 223 | |||
| 224 | def parse(self, args): | ||
| 225 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
| 226 | |||
| 227 | if len(extra) == 0: | ||
| 228 | raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "logvol") | ||
| 229 | |||
| 230 | lvd = self.handler.LogVolData() | ||
| 231 | self._setToObj(self.op, opts, lvd) | ||
| 232 | lvd.lineno = self.lineno | ||
| 233 | lvd.mountpoint=extra[0] | ||
| 234 | |||
| 235 | # Check for duplicates in the data list. | ||
| 236 | if lvd in self.dataList(): | ||
| 237 | warnings.warn(_("A logical volume with the name %s has already been defined in volume group %s.") % (lvd.device, lvd.vgname)) | ||
| 238 | |||
| 239 | return lvd | ||
| 240 | |||
| 241 | def dataList(self): | ||
| 242 | return self.lvList | ||
| 243 | |||
| 244 | class FC4_LogVol(FC3_LogVol): | ||
| 245 | removedKeywords = FC3_LogVol.removedKeywords | ||
| 246 | removedAttrs = FC3_LogVol.removedAttrs | ||
| 247 | |||
| 248 | def _getParser(self): | ||
| 249 | op = FC3_LogVol._getParser(self) | ||
| 250 | op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store", | ||
| 251 | type="int", nargs=1) | ||
| 252 | op.add_option("--fsoptions", dest="fsopts") | ||
| 253 | return op | ||
| 254 | |||
| 255 | class RHEL5_LogVol(FC4_LogVol): | ||
| 256 | removedKeywords = FC4_LogVol.removedKeywords | ||
| 257 | removedAttrs = FC4_LogVol.removedAttrs | ||
| 258 | |||
| 259 | def _getParser(self): | ||
| 260 | op = FC4_LogVol._getParser(self) | ||
| 261 | op.add_option("--encrypted", action="store_true", default=False) | ||
| 262 | op.add_option("--passphrase") | ||
| 263 | return op | ||
| 264 | |||
| 265 | class F9_LogVol(FC4_LogVol): | ||
| 266 | removedKeywords = FC4_LogVol.removedKeywords | ||
| 267 | removedAttrs = FC4_LogVol.removedAttrs | ||
| 268 | |||
| 269 | def _getParser(self): | ||
| 270 | op = FC4_LogVol._getParser(self) | ||
| 271 | op.add_option("--bytes-per-inode", deprecated=1) | ||
| 272 | op.add_option("--fsprofile", dest="fsprofile", action="store", | ||
| 273 | type="string", nargs=1) | ||
| 274 | op.add_option("--encrypted", action="store_true", default=False) | ||
| 275 | op.add_option("--passphrase") | ||
| 276 | return op | ||
| 277 | |||
| 278 | class F12_LogVol(F9_LogVol): | ||
| 279 | removedKeywords = F9_LogVol.removedKeywords | ||
| 280 | removedAttrs = F9_LogVol.removedAttrs | ||
| 281 | |||
| 282 | def _getParser(self): | ||
| 283 | op = F9_LogVol._getParser(self) | ||
| 284 | op.add_option("--escrowcert") | ||
| 285 | op.add_option("--backuppassphrase", action="store_true", default=False) | ||
| 286 | return op | ||
| 287 | |||
| 288 | class F14_LogVol(F12_LogVol): | ||
| 289 | removedKeywords = F12_LogVol.removedKeywords | ||
| 290 | removedAttrs = F12_LogVol.removedAttrs | ||
| 291 | |||
| 292 | def _getParser(self): | ||
| 293 | op = F12_LogVol._getParser(self) | ||
| 294 | op.remove_option("--bytes-per-inode") | ||
| 295 | return op | ||
| 296 | |||
| 297 | class F15_LogVol(F14_LogVol): | ||
| 298 | removedKeywords = F14_LogVol.removedKeywords | ||
| 299 | removedAttrs = F14_LogVol.removedAttrs | ||
| 300 | |||
| 301 | def _getParser(self): | ||
| 302 | op = F14_LogVol._getParser(self) | ||
| 303 | op.add_option("--label") | ||
| 304 | return op | ||
