List products consistently across all SLES systems

This commit is contained in:
Bo Maryniuk 2015-11-27 14:06:20 +01:00
parent b225263279
commit 302b5d3bc1

View file

@ -1191,36 +1191,32 @@ def _parse_suse_product(path, *info):
return product
def list_products():
def list_products(all=False):
'''
List all installed SUSE products.
List all available or installed SUSE products.
all
List all products available or only installed. Default is False.
CLI Examples:
.. code-block:: bash
salt '*' pkg.list_products
salt '*' pkg.list_products all=True
'''
products_dir = '/etc/products.d'
if not os.path.exists(products_dir):
raise CommandExecutionError('Directory {0} does not exists.'.format(products_dir))
p_data = {}
for fname in os.listdir(products_dir):
pth_name = os.path.join(products_dir, fname)
r_pth_name = os.path.realpath(pth_name)
p_data[r_pth_name] = r_pth_name != pth_name and 'baseproduct' or None
info = ['vendor', 'name', 'version', 'baseversion', 'patchlevel',
'predecessor', 'release', 'endoflife', 'arch', 'cpeid',
'productline', 'updaterepokey', 'summary', 'shortsummary',
'description']
ret = {}
for prod_meta, is_base_product in six.iteritems(p_data):
product = _parse_suse_product(prod_meta, *info)
product['baseproduct'] = is_base_product is not None
ret[product.pop('name')] = product
ret = list()
doc = dom.parseString(__salt__['cmd.run'](("zypper -x products{0}".format(not all and ' -i' or '')),
output_loglevel='trace'))
for prd in doc.getElementsByTagName('product-list')[0].getElementsByTagName('product'):
p_data = dict()
p_nfo = dict(prd.attributes.items())
p_name = p_nfo.pop('name')
p_data[p_name] = p_nfo
p_data[p_name]['eol'] = prd.getElementsByTagName('endoflife')[0].getAttribute('text')
descr = prd.getElementsByTagName('description')[0].childNodes[0].nodeValue
p_data[p_name]['description'] = " ".join([line.strip() for line in descr.split(os.linesep)])
ret.append(p_data)
return ret