Re: [PATCH 2/8] Modify dracutSetupData() methods to return lists of dicts.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/10/2009 12:27 AM, David Cantrell wrote:
> Update all of the dracutSetupData() methods to return lists of dicts
> containing kernel parameter information.  The KernelArguments.get()
> method in booty will iterate over the list and create the kernel
> parameter string based on the dict entries.

This I really like. It's generic and extending with additional
parameters in the future will be possible without much code change if any.

> Structure of the data returned from dracutSetupData():
> 
>     [{'option': STRING, 'value': STRING},
>      {'option': STRING, 'value': STRING},
>      ...]

Up to here, I was assuming one would only need one dict having option
names as keys and each key had a value string:

{STRING: STRING, STRING: STRING, ...}
e.g.
{'use_diag': '0', 'readonly': '0', 'erplog': '0', 'failfast': '0'}

> The dicts in the list must at least provide an 'option' key.  Value can
> be None, in which case just the 'option' part is added to the kernel
> args list.  If option and value both exist, you'll get option=value
> written to the kernel arg list.
> 
> In the future, the dicts may contain a 'combine' boolean and a
> 'delimiter' string.  Explanation is in the docstrings for
> dracutSetupData in storage/devices.py.

I don't like the mix of sysfs attributes and anaconda internal "flags"
in the same dict. That makes the sysfs attributes look verbose since you
need the 'option' and 'value' keys to separate parameters from the
flags. Maybe I'm just thinking too much C like, but I would have
expected something like this:

struct dracut_setup_data_element {
  struct map parameters;
  char *(*filter)(char *input); /* signature just placeholder */
  char *delimiter;
  char combine:1;
};

However, with what I wrote in the reply to the patch intro mail, we
might not even need filter, delimiter, and combine.

