Exemplo n.º 1
0
def do_list_usage_deletes(request):

    filter_args = {}
    if 'instance' in request.GET:
        uuid = request.GET['instance']
        if not utils.is_uuid_like(uuid):
            msg = "%s is not uuid-like" % uuid
            return error_response(400, 'Bad Request', msg)
        filter_args['instance'] = uuid

    if len(filter_args) > 0:
        deletes = models.InstanceDeletes.objects.filter(**filter_args)
    else:
        deletes = models.InstanceDeletes.objects.all()

    results = [["UUID", "Launched At", "Deleted At"]]

    for delete in deletes:
        launched = None
        if delete.launched_at:
            launched = str(dt.dt_from_decimal(delete.launched_at))
        deleted = None
        if delete.deleted_at:
            deleted = str(dt.dt_from_decimal(delete.deleted_at))
        results.append([delete.instance, launched, deleted])

    return rsp(json.dumps(results))
Exemplo n.º 2
0
def do_list_usage_exists(request):

    filter_args = {}
    if 'instance' in request.GET:
        uuid = request.GET['instance']
        if not utils.is_uuid_like(uuid):
            msg = "%s is not uuid-like" % uuid
            return error_response(400, 'Bad Request', msg)
        filter_args['instance'] = uuid

    if len(filter_args) > 0:
        exists = models.InstanceExists.objects.filter(**filter_args)
    else:
        exists = models.InstanceExists.objects.all()

    results = [["UUID", "Launched At", "Deleted At", "Instance Type Id",
                "Message ID", "Status"]]

    for exist in exists:
        launched = None
        if exist.launched_at:
            launched = str(dt.dt_from_decimal(exist.launched_at))
        deleted = None
        if exist.deleted_at:
            deleted = str(dt.dt_from_decimal(exist.deleted_at))
        results.append([exist.instance, launched, deleted,
                        exist.instance_type_id, exist.message_id,
                        exist.status])

    return rsp(json.dumps(results))
Exemplo n.º 3
0
def do_list_usage_launches(request):

    filter_args = {}
    if 'instance' in request.GET:
        uuid = request.GET['instance']
        if not utils.is_uuid_like(uuid):
            msg = "%s is not uuid-like" % uuid
            return error_response(400, 'Bad Request', msg)
        filter_args['instance'] = uuid

    model = models.InstanceUsage.objects
    if len(filter_args) > 0:
        launches = model_search(request, model, filter_args)
    else:
        launches = model_search(request, model, None)

    results = [[
        "UUID", "Launched At", "Instance Type Id", "Instance Flavor Id"
    ]]

    for launch in launches:
        launched = None
        if launch.launched_at:
            launched = str(dt.dt_from_decimal(launch.launched_at))
        results.append([
            launch.instance, launched, launch.instance_type_id,
            launch.instance_flavor_id
        ])

    return rsp(json.dumps(results))
Exemplo n.º 4
0
def do_timings_uuid(request):
    uuid = request.GET['uuid']
    if not utils.is_uuid_like(uuid):
        msg = "%s is not uuid-like" % uuid
        return error_response(400, 'Bad Request', msg)
    results = get_timings_for_uuid(uuid)
    return rsp(json.dumps(results))
Exemplo n.º 5
0
def do_list_usage_launches(request):

    filter_args = {}
    if 'instance' in request.GET:
        uuid = request.GET['instance']
        if not utils.is_uuid_like(uuid):
            msg = "%s is not uuid-like" % uuid
            return error_response(400, 'Bad Request', msg)
        filter_args['instance'] = uuid

    model = models.InstanceUsage.objects
    if len(filter_args) > 0:
        launches = model_search(request, model, filter_args)
    else:
        launches = model_search(request, model, None)

    results = [["UUID", "Launched At", "Instance Type Id",
                "Instance Flavor Id"]]

    for launch in launches:
        launched = None
        if launch.launched_at:
            launched = str(dt.dt_from_decimal(launch.launched_at))
        results.append([launch.instance, launched, launch.instance_type_id,
                        launch.instance_flavor_id])

    return rsp(json.dumps(results))
