Exemplo n.º 1
0
def deallocate_instance(allocation_id):
    """
    Stops a running Packet Tracer instance.
    ---
    tags:
      - allocation
    parameters:
      - name: allocation_id
        in: path
        type: integer
        description: allocation identifier
        required: true
    responses:
      200:
          description: Allocation removed
          schema:
              $ref: '#/definitions/allocate_instance_post_Allocation'
      404:
          description: There is not an allocation for the given allocation_id.
          schema:
              $ref: '#/definitions/allocate_instance_post_Error'
    """
    instance = Instance.get_by_allocation_id(allocation_id)
    if not instance:
        return not_found(error="The allocation does not exist.")

    try:
        allocation_id = instance.allocated_by
        result = tasks.deallocate_instance.apply_async(args=(instance.id, ))
        result.get()
        allocation = Allocation.get(allocation_id)
        if allocation:
            # TODO update instance object as status has changed
            return jsonify(allocation.serialize(request.base_url, get_host()))
        # else
        return not_found(error="The allocation does not exist.")
    except Exception as e:
        return internal_error(e.args[0])
Exemplo n.º 2
0
def deallocate_instance(allocation_id):
    """
    Stops a running Packet Tracer instance.
    ---
    tags:
      - allocation
    parameters:
      - name: allocation_id
        in: path
        type: integer
        description: allocation identifier
        required: true
    responses:
      200:
          description: Allocation removed
          schema:
              $ref: '#/definitions/allocate_instance_post_Allocation'
      404:
          description: There is not an allocation for the given allocation_id.
          schema:
              $ref: '#/definitions/allocate_instance_post_Error'
    """
    instance = Instance.get_by_allocation_id(allocation_id)
    if not instance:
        return not_found(error="The allocation does not exist.")

    try:
        allocation_id = instance.allocated_by
        result = tasks.deallocate_instance.apply_async(args=(instance.id,))
        result.get()
        allocation = Allocation.get(allocation_id)
        if allocation:
            # TODO update instance object as status has changed
            return jsonify(allocation.serialize(request.base_url, get_host()))
        # else
        return not_found(error="The allocation does not exist.")
    except Exception as e:
        return internal_error(e.args[0])