diff options
author | Vlastimil Holer <vlastimil.holer@gmail.com> | 2013-02-19 16:30:06 +0100 |
---|---|---|
committer | Vlastimil Holer <vlastimil.holer@gmail.com> | 2013-02-19 16:30:06 +0100 |
commit | 6b0652745129808dc0669354cb3e0dc53962d6ea (patch) | |
tree | 6ec307c7c245cf68d28ef05e3f1a9f7d075ff8bc /cloudinit/util.py | |
parent | e18f0f8a382729cc7c9f8df3ad0573af7eeb8f47 (diff) | |
parent | 174bc39e6b2c1cac3f73f67f25fad87cab16fa42 (diff) | |
download | vyos-cloud-init-6b0652745129808dc0669354cb3e0dc53962d6ea.tar.gz vyos-cloud-init-6b0652745129808dc0669354cb3e0dc53962d6ea.zip |
Merged trunk lp:cloud-init
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index e334559c..7b1202a2 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,37 @@ def keyval_str_to_dict(kvstring): val = True ret[key] = val return ret + + +def is_partition(device): + if device.startswith("/dev/"): + 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 |