Ejemplo n.º 1
0
def get_base_image_info(request):
    params = request.GET
    base_image_info = baseimages_helper.get_by_id(request, params['id'])
    contents = render_to_string("clusters/get_base_image_info.tmpl", {
        'base_image_info': base_image_info,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 2
0
    def post(self, request, name, stage):
        try:
            env = environs_helper.get_env_by_stage(request, name, stage)
            cluster_name = env.get('clusterName')
            cluster_info = json.loads(request.body)
            log.info("Update Cluster Configuration with {}", cluster_info)

            cluster_name = '{}-{}'.format(name, stage)
            current_cluster = clusters_helper.get_cluster(request, cluster_name)
            log.info("getting current Cluster Configuration is {}", current_cluster)
            if 'configs' in current_cluster and 'configs' in cluster_info:
                if 'spiffe_id' in current_cluster['configs'] and 'spiffe_id' in cluster_info['configs']:
                    if current_cluster['configs']['spiffe_id'] != cluster_info['configs']['spiffe_id']:
                       log.error("Teletraan does not support user to update spiffe_id %s" % cluster_info['spiffe_id'])
                       raise TeletraanException("Teletraan does not support user to update spiffe_id")

                if 'spiffe_id' in current_cluster['configs'] and 'spiffe_id' not in cluster_info['configs']:
                    log.error("Teletraan does not support user to remove spiffe_id %s" % cluster_info['spiffe_id'])
                    raise TeletraanException("Teletraan does not support user to remove spiffe_id")

            image = baseimages_helper.get_by_id(request, cluster_info['baseImageId'])
            clusters_helper.update_cluster(request, cluster_name, cluster_info)
        except NotAuthorizedException as e:
            log.error("Have an NotAuthorizedException error {}".format(e))
            return HttpResponse(e, status=403, content_type="application/json")
        except Exception as e:
            log.error("Post to cluster configuration view has an error {}", e)
            return HttpResponse(e, status=500, content_type="application/json")
        return HttpResponse(json.dumps(cluster_info), content_type="application/json")
Ejemplo n.º 3
0
def get_base_image_info(request):
    params = request.GET
    base_image_info = baseimages_helper.get_by_id(request, params['id'])
    contents = render_to_string("clusters/get_base_image_info.tmpl", {
        'base_image_info': base_image_info,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 4
0
def get_image_names(request):
    params = request.GET
    provider = params["provider"]
    env_name = params["env"]
    stage_name = params["stage"]
    image_names = baseimages_helper.get_image_names(request, provider)
    curr_image_name = None
    curr_base_image = None
    if "curr_base_image" in params:
        curr_base_image = params["curr_base_image"]
        image = baseimages_helper.get_by_id(request, curr_base_image)
        curr_image_name = image.get("abstract_name")

    contents = render_to_string(
        "clusters/get_image_name.tmpl",
        {
            "image_names": image_names,
            "curr_image_name": curr_image_name,
            "curr_base_image": curr_base_image,
            "provider": provider,
            "env_name": env_name,
            "stage_name": stage_name,
        },
    )
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 5
0
def get_cluster(request, name, stage):
    envs = environs_helper.get_all_env_stages(request, name)
    stages, env = common.get_all_stages(envs, stage)
    provider_list = baseimages_helper.get_all_providers(request)
    basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
    adv = False
    is_cmp = False
    if basic_cluster_info:
        base_image_id = basic_cluster_info.get('baseImageId')
        base_image = baseimages_helper.get_by_id(request, base_image_id)
        if base_image.get('abstract_name') != 'CMP-DOCKER':
            adv = True
        else:
            is_cmp = True

    params = request.GET
    if params.get('adv'):
        adv = params.get('adv')

    return render(request, 'clusters/clusters.html', {
        'env': env,
        'envs': envs,
        'stages': stages,
        'provider_list': provider_list,
        'basic_cluster_info': basic_cluster_info,
        'adv': adv,
        'is_cmp': is_cmp,
    })
Ejemplo n.º 6
0
def get_cluster(request, name, stage):
    envs = environs_helper.get_all_env_stages(request, name)
    stages, env = common.get_all_stages(envs, stage)
    provider_list = baseimages_helper.get_all_providers(request)
    basic_cluster_info = clusters_helper.get_cluster(request, env.get("clusterName"))
    adv = False
    is_cmp = False
    if basic_cluster_info:
        base_image_id = basic_cluster_info.get("baseImageId")
        base_image = baseimages_helper.get_by_id(request, base_image_id)
        if base_image.get("abstract_name") != CMP_DOCKER_IMAGE:
            adv = True
        else:
            is_cmp = True

    params = request.GET
    if params.get("adv"):
        adv = params.get("adv")

    return render(
        request,
        "clusters/clusters.html",
        {
            "env": env,
            "envs": envs,
            "stages": stages,
            "provider_list": provider_list,
            "basic_cluster_info": basic_cluster_info,
            "adv": adv,
            "is_cmp": is_cmp,
        },
    )
Ejemplo n.º 7
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(request, base_image_id)
                if base_image.get('abstract_name') != 'CMP-DOCKER':
                    adv = True

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = common.get_non_cmp_group(request, name, stage)
            html = render_to_string("configs/capacity.tmpl", {
                "env": env,
                "hosts": ','.join(hosts),
                "groups": ','.join(groups),
                "csrf_token": get_token(request),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = common.get_non_cmp_group(request, name, stage)
        return render(request, 'configs/capacity.html', {
            "envs": envs,
            "env": env,
            "stages": stages,
            "hosts": ','.join(hosts),
            "groups": ','.join(groups),
            'is_pinterest': IS_PINTEREST,
            'provider_list': provider_list,
            'basic_cluster_info': basic_cluster_info,
            'adv': adv,
            'create_new': create_new,
        })
Ejemplo n.º 8
0
 def post(self, request, name, stage):
     try:
         env = environs_helper.get_env_by_stage(request, name, stage)
         cluster_name = env.get('clusterName')
         cluster_info = json.loads(request.body)
         log.info("Update Cluster Configuration with {}", cluster_info)
         image = baseimages_helper.get_by_id(request, cluster_info['baseImageId'])
         clusters_helper.update_cluster(request, cluster_name, cluster_info)
     except Exception as e:
         log.info("Post to cluster configuration view has an error {}", e)
         return HttpResponse(e, status=500, content_type="application/json")
     return HttpResponse(json.dumps(cluster_info), content_type="application/json")
Ejemplo n.º 9
0
 def post(self, request, name, stage):
     try:
         env = environs_helper.get_env_by_stage(request, name, stage)
         cluster_name = env.get('clusterName')
         cluster_info = json.loads(request.body)
         log.info("Update Cluster Configuration with {}", cluster_info)
         image = baseimages_helper.get_by_id(
             request, cluster_info['baseImageId'])
         clusters_helper.update_cluster(request, cluster_name, cluster_info)
     except Exception as e:
         log.info("Post to cluster configuration view has an error {}", e)
         return HttpResponse(e, status=500, content_type="application/json")
     return HttpResponse(json.dumps(cluster_info), content_type="application/json")
    def get(self, request, name, stage):

        cluster_name = '{}-{}'.format(name, stage)
        current_cluster = clusters_helper.get_cluster(request, cluster_name)
        host_types = hosttypes_helper.get_by_provider(request,
                                                      DEFAULT_PROVIDER)
        current_image = baseimages_helper.get_by_id(
            request, current_cluster['baseImageId'])
        current_cluster['baseImageName'] = current_image['abstract_name']
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        cells = cells_helper.get_by_provider(request,
                                             current_cluster['provider'])
        security_zones = securityzones_helper.get_by_provider_and_cell_name(
            request, current_cluster['provider'], current_cluster['cellName'])
        placements = placements_helper.get_by_provider_and_cell_name(
            request, current_cluster['provider'], current_cluster['cellName'])
        base_images = get_base_image_info_by_name(
            request, current_image['abstract_name'],
            current_cluster['cellName'])
        base_images_names = baseimages_helper.get_image_names(
            request, current_cluster['provider'], current_cluster['cellName'])

        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'cells': cells,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE),
            'currentCluster': current_cluster
        }

        return render(
            request, 'clusters/cluster_configuration.html', {
                'env': env,
                'capacity_creation_info': json.dumps(capacity_creation_info),
                'user_data_config_settings_wiki':
                USER_DATA_CONFIG_SETTINGS_WIKI,
                'is_pinterest': IS_PINTEREST
            })
Ejemplo n.º 11
0
def get_image_names(request):
    params = request.GET
    provider = params['provider']
    image_names = baseimages_helper.get_image_names(request, provider)
    curr_image_name = None
    if 'curr_base_image' in params:
        image = baseimages_helper.get_by_id(request, params['curr_base_image'])
        curr_image_name = image.get('abstract_name')

    contents = render_to_string("clusters/get_image_name.tmpl", {
        'image_names': image_names,
        'curr_image_name': curr_image_name,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 12
0
def get_image_names(request):
    params = request.GET
    provider = params['provider']
    image_names = baseimages_helper.get_image_names(request, provider)
    curr_image_name = None
    if 'curr_base_image' in params:
        image = baseimages_helper.get_by_id(request, params['curr_base_image'])
        curr_image_name = image.get('abstract_name')

    contents = render_to_string("clusters/get_image_name.tmpl", {
        'image_names': image_names,
        'curr_image_name': curr_image_name,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 13
0
    def get(self, request, name, stage):

        cluster_name = '{}-{}'.format(name, stage)
        current_cluster = clusters_helper.get_cluster(request, cluster_name)
        host_types = hosttypes_helper.get_by_provider(
            request, DEFAULT_PROVIDER)
        current_image = baseimages_helper.get_by_id(
            request, current_cluster['baseImageId'])
        current_cluster['baseImageName'] = current_image['abstract_name']
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        cells = cells_helper.get_by_provider(request, current_cluster['provider'])
        security_zones = securityzones_helper.get_by_provider_and_cell_name(
            request, current_cluster['provider'], current_cluster['cellName'])
        placements = placements_helper.get_by_provider_and_cell_name(
            request, current_cluster['provider'], current_cluster['cellName'])
        base_images = get_base_image_info_by_name(
            request, current_image['abstract_name'], current_cluster['cellName'])
        base_images_names = baseimages_helper.get_image_names(
            request, current_cluster['provider'], current_cluster['cellName'])

        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'cells': cells,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE),
            'currentCluster': current_cluster
        }
        return render(request, 'clusters/cluster_configuration.html', {
            'env': env,
            'capacity_creation_info': json.dumps(capacity_creation_info),
            'user_data_config_settings_wiki': USER_DATA_CONFIG_SETTINGS_WIKI,
            'is_pinterest': IS_PINTEREST})
Ejemplo n.º 14
0
def get_base_images_by_name(request):
    params = request.GET
    base_images = None
    if "name" in params:
        name = params["name"]
        base_images = baseimages_helper.get_by_name(request, name)

    curr_base_image = None
    if "curr_base_image" in params:
        curr_base_image = params["curr_base_image"]
        image = baseimages_helper.get_by_id(request, curr_base_image)
        curr_image_name = image.get("abstract_name")
        base_images = baseimages_helper.get_by_name(request, curr_image_name)

    contents = render_to_string(
        "clusters/get_base_image.tmpl", {"base_images": base_images, "curr_base_image": curr_base_image}
    )
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 15
0
    def get(self, request, name, stage):

        cluster_name = '{}-{}'.format(name, stage)
        current_cluster = clusters_helper.get_cluster(request, cluster_name)
        host_types = hosttypes_helper.get_by_provider(request,
                                                      DEFAULT_PROVIDER)
        current_image = baseimages_helper.get_by_id(
            request, current_cluster['baseImageId'])
        current_cluster['baseImageName'] = current_image['abstract_name']
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        security_zones = securityzones_helper.get_by_provider(
            request, current_cluster['provider'])
        placements = placements_helper.get_by_provider(
            request, current_cluster['provider'])
        base_images = baseimages_helper.get_by_name(
            request, current_image['abstract_name'])
        base_images_names = baseimages_helper.get_image_names(
            request, current_cluster['provider'])

        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'defaultMappings': PINTEREST_SECURITY_GROUP_PLACEMENTMAPPING,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE),
            'currentCluster': current_cluster
        }
        return render(
            request, 'clusters/cluster_configuration.html', {
                'env': env,
                'capacity_creation_info': json.dumps(capacity_creation_info)
            })
Ejemplo n.º 16
0
def get_base_images_by_name(request):
    params = request.GET
    base_images = None
    if 'name' in params:
        name = params['name']
        base_images = baseimages_helper.get_by_name(request, name)

    curr_base_image = None
    if 'curr_base_image' in params:
        curr_base_image = params['curr_base_image']
        image = baseimages_helper.get_by_id(request, curr_base_image)
        curr_image_name = image.get('abstract_name')
        base_images = baseimages_helper.get_by_name(request, curr_image_name)

    contents = render_to_string("clusters/get_base_image.tmpl", {
        'base_images': base_images,
        'curr_base_image': curr_base_image,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 17
0
def get_image_names(request):
    params = request.GET
    provider = params['provider']
    env_name = params['env']
    stage_name = params['stage']
    cell = params.get('cell', DEFAULT_CELL)
    image_names = baseimages_helper.get_image_names(request, provider, cell)
    curr_image_name = None
    curr_base_image = None
    if 'curr_base_image' in params:
        curr_base_image = params['curr_base_image']
        image = baseimages_helper.get_by_id(request, curr_base_image)
        curr_image_name = image.get('abstract_name')

    contents = render_to_string("clusters/get_image_name.tmpl", {
        'image_names': image_names,
        'curr_image_name': curr_image_name,
        'curr_base_image': curr_base_image,
        'provider': provider,
        'env_name': env_name,
        'stage_name': stage_name,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 18
0
def get_image_names(request):
    params = request.GET
    provider = params['provider']
    env_name = params['env']
    stage_name = params['stage']
    cell = params.get('cell', DEFAULT_CELL)
    image_names = baseimages_helper.get_image_names(request, provider, cell)
    curr_image_name = None
    curr_base_image = None
    if 'curr_base_image' in params:
        curr_base_image = params['curr_base_image']
        image = baseimages_helper.get_by_id(request, curr_base_image)
        curr_image_name = image.get('abstract_name')

    contents = render_to_string("clusters/get_image_name.tmpl", {
        'image_names': image_names,
        'curr_image_name': curr_image_name,
        'curr_base_image': curr_base_image,
        'provider': provider,
        'env_name': env_name,
        'stage_name': stage_name,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Ejemplo n.º 19
0
    def get(self, request, name, stage):

        cluster_name = '{}-{}'.format(name, stage)
        current_cluster = clusters_helper.get_cluster(request, cluster_name)
        host_types = hosttypes_helper.get_by_provider(request, DEFAULT_PROVIDER)
        current_image = baseimages_helper.get_by_id(request, current_cluster['baseImageId'])
        current_cluster['baseImageName'] = current_image['abstract_name']
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        security_zones = securityzones_helper.get_by_provider(request, current_cluster['provider'])
        placements = placements_helper.get_by_provider(request, current_cluster['provider'])
        base_images = baseimages_helper.get_by_name(request, current_image['abstract_name'])
        base_images_names = baseimages_helper.get_image_names(request, current_cluster['provider'])


        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'defaultMappings': PINTEREST_SECURITY_GROUP_PLACEMENTMAPPING,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE),
            'currentCluster': current_cluster
        }
        return render(request, 'clusters/cluster_configuration.html', {
            'env': env,
            'capacity_creation_info': json.dumps(capacity_creation_info)})
Ejemplo n.º 20
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        cluster_name = env.get('clusterName')
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(request, cluster_name)
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(request, base_image_id)
                asg_cluster = autoscaling_groups_helper.get_group_info(request, cluster_name)
                basic_cluster_info['asg_info'] = asg_cluster
                basic_cluster_info['base_image_info'] = base_image

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = common.get_env_groups(request, name, stage)
            if cluster_name in groups:
                groups.remove(cluster_name)
            info = {
                "env": env,
                "hosts": hosts,
                "groups": groups,
                "csrf_token": get_token(request),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            }
            return HttpResponse(json.dumps(info), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = common.get_env_groups(request, name, stage)
        if cluster_name in groups:
            groups.remove(cluster_name)
        data = {
            "envs": envs,
            "env": env,
            "stages": stages,
            "hosts": hosts,
            "groups": groups,
            'is_pinterest': IS_PINTEREST,
            'provider_list': provider_list,
            'basic_cluster_info': basic_cluster_info,
            'adv': adv,
            'create_new': create_new
        }
        data['info'] = json.dumps(data)
        return render(request, 'configs/capacity.html', data)
Ejemplo n.º 21
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(
                request, env.get('clusterName'))
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(
                    request, base_image_id)
                if base_image.get('abstract_name') != 'CMP-DOCKER':
                    adv = True

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request,
                                                     name,
                                                     stage,
                                                     capacity_type="HOST")
            groups = common.get_non_cmp_group(request, name, stage)
            html = render_to_string(
                "configs/capacity.tmpl", {
                    "env": env,
                    "hosts": ','.join(hosts),
                    "groups": ','.join(groups),
                    "csrf_token": get_token(request),
                    'is_pinterest': IS_PINTEREST,
                    'provider_list': provider_list,
                    'basic_cluster_info': basic_cluster_info,
                    'adv': adv,
                    'create_new': create_new,
                })
            return HttpResponse(json.dumps({'html': html}),
                                content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request,
                                                 name,
                                                 stage,
                                                 capacity_type="HOST")
        groups = common.get_non_cmp_group(request, name, stage)
        return render(
            request, 'configs/capacity.html', {
                "envs": envs,
                "env": env,
                "stages": stages,
                "hosts": ','.join(hosts),
                "groups": ','.join(groups),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            })
Ejemplo n.º 22
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        cluster_name = env.get('clusterName')
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(request, cluster_name)
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(request, base_image_id)
                asg_cluster = autoscaling_groups_helper.get_group_info(request, cluster_name)
                basic_cluster_info['asg_info'] = asg_cluster

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = common.get_env_groups(request, name, stage)
            if cluster_name in groups:
                groups.remove(cluster_name)
            info = {
                "env": env,
                "hosts": hosts,
                "groups": groups,
                "csrf_token": get_token(request),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            }
            return HttpResponse(json.dumps(info), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = common.get_env_groups(request, name, stage)
        if cluster_name in groups:
            groups.remove(cluster_name)
        data = {
            "envs": envs,
            "env": env,
            "stages": stages,
            "hosts": hosts,
            "groups": groups,
            'is_pinterest': IS_PINTEREST,
            'provider_list': provider_list,
            'basic_cluster_info': basic_cluster_info,
            'adv': adv,
            'create_new': create_new
        }
        data['info'] = json.dumps(data)
        return render(request, 'configs/capacity.html', data)