From 9a6b2175c6c6b80fd557ad6ec6cfb54df0fcfcb5 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Thu, 14 Jul 2016 18:04:59 +0200 Subject: [PATCH] Implement "osmajorrelease" by killing spaghetti --- salt/grains/core.py | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/salt/grains/core.py b/salt/grains/core.py index 6c7a161aaa..278cb77aea 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -1482,32 +1482,6 @@ def os_data(): grains.update(_virtual(grains)) grains.update(_ps(grains)) - # Load additional OS family grains - if grains['os_family'] == "RedHat": - grains['osmajorrelease'] = grains['osrelease'].split('.', 1)[0] - - grains['osfinger'] = '{os}-{ver}'.format( - os=grains['osfullname'], - ver=grains['osrelease'].partition('.')[0]) - elif grains.get('osfullname') == 'Ubuntu': - grains['osmajorrelease'] = grains['osrelease'].split('.', 1)[0] - - grains['osfinger'] = '{os}-{ver}'.format( - os=grains['osfullname'], - ver=grains['osrelease']) - elif grains.get('osfullname') == "Debian": - grains['osmajorrelease'] = grains['osrelease'].split('.', 1)[0] - - grains['osfinger'] = '{os}-{ver}'.format( - os=grains['osfullname'], - ver=grains['osrelease'].partition('.')[0]) - elif grains.get('os') in ('FreeBSD', 'OpenBSD', 'NetBSD', 'Mac', 'Raspbian'): - grains['osmajorrelease'] = grains['osrelease'].split('.', 1)[0] - - grains['osfinger'] = '{os}-{ver}'.format( - os=grains['os'], - ver=grains['osrelease']) - if grains.get('osrelease', ''): osrelease_info = grains['osrelease'].split('.') for idx, value in enumerate(osrelease_info): @@ -1515,6 +1489,9 @@ def os_data(): continue osrelease_info[idx] = int(value) grains['osrelease_info'] = tuple(osrelease_info) + grains['osmajorrelease'] = grains['osrelease_info'][0] + os_name = 'os' if grains.get('os') in ('FreeBSD', 'OpenBSD', 'NetBSD', 'Mac', 'Raspbian') else 'osfullname' + grains['osfinger'] = '{0}-{1}'.format(grains[os_name], grains['osrelease_info'][0]) return grains