diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2019-03-19 14:24:37 +0000 |
---|---|---|
committer | Server Team CI Bot <josh.powers+server-team-bot@canonical.com> | 2019-03-19 14:24:37 +0000 |
commit | 5e5894d68d21bf33649aca36973a0ef2fe72f01d (patch) | |
tree | 929f192b700e9b5f3454da1bb4edbdd07687c94a /cloudinit/util.py | |
parent | 6d58bd8a65e1e7723cd6019b0ceca39564c435fd (diff) | |
download | vyos-cloud-init-5e5894d68d21bf33649aca36973a0ef2fe72f01d.tar.gz vyos-cloud-init-5e5894d68d21bf33649aca36973a0ef2fe72f01d.zip |
Add ubuntu_drivers config module
The ubuntu_drivers config module enables usage of the 'ubuntu-drivers'
command. At this point it only serves as a way of installing NVIDIA
drivers for general purpose graphics processing unit (GPGPU)
functionality.
Also, a small usability improvement to get_cfg_by_path to allow it to
take a string for the key path
"toplevel/second/mykey"
in addition to the original:
("toplevel", "second", "mykey")
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index a192091f..385f231c 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -703,6 +703,21 @@ def get_cfg_option_list(yobj, key, default=None): # get a cfg entry by its path array # for f['a']['b']: get_cfg_by_path(mycfg,('a','b')) def get_cfg_by_path(yobj, keyp, default=None): + """Return the value of the item at path C{keyp} in C{yobj}. + + example: + get_cfg_by_path({'a': {'b': {'num': 4}}}, 'a/b/num') == 4 + get_cfg_by_path({'a': {'b': {'num': 4}}}, 'c/d') == None + + @param yobj: A dictionary. + @param keyp: A path inside yobj. it can be a '/' delimited string, + or an iterable. + @param default: The default to return if the path does not exist. + @return: The value of the item at keyp." + is not found.""" + + if isinstance(keyp, six.string_types): + keyp = keyp.split("/") cur = yobj for tok in keyp: if tok not in cur: |