예제 #1
0
def connection(uuid, session):
    LOG.debug('Received registration from %s with session %s', uuid, session)
    try:
        board = objects.Board.get_by_uuid(ctxt, uuid)
    except Exception as exc:
        msg = exc.message % {'board': uuid}
        LOG.error(msg)
        return wm.WampError(msg).serialize()

    try:
        old_ses = objects.SessionWP(ctxt)
        old_ses = old_ses.get_session_by_board_uuid(ctxt,
                                                    board.uuid,
                                                    valid=True)
        old_ses.valid = False
        old_ses.save()

    except Exception:
        LOG.debug('valid session for %s not found', board.uuid)

    session_data = {
        'board_id': board.id,
        'board_uuid': board.uuid,
        'session_id': session
    }
    session = objects.SessionWP(ctxt, **session_data)
    session.create()
    board.status = states.ONLINE
    board.save()
    LOG.info('Board %s (%s) is now  %s', board.uuid, board.name, states.ONLINE)
    return wm.WampSuccess('').serialize()
예제 #2
0
def registration(code_node, session_num):
    LOG.debug('Receved registration from %s with session %s', code_node,
              session_num)
    try:
        node = objects.Node.get_by_code({}, code_node)
    except Exception:
        return exception.NodeNotFound(node=code_node)
    try:
        old_session = objects.SessionWP({}).get_session_by_node_uuid(
            node.uuid, valid=True)
        old_session.valid = False
        old_session.save()
    except Exception:
        LOG.debug('valid session for %s Not found', node.uuid)

    session = objects.SessionWP({})
    session.node_id = node.id
    session.node_uuid = node.uuid
    session.session_id = session_num
    session.create()
    session.save()

    r = WampResponse()

    r.addSection('config', [])
    r.addConfig('add', 'config:node:uuid', node.uuid, 'config')
    r.addConfig('add', 'config:iotronic:command-agent', {
        "url": "ws://cmd-iotronic",
        "port": "8181",
        "realm": "s4t"
    }, 'config')

    return r.getResponse()
예제 #3
0
    def registration(self, ctx, code, session_num):
        LOG.debug('Received registration from %s with session %s', code,
                  session_num)
        try:
            board = objects.Board.get_by_code(ctx, code)

        except Exception as exc:
            msg = exc.message % {'board': code}
            LOG.error(msg)
            return wm.WampError(msg).serialize()

        if not board.status == states.REGISTERED:
            msg = "board with code %(board)s cannot " \
                  "be registered again." % {'board': code}
            LOG.error(msg)
            return wm.WampError(msg).serialize()

        try:
            old_ses = objects.SessionWP(ctx)
            old_ses = old_ses.get_session_by_board_uuid(ctx,
                                                        board.uuid,
                                                        valid=True)
            old_ses.valid = False
            old_ses.save()

        except Exception:
            LOG.debug('valid session for %s not found', board.uuid)

        session_data = {
            'board_id': board.id,
            'board_uuid': board.uuid,
            'session_id': session_num
        }
        session = objects.SessionWP(ctx, **session_data)
        session.create()

        board.agent = get_best_agent(ctx)
        agent = objects.WampAgent.get_by_hostname(ctx, board.agent)

        prov = Provisioner(board)
        prov.conf_registration_agent(self.ragent.wsurl)

        prov.conf_main_agent(agent.wsurl)
        loc = objects.Location.list_by_board_uuid(ctx, board.uuid)[0]
        prov.conf_location(loc)
        board.config = prov.get_config()

        board.status = states.OFFLINE
        board.save()

        LOG.debug('sending this conf %s', board.config)

        wmessage = wm.WampSuccess(board.config)
        return wmessage.serialize()
예제 #4
0
def leave_function(session_id):
    LOG.debug('A node with %s disconnectd', session_id)
    try:
        old_session = objects.SessionWP({}).get_by_session_id({}, session_id)
        old_session.valid = False
        old_session.save()
        LOG.debug('Session %s deleted', session_id)
    except Exception:
        LOG.debug('session %s not found', session_id)
예제 #5
0
def registration_uuid(uuid, session_num):
    LOG.debug('Receved registration from %s with session %s', uuid,
              session_num)
    try:
        node = objects.Node.get_by_uuid({}, uuid)
    except Exception:
        return exception.NodeNotFound(node=uuid)
    try:
        old_session = objects.SessionWP({}).get_session_by_node_uuid(
            node.uuid, valid=True)
        old_session.valid = False
        old_session.save()
    except Exception:
        LOG.debug('valid session for %s not found', node.uuid)

    session = objects.SessionWP({})
    session.node_id = node.id
    session.node_uuid = node.uuid
    session.session_id = session_num
    session.create()
    session.save()
    r = WampResponse()
    r.addSection('result', 0)
    return r.getResponse()
예제 #6
0
파일: node.py 프로젝트: fabio14/iotronic
    def _convert_with_locates(node, url, expand=True, show_password=True):

        try:
            session = objects.SessionWP({}).get_session_by_node_uuid(
                node.uuid, valid=True)
            node.session = session.session_id
        except Exception:
            pass

        if not expand:
            except_list = ['name', 'code', 'status', 'uuid', 'session']
            node.unset_fields_except(except_list)
            return node

        list_loc = objects.Location({}).list_by_node_id({}, node.id)
        node.location = loc.Location.convert_with_list(list_loc)

        return node