def handle_send_connect(data): app.logger.info('Send connect: {}'.format(data)) computer_id = data['id'] computer_name = data['name'] computer_location = data['location'] computer_instance = data['instance'] computer = Computer.query.filter( Computer.computer_id == computer_id).first() if computer is None: computer = Computer(computer_id=computer_id, computer_name=computer_name, computer_location=computer_location, computer_instance=computer_instance) if Computer.add(computer): socketIo.emit('receive_register', computer_info_w(computer)) computer.computer_power_status = 1 computer.computer_cmd = 1 if Computer.update(computer): # emit to user room dashboard socketIo.emit('receive_update', computer_info_w(computer), room='{}_{}'.format(computer.computer_instance, computer_location)) # emit to socket client socketIo.emit('receive_connect', computer_info_w(computer))
def computer_add(): jb = request.get_json() computer_id = jb.get('computer_id') computer_instance = jb.get('computer_instance') computer_location = jb.get('computer_location') computer_name = jb.get('computer_name') if computer_name is None or computer_location is None or computer_instance is None: return invalid_input_w() computer = Computer(computer_id=computer_id, computer_location=computer_location, computer_name=computer_name, computer_instance=computer_instance) if Computer.add(computer): return { 'status': 'OK', 'msg': 'Computer successfully registered to system' } else: return {'status': 'ERROR', 'msg': 'Failed to register computer'}