def api_get_regions(request):
    cloud_name = request.GET.get('cloud_name', '')
    access_key = request.GET.get('access_key', '')
    secret_key = request.GET.get('secret_key', '')
    instance_type = request.GET.get('instance_type', '')
    regions = []
    if (cloud_name != '' and access_key != '' and secret_key != '' and instance_type != ''):
        cloud = models.Cloud.objects.get(name=cloud_name)
        ec2_conn = connect_ec2(access_key, secret_key, cloud)
        regions = _find_placement(ec2_conn, instance_type, cloud.cloud_type, get_all=True)
        result_text = simplejson.dumps(regions)
    else:
        result_text = "{'error': 'Please provide correct parameters'}" #STUB
    result = HttpResponse(result_text)
    return result
def get_placements(request):
    if request.is_ajax():
        if request.method == 'POST':
            cloud_id = request.POST.get('cloud_id', '')
            a_key = request.POST.get('a_key', '')
            s_key = request.POST.get('s_key', '')
            inst_type = request.POST.get('instance_type', '')
            placements = []
            if cloud_id != '' and a_key != '' and s_key != '' and inst_type != '':
                # Needed to get the cloud connection
                cloud = models.Cloud.objects.get(pk=cloud_id)
                ec2_conn = connect_ec2(a_key, s_key, cloud)
                placements = _find_placement(ec2_conn, inst_type, cloud.cloud_type, get_all=True)
                state = {'placements': placements}
        else:
            log.error("Not a POST request")
    else:
        log.error("No XHR")
    return HttpResponse(simplejson.dumps(state), mimetype="application/json")
def get_placements(request):
    if request.is_ajax():
        if request.method == 'POST':
            cloud_id = request.POST.get('cloud_id', '')
            a_key = request.POST.get('a_key', '')
            s_key = request.POST.get('s_key', '')
            inst_type = request.POST.get('instance_type', '')
            placements = []
            if cloud_id != '' and a_key != '' and s_key != '' and inst_type != '':
                # Needed to get the cloud connection
                cloud = models.Cloud.objects.get(pk=cloud_id)
                ec2_conn = connect_ec2(a_key, s_key, cloud)
                placements = _find_placement(ec2_conn,
                                             inst_type,
                                             cloud.cloud_type,
                                             get_all=True)
                state = {'placements': placements}
        else:
            log.error("Not a POST request")
    else:
        log.error("No XHR")
    return HttpResponse(simplejson.dumps(state), mimetype="application/json")