Exemplo n.º 1
0
def list_instances():
    """
    Lists instances.
    ---
    tags:
      - instance
    parameters:
      - name: show
        in: query
        type: string
        description: Show different types of instances
        default: running
        enum: [all, starting, deallocated, allocated, running, finished, error]
    responses:
      200:
        description: Packet Tracer instances
        schema:
            properties:
                instances:
                    type: array
                    items:
                      $ref: '#/definitions/assign_instance_post_Instance'
    """
    show_param = request.args.get("show")
    if show_param is None or show_param == "running":  # default option
        return get_json_instances(Instance.get_running())
    else:
        states = ("all", "starting", "deallocated", "allocated", "running",
                  "finished", "error")
        if show_param not in states:
            state_enum = "["
            for s in states:
                state_enum += "%s, " % s
            state_enum = state_enum[:-2] + "]"
            return BadRequest(
                "The 'show' parameter must contain one of the following values: %s."
                % state_enum)

        if show_param == "all":
            return get_json_instances(Instance.get_all())  # .limit(10)
        elif show_param == "starting":
            return get_json_instances(Instance.get_starting())
        elif show_param == "deallocated":
            return get_json_instances(Instance.get_deallocated())
        elif show_param == "allocated":
            return get_json_instances(Instance.get_allocated())
        elif show_param == "error":
            return get_json_instances(Instance.get_erroneous())
        else:  # show_param is "finished":
            return get_json_instances(Instance.get_finished())
Exemplo n.º 2
0
def list_instances():
    """
    Lists instances.
    ---
    tags:
      - instance
    parameters:
      - name: show
        in: query
        type: string
        description: Show different types of instances
        default: running
        enum: [all, starting, deallocated, allocated, running, finished, error]
    responses:
      200:
        description: Packet Tracer instances
        schema:
            properties:
                instances:
                    type: array
                    items:
                      $ref: '#/definitions/assign_instance_post_Instance'
    """
    show_param = request.args.get("show")
    if show_param is None or show_param == "running":  # default option
        return get_json_instances(Instance.get_running())
    else:
        states = ("all", "starting", "deallocated", "allocated", "running", "finished", "error")
        if show_param not in states:
            state_enum = "["
            for s in states:
                state_enum += "%s, " % s
            state_enum = state_enum[:-2] + "]"
            return BadRequest("The 'show' parameter must contain one of the following values: %s." % state_enum)

        if show_param == "all":
            return get_json_instances(Instance.get_all())  # .limit(10)
        elif show_param == "starting":
            return get_json_instances(Instance.get_starting())
        elif show_param == "deallocated":
            return get_json_instances(Instance.get_deallocated())
        elif show_param == "allocated":
            return get_json_instances(Instance.get_allocated())
        elif show_param == "error":
            return get_json_instances(Instance.get_erroneous())
        else:  # show_param is "finished":
            return get_json_instances(Instance.get_finished())