diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-01-30 21:39:49 -0800 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2013-01-30 21:39:49 -0800 |
commit | 9df0a78e527875d1bee2be02e477176c35a971b8 (patch) | |
tree | c1f99d1e5772b90165f7abbdf5a8277c5f15b83d /cloudinit/util.py | |
parent | 7537cec4b6fdd27f9ad667f8b4682719b8da493c (diff) | |
parent | 9ced60371239eb961e9919f13bda8b496e077411 (diff) | |
download | vyos-cloud-init-9df0a78e527875d1bee2be02e477176c35a971b8.tar.gz vyos-cloud-init-9df0a78e527875d1bee2be02e477176c35a971b8.zip |
Adding package versioning logic to package installation.
This change adds the ability to provide specific package versions to
Distro.install_packages and subsequently Distro.package_command. In order
to effectively use Distro.install_packages, one is now able to pass a
variety of formats in order to easily manage package requirements.
These are examples of what can be passed:
- "package"
- ["package1","package2"]
- ("package",)
- ("package", "version")
- [("package1",)("package2",)]
- [("package1", "version1"),("package2","version2")]
This change also adds the option to install a specific version for the
puppet configuration module. This is especially important here as
successful puppet deployments are highly reliant on specific puppet
versions.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index c0ea8d91..ffe844b2 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -402,10 +402,9 @@ def get_cfg_option_list(yobj, key, default=None): return [] val = yobj[key] if isinstance(val, (list)): - # Should we ensure they are all strings?? - cval = [str(v) for v in val] + cval = [v for v in val] return cval - if not isinstance(val, (str, basestring)): + if not isinstance(val, (basestring)): val = str(val) return [val] @@ -1560,3 +1559,30 @@ def is_partition(device): device = device[5:] return os.path.isfile("/sys/class/block/%s/partition" % device) + + +def expand_package_list(version_fmt, pkgs): + # we will accept tuples, lists of tuples, or just plain lists + if not isinstance(pkgs, list): + pkgs = [pkgs] + + pkglist = [] + for pkg in pkgs: + if isinstance(pkg, basestring): + pkglist.append(pkg) + continue + + if isinstance(pkg, (tuple, list)): + if len(pkg) < 1 or len(pkg) > 2: + raise RuntimeError("Invalid package & version tuple.") + + if len(pkg) == 2 and pkg[1]: + pkglist.append(version_fmt % tuple(pkg)) + continue + + pkglist.append(pkg[0]) + + else: + raise RuntimeError("Invalid package type.") + + return pkglist |