def poll_switch(poller_email, ip_addr, credentials,
                req_obj='mac', oper="SCAN"):
    poller = user_api.get_user_object(poller_email)
    ip_int = long(netaddr.IPAddress(ip_addr))
    with util.lock('poll switch %s' % ip_addr, timeout=120) as lock:
        if not lock:
            raise Exception(
                'failed to acquire lock to poll switch %s' % ip_addr
            )

        # TODO(grace): before repoll the switch, set the state to repolling.
        # and when the poll switch is timeout, set the state to error.
        # the frontend should only consider some main state like INTIALIZED,
        # ERROR and SUCCESSFUL, REPOLLING is as an intermediate state to
        # indicate the switch is in learning the mac of the machines connected
        # to it.
        logging.debug('poll switch: %s', ip_addr)
        switch_dict, machine_dicts = _poll_switch(
            ip_addr, credentials, req_obj=req_obj, oper=oper
        )
        switches = switch_api.list_switches(ip_int=ip_int, user=poller)
        if not switches:
            logging.error('no switch found for %s', ip_addr)
            return

        for switch in switches:
            for machine_dict in machine_dicts:
                logging.debug('add machine: %s', machine_dict)
                switch_api.add_switch_machine(
                    switch['id'], False, user=poller, **machine_dict
                )
                switch_api.update_switch(
                    switch['id'],
                    user=poller,
                    **switch_dict
                )
Looking up different scopes for variables.
dataset/ETHPy150Open openstack/compass-core/compass/actions/poll_switch.py/poll_switch--crossover with--dataset/ETHPy150Open PyTables/PyTables/tables/tests/test_queries.py/ScalarTableUsageTestCase.test_scopes