> ---
>  booty/bootloaderInfo.py |   37 +++++++++++++++++++++++++++++--------
>  language.py             |    4 ++--
>  network.py              |   16 ++++++++--------
>  storage/devices.py      |   38 ++++++++++++++++++++++++++++++++------
>  4 files changed, 71 insertions(+), 24 deletions(-)
> 
> diff --git a/booty/bootloaderInfo.py b/booty/bootloaderInfo.py
> index 3c3fd7e..0f5d9b8 100644
> --- a/booty/bootloaderInfo.py
> +++ b/booty/bootloaderInfo.py
> @@ -89,18 +89,39 @@ class KernelArguments:
>      def get(self):
>          args = self.args
>          root = self.id.storage.rootDevice
> +        params = []
> +        newargs = []
> +
>          for d in self.id.storage.devices:
>              if root.dependsOn(d):
> -                dracutSetupData = d.dracutSetupData()
> -                if len(dracutSetupData):
> -                    args += " %s" % dracutSetupData
> +                params += d.dracutSetupData()
> +
>                  import storage
>                  if isinstance(d, storage.devices.NetworkStorageDevice):
> -                    args += " "
> -                    args += self.id.network.dracutSetupData(d)
> +                    params += self.id.network.dracutSetupData(d)
> +
> +        params += self.id.instLanguage.dracutSetupData()
> +
> +        # XXX: need to patch s-c-keyboard
> +        #params += self.id.keyboard.dracutSetupData()
> +        if args:
> +            args.append(self.id.keyboard.dracutSetupString())
> +        else:
> +            args = self.id.keyboard.dracutSetupString()
> 
> -        args += self.id.instLanguage.dracutSetupData()
> -        args += self.id.keyboard.dracutSetupData()
> +        for param in params:
> +            if not param.has_key('option') or not param.has_key('value'):
> +                continue
> +
> +            if not param['value']:
> +                newargs.append(param['option'])
> +            else:
> +                newargs.append("%s=%s" % (param['option'], param['value'],))
> +
> +        if args:
> +            args += " " + " ".join(newargs)
> +        else:
> +            args = " ".join(newargs)
> 
>          if args and self.appendArgs:
>              args += " "
> diff --git a/language.py b/language.py
> index cfcc92e..b96ae37 100644
> --- a/language.py
> +++ b/language.py
> @@ -200,11 +200,11 @@ class Language(object):
>          return self.nativeLangNames.keys()
> 
>      def dracutSetupData(self):
> -        args=""
> +        args = []
> 
>          for (key, val) in self.info.iteritems():
>              if val != None:
> -                args += " %s=%s" % (key, val)
> +                args.append({'option': key, 'value': val})
> 
>          return args
> 
> diff --git a/network.py b/network.py
> index c51d3af..2a91a4f 100644
> --- a/network.py
> +++ b/network.py
> @@ -794,7 +794,7 @@ class Network:
> 
>      # get a kernel cmdline string for dracut needed for access to host host
>      def dracutSetupData(self, networkStorageDevice):
> -        netargs=""
> +        netargs = []
> 
>          if networkStorageDevice.nic:
>              # Storage bound to a specific nic (ie FCoE)
> @@ -823,7 +823,7 @@ class Network:
> 
>          if networkStorageDevice.host_address:
>              if dev.get('bootproto').lower() == 'dhcp':
> -                netargs += "ip=%s:dhcp" % nic
> +                netargs.append({'option': 'ip', 'value': "%s:dhcp" % (nic,)})
>              else:
>                  if dev.get('GATEWAY'):
>                      gateway = dev.get('GATEWAY')
> @@ -835,14 +835,14 @@ class Network:
>                  else:
>                      hostname = ""
> 
> -                netargs += "ip=%s::%s:%s:%s:%s:none" % (dev.get('ipaddr'),
> -                           gateway, dev.get('netmask'), hostname, nic)
> +                val = "%s::%s:%s:%s:%s:none" % (dev.get('ipaddr'), gateway,
> +                                                dev.get('netmask'), hostname,
> +                                                nic,)
> +                netargs.append({'option': 'ip', 'value': val})
> 
>          hwaddr = dev.get("HWADDR")
>          if hwaddr:
> -            if netargs != "":
> -                netargs += " "
> -
> -            netargs += "ifname=%s:%s" % (nic, hwaddr.lower())
> +            val = "%s:%s" % (nic, hwaddr.lower(),)
> +            netargs.append({'option': 'ifname', 'value': val})
> 
>          return netargs
> diff --git a/storage/devices.py b/storage/devices.py
> index 4d11932..c20d3f6 100644
> --- a/storage/devices.py
> +++ b/storage/devices.py
> @@ -326,7 +326,26 @@ class Device(object):
>          return False
> 
>      def dracutSetupData(self):
> -        return ""
> +        """ Return a list of dicts containing kernel parameters for dracut.
> +            Valid dict keys:
> +
> +                option      Name of the kernel parameter (e.g., "acpi")
> +                value       Data for the kernel parameter (e.g., "off")
> +                combine     If True, all parameters with the same option
> +                            will have their value entries joined in to a
> +                            string separated by delimimeter.
> +                delimiter   Only used if combine is True (e.g., ",")
> +                filter      Optional callback function used when combine
> +                            is True.  The callback function takes a list
> +                            of all values for this option, performs a
> +                            filtering operation, then returns a list of
> +                            values.
> +
> +            The option and value keys are required.  They will be written
> +            out to dracut as option=value.  The combine boolean will allow
> +            you to reduce identical options to a single value.
> +        """
> +        return []
> 
>      @property
>      def status(self):
> @@ -3003,9 +3022,11 @@ class iScsiDiskDevice(DiskDevice, NetworkStorageDevice):
> 
>      def dracutSetupData(self):
>          if self.ibft:
> -            return "iscsi_firmware"
> +            return [{'option': 'iscsi_firmware', 'value': None}]
> 
> -        netroot="netroot=iscsi:"
> +        args = []
> +        entry = {'option': 'netroot'}
> +        netroot = "iscsi:"
>          auth = self.node.getAuth()
>          if auth:
>              netroot += "%s:%s" % (auth.username, auth.password)
> @@ -3016,9 +3037,13 @@ class iScsiDiskDevice(DiskDevice, NetworkStorageDevice):
>          netroot += "@%s::%d::%s" % (self.node.address, self.node.port,
>                                      self.node.name)
> 
> -        netroot += " iscsi_initiator=%s" % self.initiator
> +        entry['value'] = netroot
> +        args.append(entry)
> +
> +        args.append({'option': 'iscsi_initiator',
> +                     'value': "%s" % (self.initiator,)})
> 
> -        return netroot
> +        return args
> 
>  class FcoeDiskDevice(DiskDevice, NetworkStorageDevice):
>      """ An FCoE disk. """
> @@ -3033,7 +3058,8 @@ class FcoeDiskDevice(DiskDevice, NetworkStorageDevice):
>          log.debug("created new fcoe disk %s @ %s" % (device, self.nic))
> 
>      def dracutSetupData(self):
> -        return "netroot=fcoe:%s:nodcb" % self.nic
> +        return [{'option': 'netroot',
> +                 'value': "fcoe:%s:nodcb" % (self.nic,)}]
> 
> 
>  class OpticalDevice(StorageDevice):

Steffen

Linux on System z Development

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Erich Baier
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux