Beispiel #1
0
def task_result(request):
    post = json.loads(request.body)
    task_id = post.get("task_id")
    result = AsyncResult(task_id)
    if not result.ready():
        return json_response(None)
    return json_response(result.get(timeout=1))
Beispiel #2
0
def task_result(request):
    post = json.loads(request.body)
    task_id = post.get("task_id")
    result = AsyncResult(task_id)
    if not result.ready():
        return json_response(None)
    return json_response(result.get(timeout=1))
Beispiel #3
0
def check_template(request, provider_id, template_name):
    try:
        template = Template.objects.get(name=template_name, provider=provider_id)
    except ObjectDoesNotExist:
        return json_response(None)
    data = {
        'stream': template.template_group.id,
        'version': template.version,
        'date': template.date.strftime('%Y-%m-%d'),
        'preconfigured': template.preconfigured,
    }
    return json_response(data)
Beispiel #4
0
def check_template(request, provider_id, template_name):
    try:
        template = Template.objects.get(name=template_name, provider=provider_id)
    except ObjectDoesNotExist:
        return json_response(None)
    data = {
        'stream': template.template_group.id,
        'version': template.version,
        'date': template.date.strftime('%Y-%m-%d'),
        'preconfigured': template.preconfigured,
    }
    return json_response(data)
Beispiel #5
0
def check_pools(request):
    data = []
    for pool in AppliancePool.objects.all():
        pool_data = {
            'description':
            pool.description,
            'id':
            pool.id,
            'stream':
            pool.group.id,
            'version':
            pool.version,
            'date':
            pool.date.strftime('%Y-%m-%d'),
            'preconfigured':
            pool.preconfigured,
            'finished':
            pool.finished,
            'owner':
            pool.owner.username,
            'appliances':
            [[a.name, a.template.provider.id] for a in pool.appliances]
        }
        data.append(pool_data)
    return json_response(data)
Beispiel #6
0
def check_pool(request, pool_id):
    try:
        pool = AppliancePool.objects.get(id=pool_id)
    except ObjectDoesNotExist:
        return json_response(None)
    data = {
        'description': pool.description,
        'stream': pool.group.id,
        'version': pool.version,
        'date': pool.date.strftime('%Y-%m-%d'),
        'preconfigured': pool.preconfigured,
        'finished': pool.finished,
        'owner': pool.owner.username,
        'appliances': [[a.name, a.template.provider.id] for a in pool.appliances]
    }
    return json_response(data)
Beispiel #7
0
def check_appliance(request, provider_id, appliance_name):
    try:
        appliance = Appliance.objects.get(name=appliance_name, template__provider=provider_id)
    except ObjectDoesNotExist:
        return json_response(None)
    owner = appliance.owner
    if owner is not None:
        owner = owner.username
    data = {
        'stream': appliance.template.template_group.id,
        'version': appliance.template.version,
        'date': appliance.template.date.strftime('%Y-%m-%d'),
        'preconfigured': appliance.template.preconfigured,
        'owner': owner,
    }
    return json_response(data)
Beispiel #8
0
def check_pool(request, pool_id):
    try:
        pool = AppliancePool.objects.get(id=pool_id)
    except ObjectDoesNotExist:
        return json_response(None)
    data = {
        'description': pool.description,
        'stream': pool.group.id,
        'version': pool.version,
        'date': pool.date.strftime('%Y-%m-%d'),
        'preconfigured': pool.preconfigured,
        'finished': pool.finished,
        'owner': pool.owner.username,
        'appliances': [[a.name, a.template.provider.id] for a in pool.appliances]
    }
    return json_response(data)
Beispiel #9
0
def check_appliance(request, provider_id, appliance_name):
    try:
        appliance = Appliance.objects.get(name=appliance_name, template__provider=provider_id)
    except ObjectDoesNotExist:
        return json_response(None)
    owner = appliance.owner
    if owner is not None:
        owner = owner.username
    data = {
        'stream': appliance.template.template_group.id,
        'version': appliance.template.version,
        'date': appliance.template.date.strftime('%Y-%m-%d'),
        'preconfigured': appliance.template.preconfigured,
        'owner': owner,
    }
    return json_response(data)
Beispiel #10
0
def check_query(request):
    if not request.user.is_authenticated():
        return go_home(request)
    if request.method != 'POST':
        return HttpResponseForbidden('Only POST allowed')
    bz = Bugzilla.from_config().bugzilla
    try:
        parsed = bz.url_to_query(request.POST['url'])
        if not parsed:
            parsed = None
    except:
        parsed = None
    if 'cmdtype' in parsed:
        # It is a command and that is not supported within .query()
        parsed = None
    return json_response(parsed)
Beispiel #11
0
def check_query(request):
    if not request.user.is_authenticated():
        return go_home(request)
    if request.method != 'POST':
        return HttpResponseForbidden('Only POST allowed')
    bz = Bugzilla.from_config().bugzilla
    try:
        parsed = bz.url_to_query(request.POST['url'])
        if not parsed:
            parsed = None
    except:
        parsed = None
    if 'cmdtype' in parsed:
        # It is a command and that is not supported within .query()
        parsed = None
    return json_response(parsed)
Beispiel #12
0
def check_pools(request):
    data = []
    for pool in AppliancePool.objects.all():
        pool_data = {
            'description': pool.description,
            'id': pool.id,
            'stream': pool.group.id,
            'version': pool.version,
            'date': pool.date.strftime('%Y-%m-%d'),
            'preconfigured': pool.preconfigured,
            'finished': pool.finished,
            'owner': pool.owner.username,
            'appliances': [[a.name, a.template.provider.id] for a in pool.appliances]
        }
        data.append(pool_data)
    return json_response(data)
Beispiel #13
0
def set_appliance_description(request):
    if request.method != 'POST':
        messages.error(request, "Invalid request.")
        return go_home(request)
    post = json.loads(request.body)
    if not request.user.is_authenticated:
        raise PermissionDenied()
    try:
        appliance_id = post.get("appliance_id")
        appliance = Appliance.objects.get(id=appliance_id)
    except ObjectDoesNotExist:
        raise Http404('Appliance with ID {} does not exist!.'.format(appliance_id))
    if not can_operate_appliance_or_pool(appliance, request.user):
        raise PermissionDenied("Permission denied")
    new_description = post.get("description")
    appliance.description = new_description
    appliance.save()
    return json_response(True)
Beispiel #14
0
def set_appliance_description(request):
    if request.method != 'POST':
        messages.error(request, "Invalid request.")
        return go_home(request)
    post = json.loads(request.body)
    if not request.user.is_authenticated():
        raise PermissionDenied()
    try:
        appliance_id = post.get("appliance_id")
        appliance = Appliance.objects.get(id=appliance_id)
    except ObjectDoesNotExist:
        raise Http404('Appliance with ID {} does not exist!.'.format(appliance_id))
    if not can_operate_appliance_or_pool(appliance, request.user):
        raise PermissionDenied("Permission denied")
    new_description = post.get("description")
    appliance.description = new_description
    appliance.save()
    return json_response(True)