From 7dbe2461622511c6721fad9ad63103b5bcdda9f9 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Tue, 11 Jul 2017 16:01:41 -0400 Subject: [PATCH] ceph-volume: configuration: allow splitting by other chars for getting a list Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/configuration.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ceph-volume/ceph_volume/configuration.py b/src/ceph-volume/ceph_volume/configuration.py index 69e893a8c0b38..bd2cf4eb2f947 100644 --- a/src/ceph-volume/ceph_volume/configuration.py +++ b/src/ceph-volume/ceph_volume/configuration.py @@ -61,22 +61,27 @@ class Conf(configparser.SafeConfigParser): except (configparser.NoSectionError, configparser.NoOptionError): return default - def get_list(self, section, key): + def get_list(self, section, key, default=None, split=','): """ Assumes that the value for a given key is going to be a list separated by commas. It gets rid of trailing comments. If just one item is present it returns a list with a single item, if no key is found an empty list is returned. + + Optionally split on other characters besides ',' and return a fallback + value if no items are found. """ value = self.get_safe(section, key, []) if value == []: + if default is not None: + return default return value # strip comments value = re.split(r'\s+#', value)[0] # split on commas - value = value.split(',') + value = value.split(split) # strip spaces return [x.strip() for x in value] -- 2.39.5