示例#1
0
def upload_file(request):
    """
    if request is post: upload files to server and deal with these(unzip or save to database)
    else: show upload page
    Args:
        request (django.http.request.HttpRequest)
    """
    if request.method == "POST":
        region = request.POST['region']
        upload_files = request.FILES.getlist('file')
        upload_dir = '/tmp'
        for uploadFile in upload_files:
            upload_file_name = uploadFile.name
            # when upload zip, unzip and copy to dirname(${BASE_DIR})
            if upload_file_name.endswith('.zip'):
                filepath = os.path.join(os.path.dirname(BASE_DIR),
                                        upload_file_name)
                with open(filepath, 'wb+') as f:
                    for chunk in uploadFile.chunks():
                        f.write(chunk)
            else:
                return HttpResponse('error', status=500)
        return HttpResponse('success')
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'],
                                           exclude_regions=[current_region])
    uploader_page = SitePage.objects.get(name='uploader')
    return render(request, 'uploader/upload_bak.html', locals())
示例#2
0
def home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'],
                                           exclude_regions=[current_region])
    service_order = BasicServiceStarter.get_service_order(current_region)
    service_list = []
    for services in service_order.values():
        service_list += services
    basic_service_instances = ec2api.find_basic_instances(
        current_region, service_list)
    basic_service_infos = {}
    for order in service_order:
        basic_service_infos[order] = {}
    for instance in basic_service_instances:
        instance_state = instance.state['Name']
        instance_name = ec2api.get_instance_tag_name(instance)
        logger.debug('instance name: %s' % instance_name)
        service_name = ec2api.get_module_info(instance_name)[0]
        ip = instance.private_ip_address
        service_state = True
        service_order = BasicServiceDeployInfo.objects.get(
            service_name=service_name).order
        service_info = basic_service_infos[service_order].get(service_name)
        if service_info:
            service_info['total_count'] += 1
            if instance_state == 'running':
                service_info['running_count'] += 1
            else:
                service_info['service_state'] = False
            service_info.get('details').append(
                (instance_name, ip, instance_state))
        else:
            if instance_state == 'running':
                running_count = 1
            else:
                running_count = 0
                service_state = False
            basic_service_infos[service_order].update({
                service_name: {
                    'total_count': 1,
                    'running_count': running_count,
                    'service_state': service_state,
                    'details': [(instance_name, ip, instance_state)]
                }
            })
        logger.debug('basic service info after one instance: %s ' %
                     json.dumps(basic_service_infos))
    logger.debug('basic service infos: %s' % json.dumps(basic_service_infos))
    basic_service_page = SitePage.objects.get(name='basic')
    return render(
        request, 'basic/basic-service-details.html', {
            'basic_service_infos': basic_service_infos,
            'current_region': current_region,
            'regions': regions,
            'basic_service_page': basic_service_page
        })
示例#3
0
def home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region])
    launcher_page = SitePage.objects.get(name='launcher')
    return render(request, 'launcher/ec2-launcher.html', {
        'current_region': current_region,
        'regions': regions,
        'launcher_page': launcher_page,
        'account_name': ACCOUNT_NAME
    })
示例#4
0
def home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'],
                                           exclude_regions=[current_region])
    elb_page = SitePage.objects.get(name='elb')
    return render(request, 'elb/loadbalancer-info.html', {
        'current_region': current_region,
        'regions': regions,
        'elb_page': elb_page
    })
示例#5
0
def home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'],
                                           exclude_regions=[current_region])
    bizmodule_page = SitePage.objects.get(name='bizmodule')
    return render(
        request, 'bizmodule/business-module.html', {
            'current_region': current_region,
            'regions': regions,
            'bizmodule_page': bizmodule_page
        })
示例#6
0
def home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region])
    script_exec_logs = ScriptExecLog.objects.order_by('-exec_time')[:10]
    module_page = SitePage.objects.get(name='module')
    return render(request, 'module/index.html', {
        'regions': regions,
        'current_region': current_region,
        'module_page': module_page,
        'script_logs': script_exec_logs
    })
示例#7
0
def home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'],
                                           exclude_regions=[current_region])
    deploy_page = SitePage.objects.get(name='deploy')
    return render(
        request, 'deploy/index.html', {
            'current_region': current_region,
            'regions': regions,
            'deploy_page': deploy_page,
            'username': request.user.username
        })
示例#8
0
def auto_deploy_home(request):
    current_region = RegionInfo.get_region(request)
    regions = RegionInfo.get_regions_infos(['region', 'chinese_name'],
                                           exclude_regions=[current_region])
    autodeploy_historys = AutoDeployHistory.objects.all().order_by('-id')
    deploy_history_info = []
    for auto_deploy_history in autodeploy_historys:
        deploy_history_info.append([
            auto_deploy_history.id, auto_deploy_history.upgrade_version,
            auto_deploy_history.is_deploy_finish
            and auto_deploy_history.is_result_finish,
            auto_deploy_history.is_success, auto_deploy_history.start_time,
            auto_deploy_history.managers, auto_deploy_history.end_time
        ])
    logger.debug(deploy_history_info)
    return render(request, 'autodeploy/autodeploy-index.html', locals())