Skip to content

Commit

Permalink
Make disks grain datatyper more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
kev009 committed May 28, 2016
1 parent afd3c1b commit 8bf0290
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions salt/grains/disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,27 @@ class _geomconsts(object):

_datatypes = {
MEDIASIZE: ('re_int', r'(\d+)'),
SECTORSIZE: 'int',
STRIPESIZE: 'int',
STRIPEOFFSET: 'int',
ROTATIONRATE: 'int',
SECTORSIZE: 'try_int',
STRIPESIZE: 'try_int',
STRIPEOFFSET: 'try_int',
ROTATIONRATE: 'try_int',
}


def _datavalue(datatype, data):
if datatype == 'int':
return int(data)
elif datatype and datatype[0] == 're_int':
return int(re.search(datatype[1], data).group(1))
if datatype == 'try_int':
try:
return int(data)
except ValueError:
return None
elif datatype is tuple and datatype[0] == 're_int':
search = re.search(datatype[1], data)
if search:
try:
return int(search.group(1))
except ValueError:
return None
return None
else:
return data

Expand Down

0 comments on commit 8bf0290

Please sign in to comment.