def process_presence_events(self, salt_data, token, opts):
        '''
        Check if any minions have connected or dropped.
        Send a message to the client if they have.
        '''
        log.debug('In presence')
        changed = False

        # check if any connections were dropped
        if set(salt_data['data'].get('lost', [])):
            dropped_minions = set(salt_data['data'].get('lost', []))
        else:
            dropped_minions = set(self.minions) - set(salt_data['data'].get('present', []))

        for minion in dropped_minions:
            changed = True
            log.debug('Popping %s', minion)
            self.minions.pop(minion, None)

        # check if any new connections were made
        if set(salt_data['data'].get('new', [])):
            log.debug('got new minions')
            new_minions = set(salt_data['data'].get('new', []))
            changed = True
        elif set(salt_data['data'].get('present', [])) - set(self.minions):
            log.debug('detected new minions')
            new_minions = set(salt_data['data'].get('present', [])) - set(self.minions)
            changed = True
        else:
            new_minions = []

        tgt = ','.join(new_minions)
        for mid in new_minions:
            log.debug('Adding minion')
            self.minions[mid] = {}

        if tgt:
            changed = True
            client = salt.netapi.NetapiClient(opts)
            client.run(
                {
                    'fun': 'grains.items',
                    'tgt': tgt,
                    'expr_type': 'list',
                    'mode': 'client',
                    'client': 'local',
                    'asynchronous': 'local_async',
                    'token': token,
                })

        if changed:
            self.publish_minions()
def process_presence_events ( self , salt_data , token , opts ) : log . debug ( 'In presence' ) changed = False if set ( salt_data [ 'data' ] . get ( 'lost' , [ ] ) ) : dropped_minions = set ( salt_data [ 'data' ] . get ( 'lost' , [ ] ) ) else : dropped_minions = set ( self . minions ) - set ( salt_data [ 'data' ] . get ( 'present' , [ ] ) ) for minion in dropped_minions : changed = True log . debug ( 'Popping %s' , minion ) self . minions . pop ( minion , None ) if set ( salt_data [ 'data' ] . get ( 'new' , [ ] ) ) : log . debug ( 'got new minions' ) new_minions = set ( salt_data [ 'data' ] . get ( 'new' , [ ] ) ) changed = True elif set ( salt_data [ 'data' ] . get ( 'present' , [ ] ) ) - set ( self . minions ) : log . debug ( 'detected new minions' ) new_minions = set ( salt_data [ 'data' ] . get ( 'present' , [ ] ) ) - set ( self . minions ) changed = True else : new_minions = [ ] tgt = ',' . join ( new_minions ) for mid in new_minions : log . debug ( 'Adding minion' ) self . minions [ mid ] = { } if tgt : changed = True client = salt . netapi . NetapiClient ( opts ) client . run ( { 'fun' : 'grains.items' , 'tgt' : tgt , 'expr_type' : 'list' , 'mode' : 'client' , 'client' : 'local' , 'asynchronous' : 'local_async' , 'token' : token , } ) if changed : self . publish_minions ( )
Check if any minions have connected or dropped.
        Send a message to the client if they have.