コード例 #1
0
ファイル: __init__.py プロジェクト: EVMosaic/flamenco
def connect():
    # We assemble the remote_addr value with
    # the port value sent from the manager
    ip_address = request.remote_addr + ':' + str(request.form['port'])
    hostname = request.form['name']

    manager = Manager.query.filter_by(mac_address=mac_address).first()

    if manager:
        logging.info('Known manager requested connection, updating IP address')
        manager.ip_address = ip_address
        db.session.add(manager)
        db.session.commit()

    else:
        logging.info('New manager requested connection')
        # create new manager object with some defaults.
        # Later on most of these values will be passed as JSON object
        # during the first connection

        manager = Manager(name=hostname,
                          port=port,
                          ip_address=ip_address)

        db.session.add(manager)
        db.session.commit()
        logging.info('Manager added')

    # we verify the identity of the manager (will check on database)
    try:
        f = urllib.urlopen('http://' + ip_address)
        manager = json.loads(f.read())
        logging.info('Manager connected:')
        for k, v in manager.iteritems():
            logging.info('  {0}: {1}'.format(k, v))
        return 'You are now connected to the server'
    except:
        error = "server could not connect to manager with ip=" + ip_address
コード例 #2
0
ファイル: __init__.py プロジェクト: EVMosaic/flamenco
    def post(self):
        """Upon every manager startup, we check this resource to know if
        the manager already existed. If not, we create one and assign it a
        unique identifier.
        """
        args = parser.parse_args()
        ip_address = request.remote_addr
        port = args['port']
        has_virtual_workers = args['has_virtual_workers']

        manager = Manager.query\
            .filter_by(ip_address=ip_address)\
            .filter_by(port=port)\
            .first()

        if not manager:
            u = uuid.uuid1()
            manager = Manager(
                name=args['name'],
                ip_address=ip_address,
                port=port,
                has_virtual_workers=has_virtual_workers,
                uuid=u.hex)
            db.session.add(manager)
            db.session.commit()
            logging.info("New manager registered with uuid: {0}".format(u.hex))
        else:
            # Handle the case where the manager has no UUID
            if not manager.uuid:
                u = uuid.uuid1()
                manager.uuid = u.hex
                db.session.commit()
                logging.info("Manager updated with uuid: {0}".format(u.hex))

        logging.info("Manager connected at {0}:{1}".format(manager.ip_address, manager.port))

        return jsonify(uuid=manager.uuid)