def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) > 1: raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("Only one partition may be specified for driverdisk command." ))) if len(extra) == 1 and opts.source: raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("Only one of --source and partition may be specified for driverdisk command." ))) if not extra and not opts.source: raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("One of --source or partition must be specified for driverdisk command." ))) ddd = self.handler.DriverDiskData() self._setToObj(self.op, opts, ddd) ddd.lineno = self.lineno if len(extra) == 1: ddd.partition = extra[0] return ddd
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) data = self.handler.BTRFSData() self._setToObj(self.op, opts, data) data.lineno = self.lineno if len(extra) == 0: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs must be given a mountpoint"))) if len(extra) == 1 and not data.subvol: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs must be given a list of partitions"))) elif len(extra) == 1: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs subvol requires specification of parent volume"))) if data.subvol and not data.name: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs subvolume requires a name"))) data.mountpoint = extra[0] data.devices = extra[1:] # Check for duplicates in the data list. if data in self.dataList(): warnings.warn(_("A btrfs volume with the mountpoint %s has already been defined.") % data.label) return data
def _parseJoin(self, args): try: # We only support these args opts, remaining = getopt.getopt(args, "", ("client-software=", "server-software=", "membership-software=", "one-time-password="******"no-password", "computer-ou=")) except getopt.GetoptError as ex: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_( "Invalid realm arguments: %s") % ex)) if len(remaining) != 1: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_( "Specify only one realm to join"))) # Parse successful, just use this as the join command self.join_realm = remaining[0] self.join_args = args # Build a discovery command self.discover_options = [] supported_discover_options = ("--client-software", "--server-software", "--membership-software") for (o, a) in opts: if o in supported_discover_options: self.discover_options.append("%s=%s" % (o, a))
def handle_line(self, line): """ :param line: :return: """ try: (param, value) = line.strip().split(maxsplit=1) except ValueError: raise KickstartValueError('invalid line: %s' % line) if param in self.bool_options: if value.lower() not in ('true', 'false'): raise KickstartValueError( 'invalid value for bool property: %s' % line) bool_value = value.lower() == 'true' setattr(self, param, bool_value) elif param == 'default_template': self.default_template = value elif param == 'templates_to_install': self.templates_to_install = value.split(' ') elif param == 'lvm_pool': parsed = value.split('/') if len(parsed) != 2: raise KickstartValueError('invalid value for lvm_pool: %s' % line) self.vg_tpool = (parsed[0], parsed[1]) else: raise KickstartValueError('invalid parameter: %s' % param) self.seen = True
def parse(self, args): retval = F21_LogVol.parse(self, args) if retval.cache_size or retval.cache_mode or retval.cache_pvs: if retval.preexist: err = formatErrorMsg(self.lineno, msg=_("Adding a cache to an existing logical volume is not supported")) raise KickstartParseError(err) if retval.thin_volume: err = formatErrorMsg(self.lineno, msg=_("Thin volumes cannot be cached")) raise KickstartParseError(err) if not retval.cache_pvs: err = formatErrorMsg(self.lineno, msg=_("Cache needs to have a list of (fast) PVs specified")) raise KickstartParseError(err) if not retval.cache_size: err = formatErrorMsg(self.lineno, msg=_("Cache needs to have size specified")) raise KickstartParseError(err) if retval.cache_mode and retval.cache_mode not in ("writeback", "writethrough"): err = formatErrorMsg(self.lineno, msg=_("Invalid cache mode given: %s") % retval.cache_mode) raise KickstartParseError(err) if not retval.format and retval.mkfsopts: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--mkfsoptions with --noformat has no effect."))) if retval.fsprofile and retval.mkfsopts: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--mkfsoptions and --fsprofile cannot be used together."))) return retval
def parse(self, args): # call the overridden command to do it's job first retval = F21_Network.parse(self, args) # validate the network interface name error_message = validate_network_interface_name(retval.interfacename) # something is wrong with the interface name if error_message is not None: raise KickstartValueError( formatErrorMsg(self.lineno, msg=error_message)) if retval.bridgeopts: if not retval.bridgeslaves: msg = formatErrorMsg(self.lineno, msg=_("Option --bridgeopts requires "\ "--bridgeslaves to be specified")) raise KickstartValueError(msg) opts = retval.bridgeopts.split(",") for opt in opts: _key, _sep, value = opt.partition("=") if not value or "=" in value: msg = formatErrorMsg( self.lineno, msg= _("Bad format of --bridgeopts, expecting key=value options separated by ','" )) raise KickstartValueError(msg) return retval
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) > 0: raise KickstartValueError( formatErrorMsg( self.lineno, msg=_("Kickstart command %s does not take any arguments") % "upgrade")) if opts.root_device == "": raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("Kickstart command %s does not accept empty parameter %s" ) % ("upgrade", "--root-device"))) else: self.root_device = opts.root_device if self.currentCmd == "upgrade": self.upgrade = True else: self.upgrade = False return self
def _parse_fingerprint(self, value): if FINGERPRINT_REGEX.match(value) is None: msg = "Unsupported or invalid fingerprint" raise KickstartValueError(msg) if utils.get_hashing_algorithm(value) is None: msg = "Unsupported fingerprint" raise KickstartValueError(msg) self.fingerprint = value
def parse(self, args): retval = F21_LogVol.parse(self, args) if not retval.format and retval.mkfsopts: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--mkfsoptions with --noformat has no effect."))) if retval.fsprofile and retval.mkfsopts: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--mkfsoptions and --fsprofile cannot be used together."))) return retval
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) self._setToSelf(self.op, opts) if len(extra) != 0: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % "eula")) if not self.agreed: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command eula expects the --agreed option"))) return self
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) == 0: raise KickstartValueError( formatErrorMsg(self.lineno, msg=_("Mount point required for %s") % "raid")) if len(extra) == 1 and not opts.preexist: raise KickstartValueError( formatErrorMsg(self.lineno, msg=_("Partitions required for %s") % "raid")) elif len(extra) > 1 and opts.preexist: raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("Members may not be specified for preexisting RAID device" ))) rd = self.handler.RaidData() self._setToObj(self.op, opts, rd) rd.lineno = self.lineno # In older pykickstart --device was always specifying a minor, so # rd.device had to be an integer. # In newer pykickstart it has to be the array name since the minor # cannot be reliably predicted due to lack of mdadm.conf during boot. rd.device = self._getDevice(rd.device) rd.mountpoint = extra[0] if len(extra) > 1: rd.members = extra[1:] # Check for duplicates in the data list. if rd in self.dataList(): warnings.warn( _("A RAID device with the name %s has already been defined.") % rd.device) if not rd.preexist and not rd.level: raise KickstartValueError( formatErrorMsg( self.lineno, msg="RAID Partition defined without RAID level")) if rd.preexist and rd.device == "": raise KickstartValueError( formatErrorMsg( self.lineno, msg="Device required for preexisting RAID device")) return rd
def _parseArguments(self, string): if self.join_realm: raise KickstartParseError(formatErrorMsg(self.lineno, msg=_( "The realm command 'join' should only be specified once"))) args = shlex.split(string) if not args: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_( "Missing realm command arguments"))) command = args.pop(0) if command == "join": self._parseJoin(args) else: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_( "Unsupported realm '%s' command") % command))
def check_values (self, values, args): def seen(option): return option in self.option_seen def usedTooNew(option): return option.introduced and option.introduced > self.version def usedDeprecated(option): return option.deprecated def usedRemoved(option): return option.removed and option.removed <= self.version for option in [o for o in self.option_list if isinstance(o, Option)]: if option.required and not seen(option): raise KickstartValueError(formatErrorMsg(self.lineno, _("Option %s is required") % option)) elif seen(option) and usedTooNew(option): mapping = {"option": option, "intro": versionToString(option.introduced), "version": versionToString(self.version)} self.error(_("The %(option)s option was introduced in version %(intro)s, but you are using kickstart syntax version %(version)s.") % mapping) elif seen(option) and usedRemoved(option): mapping = {"option": option, "removed": versionToString(option.removed), "version": versionToString(self.version)} if option.removed == self.version: self.error(_("The %(option)s option is no longer supported.") % mapping) else: self.error(_("The %(option)s option was removed in version %(removed)s, but you are using kickstart syntax version %(version)s.") % mapping) elif seen(option) and usedDeprecated(option) and self.version >= option.deprecated: mapping = {"lineno": self.lineno, "option": option} warnings.warn(_("Ignoring deprecated option on line %(lineno)s: The %(option)s option has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this option.") % mapping, DeprecationWarning) return (values, args)
def _processGroup(self, line): op = OptionParser() op.add_option("--nodefaults", action="store_true", default=False) op.add_option("--optional", action="store_true", default=False) (opts, extra) = op.parse_args(args=line.split()) if opts.nodefaults and opts.optional: raise KickstartValueError( _("Group cannot specify both --nodefaults and --optional")) # If the group name has spaces in it, we have to put it back together # now. grp = " ".join(extra) if grp in [g.name for g in self.groupList]: return if opts.nodefaults: self.groupList.append( Group(name=grp, include=constants.GROUP_REQUIRED)) elif opts.optional: self.groupList.append(Group(name=grp, include=constants.GROUP_ALL)) else: self.groupList.append( Group(name=grp, include=constants.GROUP_DEFAULT))
def _parse_content_url(self, value): if any(value.startswith(prefix) for prefix in SUPPORTED_URL_PREFIXES): self.content_url = value else: msg = "Unsupported url '%s' in the %s addon" % (value, self.name) raise KickstartValueError(msg)
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) != 1: raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("%(command)s command requires a single argument: %(argument)s" ) % { "command": "device", "argument": "module name" })) dd = F8_DeviceData() self._setToObj(self.op, opts, dd) dd.lineno = self.lineno dd.moduleName = extra[0] # Check for duplicates in the data list. if dd in self.dataList(): warnings.warn( _("A module with the name %s has already been defined.") % dd.moduleName) return dd
def parse(self, args): (_opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) > 0: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % "mediacheck")) self.mediacheck = True return self
def parse(self, args): data = F17_BTRFS.parse(self, args) if (data.preexist or not data.format) and data.mkfsopts: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("--mkfsoptions with --noformat or --useexisting has no effect."))) return data
def parse(self, args): (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno) dd = FC6_MpPathData() self._setToObj(self.op, opts, dd) dd.lineno = self.lineno dd.mpdev = dd.mpdev.split('/')[-1] parent = None for x in range(0, len(self.mpaths)): mpath = self.mpaths[x] for path in mpath.paths: if path.device == dd.device: mapping = { "device": path.device, "multipathdev": path.mpdev } raise KickstartValueError( formatErrorMsg( self.lineno, msg= _("Device '%(device)s' is already used in multipath '%(multipathdev)s'" ) % mapping)) if mpath.name == dd.mpdev: parent = x if parent is None: mpath = FC6_MultiPathData() return mpath else: mpath = self.mpaths[parent] return dd
class F19_Realm(KickstartCommand): removedKeywords = KickstartCommand.removedKeywords removedAttrs = KickstartCommand.removedAttrs def __init__(self, writePriority=0, *args, **kwargs): KickstartCommand.__init__(self, *args, **kwargs) self.join_realm = None self.join_args = [] self.discover_options = [] def _parseArguments(self, string): if self.join_realm: raise KickstartParseError( formatErrorMsg( self.lineno, msg=_( "The realm command 'join' should only be specified once" ))) args = shlex.split(string) if not args: raise KickstartValueError( formatErrorMsg(self.lineno, msg=_("Missing realm command arguments"))) command = args.pop(0) if command == "join": self._parseJoin(args) else: raise KickstartValueError( formatErrorMsg(self.lineno, msg=_("Unsupported realm '%s' command" % command))) def _parseJoin(self, args): try: # We only support these args opts, remaining = getopt.getopt( args, "", ("client-software=", "server-software=", "membership-software=", "one-time-password="******"no-password", "computer-ou=")) except getopt.GetoptError, ex: raise KickstartValueError( formatErrorMsg(self.lineno, msg=_("Invalid realm arguments: %s") % ex)) if len(remaining) != 1: raise KickstartValueError( formatErrorMsg(self.lineno, msg=_("Specify only one realm to join"))) # Parse successful, just use this as the join command self.join_realm = remaining[0] self.join_args = args # Build a discovery command self.discover_options = [] supported_discover_options = ("--client-software", "--server-software", "--membership-software") for (o, a) in opts: if o in supported_discover_options: self.discover_options.append("%s=%s" % (o, a))
def _parse_content_type(self, value): value_low = value.lower() if value_low in SUPPORTED_CONTENT_TYPES: self.content_type = value_low else: msg = "Unsupported content type '%s' in the %s addon" % (value, self.name) raise KickstartValueError(msg)
def parse(self, args): # call the overridden command to do it's job first retval = F21_Network.parse(self, args) if retval.bridgeopts: if not retval.bridgeslaves: msg = formatErrorMsg(self.lineno, msg=_("Option --bridgeopts requires "\ "--bridgeslaves to be specified")) raise KickstartValueError(msg) opts = retval.bridgeopts.split(",") for opt in opts: _key, _sep, value = opt.partition("=") if not value or "=" in value: msg = formatErrorMsg(self.lineno, msg=_("Bad format of --bridgeopts, expecting key=value options separated by ','")) raise KickstartValueError(msg) return retval
def parse(self, args, errorCheck=True): retval = FC3_IgnoreDisk.parse(self, args) if errorCheck: if (len(self.ignoredisk) == 0 and len(self.onlyuse) == 0) or (len(self.ignoredisk) > 0 and (len(self.onlyuse) > 0)): raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --drives or --only-use must be specified for ignoredisk command."))) return retval
def parse(self, args): F9_Vnc.parse(self, args) if self.password and not 5 < len(self.password) < 9: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("VNC password must be six to eight characters long"))) return self
def parse(self, args): (namespace, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) data = self.handler.BTRFSData() self.set_to_obj(namespace, data) data.lineno = self.lineno if len(extra) == 0 and not data.snapshot: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs must be given a mountpoint")) if len(extra) == 1 and not data.subvol: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs must be given a list of partitions")) elif len(extra) == 1: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs subvol requires specification of parent volume")) if data.subvol and not data.name: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs subvolume requires a name")) if data.snapshot and not data.name: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs snapshot requires a name")) if data.snapshot and data.subvol: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs subvolume cannot be snapshot at the same time")) if data.snapshot and not data.base: raise KickstartValueError(formatErrorMsg(self.lineno, msg="btrfs snapshot requires a base")) if len(extra) > 0: data.mountpoint = extra[0] data.devices = extra[1:] # Check for duplicates in the data list. if data in self.dataList(): warnings.warn("A btrfs volume with the mountpoint '{}' has already been defined.".format(data.label)) return data
def parse(self, args): (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno) if opts.nomount and opts.romount: raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --nomount and --romount may be specified for rescue command."))) self._setToSelf(self.op, opts) self.rescue = True return self
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) != 0: mapping = {"command": "firewall", "options": extra} raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping)) self._setToSelf(self.op, opts) return self
def parse(self, args): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) self._setToSelf(self.op, opts) if len(extra) > 1: message = _("A single argument is expected for the %s command") % \ "keyboard" raise KickstartValueError(formatErrorMsg(self.lineno, msg=message)) elif len(extra) == 0 and not self.vc_keymap and not self.x_layouts: message = _("One of --xlayouts, --vckeymap options with value(s) " "or argument is expected for the keyboard command") raise KickstartValueError(formatErrorMsg(self.lineno, msg=message)) if len(extra) > 0: self._keyboard = extra[0] return self
def percent_cb(option, opt_str, value, parser): if not 0 < value < 100: raise KickstartValueError( formatErrorMsg( self.lineno, msg= "Volume group reserved space percentage must be between 1 and 99." )) parser.values.reserved_percent = value
def space_cb(option, opt_str, value, parser): if value < 0: raise KickstartValueError( formatErrorMsg( self.lineno, msg= "Volume group reserved space must be a positive integer." )) parser.values.reserved_space = value