Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/driver policy #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

sohorx
Copy link
Contributor

@sohorx sohorx commented Apr 8, 2022

Hi,

In my understanding, currently to specify the same policy for a given driver we have to write it within the iface_default key for each interface name that bear this driver.

This pull request creates a new driver_default key that can duplicate a policy for each interface bearing the same driver name.

@julienfortin
Copy link
Contributor

@sohorx can you provide an example of how this would be used?

btw pretty cool use of suppress I didn't know about that before :)

@sohorx
Copy link
Contributor Author

sohorx commented May 2, 2022

sure ! :)

This is my use case:

{
  "dhcp": {
    "driver_defaults": {
      "qmi_wwan": {
        "dhcp-client": "udhcpc",
        "dhcp-wait": "no"
      }
    }
  }
}

I did some changes to make the module dhcp to handle multi-clients dhcp (which I'll make PR later on) and use this driver_defaults policy to set my client to be udhcpc for any 4g interfaces that use the qmi driver.

@sohorx
Copy link
Contributor Author

sohorx commented May 2, 2022

btw, At first I wanted to make something like this:

        if (not ifname or not attr or not module_name):
            return None

        def dig(what, *args):
            return reduce(lambda d, k: d[k], args, what)

        driname = self._get_driver_name(ifname)
        policies = [
            [module_name, 'iface_defaults', ifname, attr],
            [module_name, 'driver_defaults', driname, attr],
            [module_name, 'defaults', attr],
        ]
        for args in policies:
            with suppress(TypeError, KeyError, IndexError):
                return dig(self.user_policy_array, *args)

        for args in policies:
            with suppress(TypeError, KeyError, IndexError):
                return dig(self.system_policy_array, *args)

        # could not find any system or user default so return Non
        return None

But that is maybe too much changes ;-)

This new methods works like the get_attr_default to takes defaults
values from the driver name only.
This update is meant to check if there is a driver default policy
in between ifname and default policies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants