def allocate_port():
    available_port = Port.allocate()
    if available_port is None:
        raise InsufficientResourcesError(
            'The server cannot create new instances. Please, wait and retry it.'
        )
    return available_port
Example #2
0
def list_ports():
    """
    Lists the ports used by the Packet Tracer instances.
    ---
    tags:
      - port
    parameters:
      - name: show
        in: query
        type: string
        description: Filter ports by their current status
        default: all
        enum: [all, available, unavailable]
    responses:
      200:
        description: Ports
        schema:
            properties:
                ports:
                    type: array
                    items:
                      id: Port
                      properties:
                        number:
                            type: integer
                            description: Number of port
                        used_by:
                            type: integer
                            description: Identifier of the instance currently using it or -1 if the port is available.
    """
    show_param = request.args.get("show")
    if show_param is None or show_param == "all":
        return jsonify(ports=[port.serialize for port in Port.get_all()])
    else:
        if show_param not in ("available", "unavailable"):
            return BadRequest(
                "The 'show' parameter must contain one of the following values: all, available or unavailable."
            )

        if show_param == "available":
            return jsonify(
                ports=[port.serialize for port in Port.get_available()])
        else:  # show_param is "unavailable":
            return jsonify(
                ports=[port.serialize for port in Port.get_unavailable()])
def list_ports():
    """
    Lists the ports used by the Packet Tracer instances.
    ---
    tags:
      - port
    parameters:
      - name: show
        in: query
        type: string
        description: Filter ports by their current status
        default: all
        enum: [all, available, unavailable]
    responses:
      200:
        description: Ports
        schema:
            properties:
                ports:
                    type: array
                    items:
                      id: Port
                      properties:
                        number:
                            type: integer
                            description: Number of port
                        used_by:
                            type: integer
                            description: Identifier of the instance currently using it or -1 if the port is available.
    """
    show_param = request.args.get("show")
    if show_param is None or show_param == "all":
        return jsonify(ports=[port.serialize for port in Port.get_all()])
    else:
        if show_param not in ("available", "unavailable"):
            return BadRequest("The 'show' parameter must contain one of the following values: all, available or unavailable.")

        if show_param == "available":
            return jsonify(ports=[port.serialize for port in Port.get_available()])
        else:  # show_param is "unavailable":
            return jsonify(ports=[port.serialize for port in Port.get_unavailable()])
def allocate_port():
    available_port = Port.allocate()
    if available_port is None:
        raise InsufficientResourcesError('The server cannot create new instances. Please, wait and retry it.')
    return available_port