Exemplo n.º 6
0
def do_uuid(request):
    uuid = str(request.GET['uuid'])
    service = str(request.GET.get('service', 'nova'))
    if not utils.is_uuid_like(uuid):
        msg = "%s is not uuid-like" % uuid
        return error_response(400, 'Bad Request', msg)
    model = _model_factory(service)
    result = []
    filters = {}

    if service == 'nova' or service == 'generic':
        filters = {'instance': uuid}
    if service == 'glance':
        filters = {'uuid': uuid}

    _add_when_filters(request, filters)

    related = model_search(request,
                           model,
                           filters,
                           related=True,
                           order_by='when')
    for event in related:
        when = dt.dt_from_decimal(event.when)
        routing_key_status = routing_key_type(event.routing_key)
        result = event.search_results(result, when, routing_key_status)
    return rsp(json.dumps(result))
Exemplo n.º 7
0
def do_timings_uuid(request):
    uuid = request.GET["uuid"]
    if not utils.is_uuid_like(uuid):
        msg = "%s is not uuid-like" % uuid
        return error_response(400, "Bad Request", msg)

    return rsp(get_timings_for_uuid(uuid))
Exemplo n.º 8
0
def do_uuid(request):
    uuid = str(request.GET['uuid'])
    if not utils.is_uuid_like(uuid):
        msg = "%s is not uuid-like" % uuid
        return error_response(400, 'Bad Request', msg)

    related = models.RawData.objects.select_related().filter(instance=uuid)\
                                                     .order_by('when')
    results = [["#", "?", "When", "Deployment", "Event", "Host", "State",
                "State'", "Task'"]]
    for e in related:
        when = dt.dt_from_decimal(e.when)
        results.append([e.id, routing_key_type(e.routing_key), str(when),
                        e.deployment.name, e.event, e.host, e.state,
                        e.old_state, e.old_task])
    return rsp(json.dumps(results))
Exemplo n.º 9
0
def do_uuid(request, service='nova'):
    uuid = str(request.GET['uuid'])
    if not utils.is_uuid_like(uuid):
        msg = "%s is not uuid-like" % uuid
        return error_response(400, 'Bad Request', msg)
    model = _model_factory(service)
    result = []
    param = {}
    if service == 'nova' or service == 'generic':
        param = {'instance': uuid}
    if service == 'glance':
        param = {'uuid': uuid}

    related = model.select_related().filter(**param).order_by('when')
    for event in related:
        when = dt.dt_from_decimal(event.when)
        routing_key_status = routing_key_type(event.routing_key)
        result = event.search_results(result, when, routing_key_status)
    return rsp(json.dumps(result))
Exemplo n.º 10
0
def do_uuid(request):
    uuid = str(request.GET['uuid'])
    service = str(request.GET.get('service', 'nova'))
    if not utils.is_uuid_like(uuid):
        msg = "%s is not uuid-like" % uuid
        return error_response(400, 'Bad Request', msg)
    model = _model_factory(service)
    result = []
    filters = {}

    if service == 'nova' or service == 'generic':
        filters = {'instance': uuid}
    if service == 'glance':
        filters = {'uuid': uuid}

    _add_when_filters(request, filters)

    related = model_search(request, model, filters,
                           related=True, order_by='when')
    for event in related:
        when = dt.dt_from_decimal(event.when)
        routing_key_status = routing_key_type(event.routing_key)
        result = event.search_results(result, when, routing_key_status)
    return rsp(json.dumps(result))
Exemplo n.º 11
0
def do_list_usage_launches(request):

    filter_args = {}
    if "instance" in request.GET:
        uuid = request.GET["instance"]
        if not utils.is_uuid_like(uuid):
            msg = "%s is not uuid-like" % uuid
            return error_response(400, "Bad Request", msg)
        filter_args["instance"] = uuid

    if len(filter_args) > 0:
        launches = models.InstanceUsage.objects.filter(**filter_args)
    else:
        launches = models.InstanceUsage.objects.all()

    results = [["UUID", "Launched At", "Instance Type Id"]]

    for launch in launches:
        launched = None
        if launch.launched_at:
            launched = str(dt.dt_from_decimal(launch.launched_at))
        results.append([launch.instance, launched, launch.instance_type_id])

    return rsp(results)