Skip to content

Commit

Permalink
grains/core : add useful information from SmartOS zone
Browse files Browse the repository at this point in the history
This patch is intended for SmartOS users who are using OS
virtualization. You can now have access to :

- pkgsrcversion

- imageversion
  • Loading branch information
mguegan authored and basepi committed May 21, 2013
1 parent 04b8812 commit 977ddcf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions salt/grains/core.py
Expand Up @@ -432,6 +432,8 @@ def _virtual(osdata):
zone = __salt__['cmd.run']('{0}'.format(zonename))
if zone != "global":
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)
if isdir('/.SUNWnative'):
grains['virtual'] = 'zone'
Expand Down Expand Up @@ -936,6 +938,35 @@ def _hw_data(osdata):
grains[key] = value
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():
'''
Expand Down

0 comments on commit 977ddcf

Please sign in to comment.