def beacon(config):
 ret = []
 changes = {}
 txt = {}
 global LAST_GRAINS
 _validate = __validate__(config)
 if (not _validate[0]):
  log.warning('Beacon {0} configuration invalid, not adding. {1}'.format(__virtualname__, _validate[1]))
  return ret
 if ('servicename' in config):
  servicename = config['servicename']
 else:
  servicename = __grains__['host']
 for item in config['txt']:
  if config['txt'][item].startswith('grains.'):
   grain = config['txt'][item][7:]
   grain_index = None
   square_bracket = grain.find('[')
   if ((square_bracket != (-1)) and (grain[(-1)] == ']')):
    grain_index = int(grain[(square_bracket + 1):(-1)])
    grain = grain[:square_bracket]
   grain_value = __grains__.get(grain, '')
   if isinstance(grain_value, list):
    if (grain_index is not None):
     grain_value = grain_value[grain_index]
    else:
     grain_value = ','.join(grain_value)
   txt[item] = grain_value
   if (LAST_GRAINS and (LAST_GRAINS.get(grain, '') != __grains__.get(grain, ''))):
    changes[str(('txt.' + item))] = txt[item]
  else:
   txt[item] = config['txt'][item]
  if (not LAST_GRAINS):
   changes[str(('txt.' + item))] = txt[item]
 if changes:
  if (not LAST_GRAINS):
   changes['servicename'] = servicename
   changes['servicetype'] = config['servicetype']
   changes['port'] = config['port']
   GROUP.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), servicename, config['servicetype'], '', '', dbus.UInt16(config['port']), avahi.dict_to_txt_array(txt))
   GROUP.Commit()
  elif config.get('reset_on_change', False):
   GROUP.Reset()
   reset_wait = config.get('reset_wait', 0)
   if (reset_wait > 0):
    time.sleep(reset_wait)
   GROUP.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), servicename, config['servicetype'], '', '', dbus.UInt16(config['port']), avahi.dict_to_txt_array(txt))
   GROUP.Commit()
  else:
   GROUP.UpdateServiceTxt(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), servicename, config['servicetype'], '', avahi.dict_to_txt_array(txt))
  ret.append({'tag': 'result', 'changes': changes})
 if config.get('copy_grains', False):
  LAST_GRAINS = __grains__.copy()
 else:
  LAST_GRAINS = __grains__
 return ret

def beacon ( config ) : ret = [ ] changes = { } txt = { } global LAST_GRAINS _validate = __validate__ ( config ) if ( not _validate [ 0 ] ) : log . warning ( 'Beacon {0} configuration invalid, not adding. {1}' . format ( __virtualname__ , _validate [ 1 ] ) ) return ret if ( 'servicename' in config ) : servicename = config [ 'servicename' ] else : servicename = __grains__ [ 'host' ] for item in config [ 'txt' ] : if config [ 'txt' ] [ item ] . startswith ( 'grains.' ) : grain = config [ 'txt' ] [ item ] [ 7 : ] grain_index = None square_bracket = grain . find ( '[' ) if ( ( square_bracket != ( - 1 ) ) and ( grain [ ( - 1 ) ] == ']' ) ) : grain_index = int ( grain [ ( square_bracket + 1 ) : ( - 1 ) ] ) grain = grain [ : square_bracket ] grain_value = __grains__ . get ( grain , '' ) if isinstance ( grain_value , list ) : if ( grain_index is not None ) : grain_value = grain_value [ grain_index ] else : grain_value = ',' . join ( grain_value ) txt [ item ] = grain_value if ( LAST_GRAINS and ( LAST_GRAINS . get ( grain , '' ) != __grains__ . get ( grain , '' ) ) ) : changes [ str ( ( 'txt.' + item ) ) ] = txt [ item ] else : txt [ item ] = config [ 'txt' ] [ item ] if ( not LAST_GRAINS ) : changes [ str ( ( 'txt.' + item ) ) ] = txt [ item ] if changes : if ( not LAST_GRAINS ) : changes [ 'servicename' ] = servicename changes [ 'servicetype' ] = config [ 'servicetype' ] changes [ 'port' ] = config [ 'port' ] GROUP . AddService ( avahi . IF_UNSPEC , avahi . PROTO_UNSPEC , dbus . UInt32 ( 0 ) , servicename , config [ 'servicetype' ] , '' , '' , dbus . UInt16 ( config [ 'port' ] ) , avahi . dict_to_txt_array ( txt ) ) GROUP . Commit ( ) elif config . get ( 'reset_on_change' , False ) : GROUP . Reset ( ) reset_wait = config . get ( 'reset_wait' , 0 ) if ( reset_wait > 0 ) : time . sleep ( reset_wait ) GROUP . AddService ( avahi . IF_UNSPEC , avahi . PROTO_UNSPEC , dbus . UInt32 ( 0 ) , servicename , config [ 'servicetype' ] , '' , '' , dbus . UInt16 ( config [ 'port' ] ) , avahi . dict_to_txt_array ( txt ) ) GROUP . Commit ( ) else : GROUP . UpdateServiceTxt ( avahi . IF_UNSPEC , avahi . PROTO_UNSPEC , dbus . UInt32 ( 0 ) , servicename , config [ 'servicetype' ] , '' , avahi . dict_to_txt_array ( txt ) ) ret . append ( { 'tag' : 'result' , 'changes' : changes } ) if config . get ( 'copy_grains' , False ) : LAST_GRAINS = __grains__ . copy ( ) else : LAST_GRAINS = __grains__ return ret
return status for requested information .