Merge pull request #5099 from virtua-network/smartos_features

grains/core : add useful information from SmartOS zone
This commit is contained in:
Thomas S Hatch 2013-05-17 14:11:34 -07:00
commit adb44411f1

View File

@ -471,6 +471,8 @@ def _virtual(osdata):
zone = __salt__['cmd.run']('{0}'.format(zonename)) zone = __salt__['cmd.run']('{0}'.format(zonename))
if zone != "global": if zone != "global":
grains['virtual'] = 'zone' grains['virtual'] = 'zone'
if osdata['os'] == 'SmartOS':
grains.update(_smartos_zone_data(grains))
# Check if it's a branded zone (i.e. Solaris 8/9 zone) # Check if it's a branded zone (i.e. Solaris 8/9 zone)
if isdir('/.SUNWnative'): if isdir('/.SUNWnative'):
grains['virtual'] = 'zone' grains['virtual'] = 'zone'
@ -993,6 +995,35 @@ def _hw_data(osdata):
grains[key] = value grains[key] = value
return grains return grains
def _smartos_zone_data(osdata):
'''
Return useful information from a SmartOS zone
'''
# Provides:
# pkgsrcversion
# imageversion
grains = {}
pkgsrcversion = re.compile('^release:\\s(.+)')
imageversion = re.compile('Image:\\s(.+)')
if os.path.isfile('/etc/pkgsrc_version'):
with salt.utils.fopen('/etc/pkgsrc_version', 'r') as fp_:
for line in fp_:
match = pkgsrcversion.match(line)
if match:
grains['pkgsrcversion'] = match.group(1)
if os.path.isfile('/etc/product'):
with salt.utils.fopen('/etc/product', 'r') as fp_:
for line in fp_:
match = imageversion.match(line)
if match:
grains['imageversion'] = match.group(1)
if 'pkgsrcversion' not in grains:
grains['pkgsrcversion'] = 'Unknown'
if 'imageversion' not in grains:
grains['imageversion'] = 'Unknown'
return grains
def get_server_id(): def get_server_id():
''' '''