def _check_boot_drive(self, storage, boot_drive, usable_disks): """Check the specified boot drive.""" # Resolve the disk identifier. matched_disks = device_matches(boot_drive, devicetree=storage.devicetree, disks_only=True) if not matched_disks: raise KickstartParseError(_("No match found for given boot drive " "\"{}\".").format(boot_drive)) if len(matched_disks) > 1: raise KickstartParseError(_("More than one match found for given boot drive " "\"{}\".").format(boot_drive)) if matched_disks[0] not in usable_disks: raise KickstartParseError(_("Requested boot drive \"{}\" doesn't exist or cannot " "be used.").format(boot_drive))
def handle_line(self, line): """ The handle_line method that is called with every line from this addon's %addon section of the kickstart file. :param line: a single line from the %addon section :type line: str """ actions = { "content-type": self._parse_content_type, "content-url": self._parse_content_url, "datastream-id": self._parse_datastream_id, "profile": self._parse_profile_id, "xccdf-id": self._parse_xccdf_id, "xccdf-path": self._parse_xccdf_path, "cpe-path": self._parse_cpe_path, "tailoring-path": self._parse_tailoring_path, "fingerprint": self._parse_fingerprint, "certificates": self._parse_certificates, } line = line.strip() (pre, sep, post) = line.partition("=") pre = pre.strip() post = post.strip() post = post.strip('"') try: actions[pre](post) except KeyError: msg = "Unknown item '%s' for %s addon" % (line, self.name) raise KickstartParseError(msg)
def parse(self, args): retval = F15_Bootloader.parse(self, args) if "," in retval.bootDrive: # pylint: disable=no-member raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("--boot-drive accepts only one argument"))) return retval
def _parseArguments(self, string): if self.join_realm: raise KickstartParseError( _("The realm command 'join' should only be specified once"), lineno=self.lineno) args = shlex.split(string) if not args: raise KickstartParseError(_("Missing realm command arguments"), lineno=self.lineno) command = args.pop(0) if command == "join": self._parseJoin(args) else: raise KickstartParseError(_("Unsupported realm '%s' command") % command, lineno=self.lineno)
def _when_cb(self, value): if value.lower() in self.whenMap: return self.whenMap[value.lower()] else: msg = _("Invalid snapshot when parameter: %s") % value raise KickstartParseError(formatErrorMsg(self.lineno, msg=msg), lineno=self.lineno)
def handle_line(self, line, line_number=None): """Handle one line of the section. :param line: a line to parse :param line_number: a line number :raise: KickstartParseError for invalid lines """ actions = { "content-type": self._parse_content_type, "content-url": self._parse_content_url, "content-path": self._parse_content_path, "datastream-id": self._parse_datastream_id, "profile": self._parse_profile_id, "xccdf-id": self._parse_xccdf_id, "xccdf-path": self._parse_content_path, "cpe-path": self._parse_cpe_path, "tailoring-path": self._parse_tailoring_path, "fingerprint": self._parse_fingerprint, "certificates": self._parse_certificates, "remediate": self._parse_remediate, } line = line.strip() (pre, sep, post) = line.partition("=") pre = pre.strip() post = post.strip() post = post.strip('"') try: actions[pre](post) except KeyError: msg = "Unknown item '%s' for %s addon" % (line, self.name) raise KickstartParseError(msg)
def parse(self, args): (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) assert len(ns.mntpoint) == 1 if extra: mapping = {"command": "partition", "options": extra} raise KickstartParseError(formatErrorMsg( self.lineno, msg=_( "Unexpected arguments to %(command)s command: %(options)s") % mapping), lineno=self.lineno) pd = self.dataClass() # pylint: disable=not-callable self.set_to_obj(ns, pd) pd.lineno = self.lineno pd.mountpoint = ns.mntpoint[0] # Check for duplicates in the data list. if pd.mountpoint != "swap" and pd in self.dataList(): warnings.warn( _("A partition with the mountpoint %s has already been defined." ) % pd.mountpoint) return pd
def parse(self, args): (_ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) if len(_ns.kbd) != 1: raise KickstartParseError( _("Kickstart command %s requires one argument") % "keyboard", lineno=self.lineno) elif extra: mapping = {"command": "keyboard", "options": extra} raise KickstartParseError( _("Unexpected arguments to %(command)s command: %(options)s") % mapping, lineno=self.lineno) self.keyboard = _ns.kbd[0] return self
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 = _("Option --bridgeopts requires --bridgeslaves to be specified") raise KickstartParseError(msg, lineno=self.lineno) opts = retval.bridgeopts.split(",") for opt in opts: _key, _sep, value = opt.partition("=") if not value or "=" in value: msg = _("Bad format of --bridgeopts, expecting key=value options separated by ','") raise KickstartParseError(msg, lineno=self.lineno) return retval
def _type_cb(self, value): if value.lower() in self.typeMap: return self.typeMap[value.lower()] else: raise KickstartParseError( formatErrorMsg(self.lineno, msg=_("Invalid autopart type: %s") % value))
def parse(self, args): """Parse the command. Do any glob expansion now, since we need to have the real list of disks available before the execute methods run. """ retval = super().parse(args) # Set the default type. if self.type is None: self.type = CLEARPART_TYPE_NONE # Check the disk label. if self.disklabel and self.disklabel not in DiskLabel.get_platform_label_types(): raise KickstartParseError(_("Disklabel \"{}\" given in clearpart command is not " "supported on this platform.").format(self.disklabel), lineno=self.lineno) # Get the disks names to clear. self.drives = get_device_names(self.drives, disks_only=True, lineno=self.lineno, msg=_("Disk \"{}\" given in clearpart command does " "not exist.")) # Get the devices names to clear. self.devices = get_device_names(self.devices, disks_only=False, lineno=self.lineno, msg=_("Device \"{}\" given in clearpart device list " "does not exist.")) return retval
def parse(self, args): # first call the overriden method retval = F19_Raid.parse(self, args) # the raid command can't be used together with the autopart command # due to the hard to debug behavior their combination introduces if self.handler.autopart.seen: errorMsg = _( "The raid and autopart commands can't be used at the same time" ) raise KickstartParseError(errorMsg, lineno=self.lineno) # the same applies to the 'mount' command if hasattr(self.handler, "mount") and self.handler.mount.seen: errorMsg = _( "The raid and mount commands can't be used at the same time") raise KickstartParseError(errorMsg, lineno=self.lineno) return retval
def _processGroup(self, line): op = KSOptionParser(prog="", description="", version=version.DEVEL) op.add_argument("--nodefaults", action="store_true", default=False, help="", version=version.DEVEL) op.add_argument("--optional", action="store_true", default=False, help="", version=version.DEVEL) (ns, extra) = op.parse_known_args(args=line.split()) if ns.nodefaults and ns.optional: raise KickstartParseError( _("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 ns.nodefaults: self.groupList.append( Group(name=grp, include=constants.GROUP_REQUIRED)) elif ns.optional: self.groupList.append(Group(name=grp, include=constants.GROUP_ALL)) else: self.groupList.append( Group(name=grp, include=constants.GROUP_DEFAULT))
def dispatcher(self, args, lineno): """Call the appropriate KickstartCommand handler for the current line in the kickstart file. A handler for the current command should be registered, though a handler of None is not an error. Returns the data object returned by KickstartCommand.parse. args -- A list of arguments to the current command lineno -- The line number in the file, for error reporting """ cmd = args[0] if cmd not in self.commands: raise KickstartParseError( formatErrorMsg(lineno, msg=_("Unknown command: %s") % cmd)) elif self.commands[cmd] != None: self.commands[cmd].currentCmd = cmd self.commands[cmd].currentLine = self.currentLine self.commands[cmd].lineno = lineno self.commands[cmd].seen = True # The parser returns the data object that was modified. This could # be a BaseData subclass that should be put into a list, or it # could be the command handler object itself. obj = self.commands[cmd].parse(args[1:]) lst = self.commands[cmd].dataList() if lst is not None: lst.append(obj) return obj
def parse(self, args): # call the overriden command to do it's job first retval = F18_AutoPart.parse(self, args) # Using autopart together with other partitioning command such as # part/partition, raid, logvol or volgroup can lead to hard to debug # behavior that might among other result into an unbootable system. # # Therefore if any of those commands is detected in the same kickstart # together with autopart, an error is raised and installation is # aborted. conflicting_command = "" # seen indicates that the corresponding # command has been seen in kickstart if self.handler.partition.seen: conflicting_command = "part/partition" elif self.handler.raid.seen: conflicting_command = "raid" elif self.handler.volgroup.seen: conflicting_command = "volgroup" elif self.handler.logvol.seen: conflicting_command = "logvol" elif hasattr(self.handler, "reqpart") and self.handler.reqpart.seen: conflicting_command = "reqpart" if conflicting_command: # allow for translation of the error message errorMsg = _("The %s and autopart commands can't be used at the same time") % \ conflicting_command raise KickstartParseError(formatErrorMsg(self.lineno, msg=errorMsg)) return retval
def parse(self, args): ns = self.op.parse_args(args=args, lineno=self.lineno) dd = FC6_MpPathData() self.set_to_obj(ns, dd) dd.lineno = self.lineno dd.mpdev = dd.name.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 KickstartParseError(_( "Device '%(device)s' is already used in multipath '%(multipathdev)s'" ) % mapping, lineno=self.lineno) if mpath.name == dd.mpdev: parent = x if not parent: mpath = self.dataClass(name=dd.name) # pylint: disable=not-callable mpath.paths.append(dd) return mpath else: mpath = self.mpaths[parent] mpath.paths.append(dd) return dd
def parse(self, args): (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) if extra: mapping = {"command": "logvol", "options": extra} raise KickstartParseError( _("Unexpected arguments to %(command)s command: %(options)s") % mapping, lineno=self.lineno) lvd = self.dataClass() # pylint: disable=not-callable self.set_to_obj(ns, lvd) lvd.lineno = self.lineno lvd.mountpoint = ns.mntpoint[0] if not lvd.format: lvd.preexist = True # Check for duplicates in the data list. if lvd in self.dataList(): warnings.warn( _("A logical volume with the name %(logical_volume_name)s has already been defined in volume group %(volume_group)s." ) % { "logical_volume_name": lvd.name, "volume_group": lvd.vgname }, KickstartParseWarning) return lvd
def parse(self, args): (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) self.set_to_self(ns) if extra: raise KickstartParseError( _("Kickstart command %s does not take any arguments") % "eula", lineno=self.lineno) if not self.agreed: raise KickstartParseError( _("Kickstart command eula expects the --agreed option"), lineno=self.lineno) return self
def dispatcher(self, args, lineno): """Call the appropriate KickstartCommand handler for the current line in the kickstart file. A handler for the current command should be registered, though a handler of None is not an error. Returns the data object returned by KickstartCommand.parse. args -- A list of arguments to the current command lineno -- The line number in the file, for error reporting """ cmd = args[0] if cmd not in self.commands: raise KickstartParseError( formatErrorMsg(lineno, msg=_("Unknown command: %s") % cmd)) elif self.commands[cmd] != None: self.commands[cmd].currentCmd = cmd self.commands[cmd].currentLine = self.currentLine self.commands[cmd].lineno = lineno self.commands[cmd].seen = True # The parser returns the data object that was modified. This is either # the command handler object itself (a KickstartCommand object), or it's # a BaseData subclass instance that should be put into the command's # dataList. The latter is done via side effects. # # Regardless, return the object that was given to us by the parser. obj = self.commands[cmd].parse(args[1:]) # Here's the side effect part - don't worry about lst not being returned. lst = self.commands[cmd].dataList() if isinstance(obj, BaseData) and lst is not None: lst.append(obj) return obj
def parse(self, args): tg = super().parse(args) if tg.iface: if not wait_for_network_devices([tg.iface]): raise KickstartParseError( lineno=self.lineno, msg= _("Network interface \"%(nic)s\" required by iSCSI \"%(iscsiTarget)s\" target is not up." ) % { "nic": tg.iface, "iscsiTarget": tg.target }) mode = iscsi.mode if mode == "none": if tg.iface: network_proxy = NETWORK.get_proxy() activated_ifaces = network_proxy.GetActivatedInterfaces() iscsi.create_interfaces(activated_ifaces) elif ((mode == "bind" and not tg.iface) or (mode == "default" and tg.iface)): raise KickstartParseError( lineno=self.lineno, msg= _("iscsi --iface must be specified (binding used) either for all targets or for none" )) try: if tg.target: log.info("adding iscsi target %s at %s:%d via %s", tg.target, tg.ipaddr, tg.port, tg.iface) else: log.info("adding all iscsi targets discovered at %s:%d via %s", tg.ipaddr, tg.port, tg.iface) iscsi.add_target(tg.ipaddr, tg.port, tg.user, tg.password, tg.user_in, tg.password_in, target=tg.target, iface=tg.iface) except (IOError, ValueError) as e: raise KickstartParseError(lineno=self.lineno, msg=str(e)) return tg
def _setup_mount_point(self, storage, mount_data): """Set up a mount point. :param storage: an instance of the Blivet's storage object :param mount_data: an instance of MountPointRequest """ device_spec = mount_data.device_spec reformat = mount_data.reformat format_type = mount_data.format_type device = storage.devicetree.resolve_device(device_spec) if device is None: raise KickstartParseError( _("Unknown or invalid device '%s' specified") % device_spec) if reformat: if format_type: fmt = get_format(format_type) if not fmt: raise KickstartParseError( _("Unknown or invalid format '%(format)s' specified for device " "'%(device)s'") % { "format": format_type, "device": device_spec }) else: old_fmt = device.format if not old_fmt or old_fmt.type is None: raise KickstartParseError( _("No format on device '%s'") % device_spec) fmt = get_format(old_fmt.type) storage.format_device(device, fmt) # make sure swaps end up in /etc/fstab if fmt.type == "swap": storage.add_fstab_swap(device) # only set mount points for mountable formats mount_point = mount_data.mount_point if device.format.mountable and mount_point and mount_point != "none": device.format.mountpoint = mount_point device.format.create_options = mount_data.format_options device.format.options = mount_data.mount_options
def handle_header(self, lineno, args): op = KSOptionParser() op.add_option("--enable", action="store_true", default=True, dest="enabled", help="Enable kdump") op.add_option("--enablefadump", action="store_true", default=False, dest="enablefadump", help="Enable dump mode fadump") op.add_option("--disable", action="store_false", dest="enabled", help="Disable kdump") op.add_option("--reserve-mb", type="string", dest="reserveMB", default="128", help="Amount of memory in MB to reserve for kdump.") (opts, extra) = op.parse_args(args=args, lineno=lineno) # Reject any additional arguments if extra: AddonData.handle_header(self, lineno, extra) # Validate the reserve-mb argument # Allow a final 'M' for consistency with the crashkernel kernel # parameter. Strip it if found. if opts.reserveMB and opts.reserveMB[-1] == 'M': opts.reserveMB = opts.reserveMB[:-1] try: _test = int(opts.reserveMB) except ValueError: msg = _("Invalid value %s for --reserve-mb") % opts.reserveMB if lineno != None: raise KickstartParseError(formatErrorMsg(lineno, msg=msg)) else: raise KickstartParseError(msg) # Store the parsed arguments self.enabled = opts.enabled self.reserveMB = opts.reserveMB self.enablefadump = opts.enablefadump
def parse(self, args): (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) # because positional arguments with variable number of values # don't parse very well if not ns.partitions: if extra: ns.partitions = extra extra = [] elif len(ns.name) > 1: ns.partitions = ns.name[1:] ns.name = [ns.name[0]] if not ns.format: ns.preexist = True vg = self.dataClass() # pylint: disable=not-callable self.set_to_obj(ns, vg) vg.lineno = self.lineno if not ns.name: raise KickstartParseError(formatErrorMsg( self.lineno, msg=_("volgroup must be given a VG name")), lineno=self.lineno) if not any([ns.partitions, ns.preexist]): raise KickstartParseError(formatErrorMsg( self.lineno, msg=_("volgroup must be given a list of partitions")), lineno=self.lineno) elif ns.partitions and ns.preexist: raise KickstartParseError(formatErrorMsg( self.lineno, msg=_( "Members may not be specified for preexisting volgroup")), lineno=self.lineno) vg.vgname = ns.name[0] if ns.partitions: vg.physvols = ns.partitions # Check for duplicates in the data list. if vg in self.dataList(): warnings.warn( _("A volgroup with the name %s has already been defined.") % vg.vgname) return vg
def parse(self, args): (opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno) self._setToSelf(self.op, opts) if len(self.disabled) == 0 and len(self.enabled) == 0: raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("One of --disabled or --enabled must be provided."))) return self
def parse(self, args): FC6_Timezone.parse(self, args) if self.ntpservers and self.nontp: msg = _("Options --nontp and --ntpservers are mutually exclusive") raise KickstartParseError(msg, lineno=self.lineno) return self
def parse(self, args): retval = F20_Raid.parse(self, args) if not retval.format and retval.mkfsopts: raise KickstartParseError(formatErrorMsg( self.lineno, msg=_("--mkfsoptions with --noformat has no effect.")), lineno=self.lineno) if retval.fsprofile and retval.mkfsopts: raise KickstartParseError(formatErrorMsg( self.lineno, msg=_( "--mkfsoptions and --fsprofile cannot be used together.")), lineno=self.lineno) return retval
def parse(self, args): (ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno) if len(extra) != 1: raise KickstartParseError( _("Kickstart command %s requires one argument") % "mouse", lineno=self.lineno) elif any(arg for arg in extra if arg.startswith("-")): mapping = {"command": "mouse", "options": extra} raise KickstartParseError( _("Unexpected arguments to %(command)s command: %(options)s") % mapping, lineno=self.lineno) self.set_to_self(ns) self.mouse = extra[0] return self
def parse(self, args): # call the overriden command to do its job first retval = F20_AutoPart.parse(self, args) # btrfs is not a valid filesystem type if self.fstype == "btrfs": raise KickstartParseError(_( "autopart --fstype=btrfs is not valid fstype, use --type=btrfs instead" ), lineno=self.lineno) if self._typeAsStr() == "btrfs" and self.fstype: raise KickstartParseError( _("autopart --fstype cannot be used with --type=btrfs"), lineno=self.lineno) return retval
def parse(self, args): (_opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) if len(extra) > 0: raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % self.currentCmd)) self.unsupported_hardware = True return self
def parse(self, args): if args: msg = _("Kickstart command %s does not take any arguments" ) % self.currentCmd raise KickstartParseError(formatErrorMsg(self.lineno, msg=msg), lineno=self.lineno) return self