204
203
return [path_to_kname(device)]
207
def _shlex_split(str_in):
208
# shlex.split takes a string
209
# but in python2 if input here is a unicode, encode it to a string.
210
# http://stackoverflow.com/questions/2365411/
211
# python-convert-unicode-to-ascii-without-errors
212
if sys.version_info.major == 2:
214
if isinstance(str_in, unicode):
215
str_in = str_in.encode('utf-8')
219
return shlex.split(str_in)
221
return shlex.split(str_in)
224
206
def _lsblock_pairs_to_dict(lines):
226
208
parse lsblock output and convert to dict
229
211
for line in lines.splitlines():
230
toks = _shlex_split(line)
212
toks = util.shlex_split(line)
233
215
k, v = tok.split("=", 1)
468
450
for line in out.splitlines():
469
451
curdev, curdata = line.split(":", 1)
470
452
data[curdev] = dict(tok.split('=', 1)
471
for tok in _shlex_split(curdata))
453
for tok in util.shlex_split(curdata))
979
961
raise ValueError("wipe mode %s not supported" % mode)
964
def storage_config_required_packages(storage_config, mapping):
965
"""Read storage configuration dictionary and determine
966
which packages are required for the supplied configuration
967
to function. Return a list of packaged to install.
970
if not storage_config or not isinstance(storage_config, dict):
971
raise ValueError('Invalid storage configuration. '
972
'Must be a dict:\n %s' % storage_config)
974
if not mapping or not isinstance(mapping, dict):
975
raise ValueError('Invalid storage mapping. Must be a dict')
977
if 'storage' in storage_config:
978
storage_config = storage_config.get('storage')
982
# get reqs by device operation type
983
dev_configs = set(operation['type']
984
for operation in storage_config['config'])
986
for dev_type in dev_configs:
987
if dev_type in mapping:
988
needed_packages.extend(mapping[dev_type])
990
# for any format operations, check the fstype and
991
# determine if we need any mkfs tools as well.
992
format_configs = set([operation['fstype']
993
for operation in storage_config['config']
994
if operation['type'] == 'format'])
995
for format_type in format_configs:
996
if format_type in mapping:
997
needed_packages.extend(mapping[format_type])
999
return needed_packages
1002
def detect_required_packages_mapping():
1003
"""Return a dictionary providing a versioned configuration which maps
1004
storage configuration elements to the packages which are required
1007
The mapping key is either a config type value, or an fstype value.
1013
'handler': storage_config_required_packages,
1015
'bcache': ['bcache-tools'],
1016
'btrfs': ['btrfs-tools'],
1017
'ext2': ['e2fsprogs'],
1018
'ext3': ['e2fsprogs'],
1019
'ext4': ['e2fsprogs'],
1020
'lvm_partition': ['lvm2'],
1021
'lvm_volgroup': ['lvm2'],
981
1030
# vi: ts=4 expandtab syntax=python