def post(self, request, name, stage): query_dict = request.POST hosts_str = query_dict["hosts"] hosts = [] if hosts_str: hosts = [x.strip() for x in hosts_str.split(',')] environs_helper.update_env_capacity(request, name, stage, capacity_type="HOST", data=hosts) groups_str = query_dict["groups"] groups = [] if groups_str: groups = [x.strip() for x in groups_str.split(',')] if IS_PINTEREST: basic_cluster_info = clusters_helper.get_cluster( request, name, stage) if basic_cluster_info: cluster_name = common.get_cluster_name(request, name, stage) groups.append(cluster_name) environs_helper.update_env_capacity(request, name, stage, capacity_type="GROUP", data=groups) return self.get(request, name, stage)
def get(self, request, group_name): asg_cluster = autoscaling_groups_helper.get_group_info(request, group_name) appNames = baseimages_helper.get_image_names(request, 'AWS') appNames = sorted(appNames) is_cmp = False if asg_cluster: asg_vm_info = asg_cluster.get("launchInfo") curr_image = None if asg_vm_info: curr_image = baseimages_helper.get_by_provider_name(request, asg_vm_info["imageId"]) if asg_vm_info.get("subnets"): asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',') group_info = asg_cluster.get("groupInfo") group_info = get_group_config_internal(group_info) envs = environs_helper.get_all_envs_by_group(request, group_name) for env in envs: basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName')) if basic_cluster_info: is_cmp = True else: asg_vm_info = None group_info = None curr_image = None pas_config = autoscaling_groups_helper.get_pas_config(request, group_name) return render(request, 'groups/asg_config.html', { "asg_vm_config": asg_vm_info, "app_names": appNames, "curr_image": curr_image, "group_config": group_info, "group_name": group_name, "pas_config": pas_config, "is_cmp": is_cmp })
def get(self, request, group_name): asg_cluster = autoscaling_groups_helper.get_group_info(request, group_name) appNames = baseimages_helper.get_image_names(request, 'AWS') appNames = sorted(appNames) is_cmp = False if asg_cluster: asg_vm_info = asg_cluster.get("launchInfo") curr_image = None if asg_vm_info: curr_image = baseimages_helper.get_by_provider_name(request, asg_vm_info["imageId"]) if asg_vm_info.get("subnets"): asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',') group_info = asg_cluster.get("groupInfo") group_info = get_group_config_internal(group_info) #Directly search the cluster name. As long as there exists a cluster, treat this as cmp and hide #Launch Configuration basic_cluster_info = clusters_helper.get_cluster(request, group_name) if basic_cluster_info: is_cmp = True else: asg_vm_info = None group_info = None curr_image = None pas_config = autoscaling_groups_helper.get_pas_config(request, group_name) return render(request, 'groups/asg_config.html', { "asg_vm_config": asg_vm_info, "app_names": appNames, "curr_image": curr_image, "group_config": group_info, "group_name": group_name, "pas_config": pas_config, "is_cmp": is_cmp })
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")
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, })
def get(self, request, group_name): asg_cluster = groups_helper.get_group_info(request, group_name) appNames = images_helper.get_all_app_names(request) appNames = sorted(appNames) is_cmp = False if asg_cluster: asg_vm_info = asg_cluster.get("launchInfo") if asg_vm_info and asg_vm_info.get("subnets"): asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',') group_info = asg_cluster.get("groupInfo") curr_image = images_helper.get_image_by_id(request, asg_vm_info["imageId"]) group_info = get_group_config_internal(group_info) envs = environs_helper.get_all_envs_by_group(request, group_name) for env in envs: basic_cluster_info = clusters_helper.get_cluster( request, env.get('envName'), env.get('stageName')) if basic_cluster_info: is_cmp = True else: asg_vm_info = None group_info = None curr_image = None return render( request, 'groups/asg_config.html', { "asg_vm_config": asg_vm_info, "app_names": appNames, "curr_image": curr_image, "group_config": group_info, "group_name": group_name, "is_cmp": is_cmp })
def get(self, request, group_name): asg_cluster = autoscaling_groups_helper.get_group_info(request, group_name) appNames = baseimages_helper.get_image_names(request, 'AWS') appNames = sorted(appNames) is_cmp = False if asg_cluster: asg_vm_info = asg_cluster.get("launchInfo") curr_image = None if asg_vm_info: curr_image = baseimages_helper.get_by_provider_name(request, asg_vm_info["imageId"]) if asg_vm_info.get("subnets"): asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',') group_info = asg_cluster.get("groupInfo") group_info = get_group_config_internal(group_info) #Directly search the cluster name. As long as there exists a cluster, treat this as cmp and hide #Launch Configuration basic_cluster_info = clusters_helper.get_cluster(request, group_name) if basic_cluster_info: is_cmp = True else: asg_vm_info = None group_info = None curr_image = None pas_config = autoscaling_groups_helper.get_pas_config(request, group_name) return render(request, 'groups/asg_config.html', { "asg_vm_config": asg_vm_info, "app_names": appNames, "curr_image": curr_image, "group_config": group_info, "group_name": group_name, "pas_config": pas_config, "is_cmp": is_cmp })
def get_advanced_cluster(request): params = request.GET provider = params["provider"] name = params["env"] stage = params["stage"] image_name = params["image_name"] cluster_name = common.get_cluster_name(request, name, stage) config_list = None advanced_cluster_info = {} if provider == PROVIDER_AWS: config_list = get_aws_config_name_list_by_image(image_name) basic_cluster_info = clusters_helper.get_cluster(request, cluster_name) if not basic_cluster_info: if image_name != CMP_DOCKER_IMAGE: advanced_cluster_info["aws_role"] = "base" else: advanced_cluster_info = get_default_cmp_configs(name, stage) else: if image_name != CMP_DOCKER_IMAGE: advanced_cluster_info = basic_cluster_info.get("configs") else: cmp_configs = get_default_cmp_configs(name, stage) advanced_cluster_info = basic_cluster_info.get("configs") for key, value in cmp_configs.iteritems(): if advanced_cluster_info.get(key) == value: advanced_cluster_info.pop(key) contents = render_to_string( "clusters/get_advanced_config.tmpl", {"provider": provider, "advanced_cluster_info": advanced_cluster_info, "config_list": config_list}, ) return HttpResponse(json.dumps(contents), content_type="application/json")
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, }, )
def get(self, request, group_name): asg_cluster = groups_helper.get_group_info(request, group_name) appNames = images_helper.get_all_app_names(request) appNames = sorted(appNames) is_cmp = False if asg_cluster: asg_vm_info = asg_cluster.get("launchInfo") if asg_vm_info and asg_vm_info.get("subnets"): asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',') group_info = asg_cluster.get("groupInfo") curr_image = images_helper.get_image_by_id(request, asg_vm_info["imageId"]) group_info = get_group_config_internal(group_info) envs = environs_helper.get_all_envs_by_group(request, group_name) for env in envs: basic_cluster_info = clusters_helper.get_cluster(request, env.get('envName'), env.get('stageName')) if basic_cluster_info: is_cmp = True else: asg_vm_info = None group_info = None curr_image = None return render(request, 'groups/asg_config.html', { "asg_vm_config": asg_vm_info, "app_names": appNames, "curr_image": curr_image, "group_config": group_info, "group_name": group_name, "is_cmp": is_cmp })
def get_advanced_cluster(request): params = request.GET provider = params['provider'] name = params['env'] stage = params['stage'] image_name = params['image_name'] cluster_name = common.get_cluster_name(request, name, stage) config_list = None advanced_cluster_info = {} if provider == PROVIDER_AWS: config_list = get_aws_config_name_list_by_image(image_name) basic_cluster_info = clusters_helper.get_cluster(request, cluster_name) if not basic_cluster_info: if image_name != 'CMP-DOCKER': advanced_cluster_info['aws_role'] = 'base' else: if image_name != 'CMP-DOCKER': advanced_cluster_info = basic_cluster_info.get('configs') else: cmp_configs = get_default_cmp_configs(name, stage) advanced_cluster_info = basic_cluster_info.get('configs') for key, value in cmp_configs.iteritems(): if advanced_cluster_info.get(key) == value: advanced_cluster_info.pop(key) contents = render_to_string('clusters/get_advanced_config.tmpl', { 'provider': provider, 'advanced_cluster_info': advanced_cluster_info, 'config_list': config_list, }) return HttpResponse(json.dumps(contents), content_type="application/json")
def get_non_cmp_group(request, name, stage): groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") if IS_PINTEREST: basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = get_cluster_name(request, name, stage) groups.remove(cluster_name) return groups
def gen_report(request, env, progress, sortByStatus="false"): agentStats = [] firstTimeAgentStats = [] deployStats = {} deprecatedDeployStats = [] # always set the current deploy = deploys_helper.get(request, env['deployId']) build_info = builds_helper.get_build_and_tag(request, deploy["buildId"]) stageDistMap = genStageDistMap() stateDistMap = genStateDistMap() currentDeployStat = DeployStatistics(deploy=deploy, build=build_info['build'], stageDistMap=stageDistMap, stateDistMap=stateDistMap, buildTag=build_info.get('tag')) deployStats[env['deployId']] = currentDeployStat for agent in progress["agents"]: if agent["firstDeploy"]: firstTimeAgentStats.append( addToEnvReport(request, deployStats, agent, env)) else: agentStats.append(addToEnvReport(request, deployStats, agent, env)) if sortByStatus == "true": agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y)) for key, value in deployStats.iteritems(): if key != env['deployId']: deprecatedDeployStats.append(value) provisioning_hosts = progress["provisioningHosts"] if IS_PINTEREST: basic_cluster_info = clusters_helper.get_cluster( request, env.get('clusterName')) if basic_cluster_info and basic_cluster_info.get('capacity'): hosts_in_cluster = clusters_helper.get_host_ids( request, env.get('clusterName')) num_to_fake = basic_cluster_info.get('capacity') - len( hosts_in_cluster) for i in range(num_to_fake): faked_host = {} faked_host['hostName'] = 'UNKNOWN' faked_host['hostId'] = 'UNKNOWN' faked_host['state'] = 'PROVISIONED' provisioning_hosts.append(faked_host) return AgentReport(firstTimeAgentStats=firstTimeAgentStats, agentStats=agentStats, currentDeployStat=currentDeployStat, deprecatedDeployStats=deprecatedDeployStats, missingHosts=progress["missingHosts"], provisioningHosts=provisioning_hosts, envName=env['envName'], stageName=env['stageName'])
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, })
def get_non_cmp_group(request, name, stage): groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") if IS_PINTEREST: basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = get_cluster_name(name, stage) groups.remove(cluster_name) return groups
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, name, stage) return render(request, 'clusters/clusters.html', { 'env': env, 'stages': stages, 'provider_list': provider_list, 'basic_cluster_info': basic_cluster_info, })
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, name, stage) return render(request, 'clusters/clusters.html', { 'env': env, 'stages': stages, 'provider_list': provider_list, 'basic_cluster_info': basic_cluster_info, })
def get_groups(request, name, stage): groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") # Hide cluster group info basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.remove(cluster_name) html = render_to_string('groups/simple_groups.tmpl', { "groups": groups, }) return HttpResponse(html)
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 })
def get_basic_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')) html = render_to_string('clusters/clusters.tmpl', { 'env': env, 'envs': envs, 'stages': stages, 'provider_list': provider_list, 'basic_cluster_info': basic_cluster_info, 'csrf_token': get_token(request), }) return HttpResponse(json.dumps(html), content_type="application/json")
def get(self, request, name, stage): if request.is_ajax(): # return data for ajax calls hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST") groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.remove(cluster_name) env = environs_helper.get_env_by_stage(request, name, stage) html = render_to_string("configs/capacity.tmpl", { "env": env, "hosts": ','.join(hosts), "groups": ','.join(groups), "csrf_token": get_token(request), }) 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 = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.remove(cluster_name) return render(request, 'configs/capacity.html', { "env": env, "stages": stages, "hosts": ','.join(hosts), "groups": ','.join(groups), })
def get(self, request, name, stage): if request.is_ajax(): # return data for ajax calls hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST") groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.remove(cluster_name) env = environs_helper.get_env_by_stage(request, name, stage) html = render_to_string("configs/capacity.tmpl", { "env": env, "hosts": ','.join(hosts), "groups": ','.join(groups), "csrf_token": get_token(request), }) 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 = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.remove(cluster_name) return render(request, 'configs/capacity.html', { "env": env, "stages": stages, "hosts": ','.join(hosts), "groups": ','.join(groups), })
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, name, stage) hosts_in_clusters = clusters_helper.get_hosts(request, env['envName'], env['stageName'], []) host_ids = ','.join(hosts_in_clusters) return render(request, 'clusters/clusters.html', { 'env': env, 'stages': stages, 'provider_list': provider_list, 'basic_cluster_info': basic_cluster_info, 'host_ids': host_ids, })
def gen_report(request, env, progress, sortByStatus="false"): agentStats = [] firstTimeAgentStats = [] deployStats = {} deprecatedDeployStats = [] # always set the current deploy = deploys_helper.get(request, env['deployId']) build = builds_helper.get_build(request, deploy["buildId"]) stageDistMap = genStageDistMap() stateDistMap = genStateDistMap() currentDeployStat = DeployStatistics(deploy=deploy, build=build, stageDistMap=stageDistMap, stateDistMap=stateDistMap) deployStats[env['deployId']] = currentDeployStat for agent in progress["agents"]: if agent["firstDeploy"]: firstTimeAgentStats.append(addToEnvReport(request, deployStats, agent, env)) else: agentStats.append(addToEnvReport(request, deployStats, agent, env)) if sortByStatus == "true": agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y)) for key, value in deployStats.iteritems(): if key != env['deployId']: deprecatedDeployStats.append(value) provisioning_hosts = progress["provisioningHosts"] basic_cluster_info = clusters_helper.get_cluster(request, env['envName'], env['stageName']) if basic_cluster_info and basic_cluster_info.get('capacity'): hosts_in_cluster = clusters_helper.get_hosts(request, env['envName'], env['stageName'], []) num_to_fake = basic_cluster_info.get('capacity') - len(hosts_in_cluster) for i in range(num_to_fake): faked_host = {} faked_host['hostName'] = 'UNKNOWN' faked_host['hostId'] = 'UNKNOWN' faked_host['state'] = 'PROVISIONED' provisioning_hosts.append(faked_host) return AgentReport(firstTimeAgentStats=firstTimeAgentStats, agentStats=agentStats, currentDeployStat=currentDeployStat, deprecatedDeployStats=deprecatedDeployStats, missingHosts=progress["missingHosts"], provisioningHosts=provisioning_hosts, envName=env['envName'], stageName=env['stageName'])
def get_groups(request, name, stage): groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") # Hide cluster group info basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.remove(cluster_name) html = render_to_string('groups/simple_groups.tmpl', { "groups": groups, }) return HttpResponse(html)
def get_basic_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")) html = render_to_string( "clusters/clusters.tmpl", { "env": env, "envs": envs, "stages": stages, "provider_list": provider_list, "basic_cluster_info": basic_cluster_info, "csrf_token": get_token(request), }, ) return HttpResponse(json.dumps(html), content_type="application/json")
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, name, stage) hosts_in_clusters = clusters_helper.get_hosts(request, env['envName'], env['stageName'], []) host_ids = ','.join(hosts_in_clusters) return render( request, 'clusters/clusters.html', { 'env': env, 'stages': stages, 'provider_list': provider_list, 'basic_cluster_info': basic_cluster_info, 'host_ids': host_ids, })
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})
def get(self, request, name, stage): if request.is_ajax(): env = environs_helper.get_env_by_stage(request, name, stage) html = render_to_string('configs/env_config.tmpl', { "env": env, "csrf_token": get_token(request), }) return HttpResponse(json.dumps({'html': html}), content_type="application/json") envs = environs_helper.get_all_env_stages(request, name) stages, env = common.get_all_stages(envs, stage) # get capacity to decide if we need to show the remove stage button show_remove = True # if people have already specified host capacity or group capacity but do not have cluster config # show capacity config page; otherwise, show cluster config page show_cluster_config = True hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST") if hosts: show_remove = False show_cluster_config = False else: groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") if groups: show_remove = False basic_cluster_info = clusters_helper.get_cluster( request, name, stage) if not basic_cluster_info: show_cluster_config = False return render( request, 'configs/env_config.html', { "env": env, "stages": stages, "show_remove": show_remove, "show_cluster_config": show_cluster_config, "pinterest": IS_PINTEREST, })
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) cluster_provider = clusters_helper.get_cluster_provider(request, name, stage) if cluster_provider == 'null': cluster_provider = None basic_cluster_info = clusters_helper.get_cluster(request, name, stage) advanced_cluster_info = clusters_helper.get_advanced_cluster(request, name, stage, cluster_provider) return render(request, 'clusters/clusters.html', { 'env': env, 'stages': stages, 'provider_list': provider_list, 'cluster_provider': cluster_provider, 'basic_cluster_info': basic_cluster_info, 'advanced_cluster_info': advanced_cluster_info, })
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) })
def launch_hosts(request, name, stage): params = request.POST num = int(params['num']) basic_cluster_info = clusters_helper.get_cluster(request, name, stage) cluster_capacity = 0 if basic_cluster_info: placement_id_str = basic_cluster_info.get('placement_id') placement_ids = placement_id_str.split(',') for placement_id in placement_ids: placement_info = placements_helper.get_by_id(request, placement_id) cluster_capacity += placement_info.get('capacity') if num < cluster_capacity: clusters_helper.launch_hosts(request, name, stage, num) else: content = 'The placement capacity is full. ' \ 'Please contact your friendly Teletraan owners for immediate assistance!' messages.add_message(request, messages.ERROR, content) return redirect('/env/{}/{}/'.format(name, stage))
def launch_hosts(request, name, stage): params = request.POST num = int(params['num']) basic_cluster_info = clusters_helper.get_cluster(request, name, stage) cluster_capacity = 0 if basic_cluster_info: placement_id_str = basic_cluster_info.get('placement_id') placement_ids = placement_id_str.split(',') for placement_id in placement_ids: placement_info = placements_helper.get_by_id(request, placement_id) cluster_capacity += placement_info.get('capacity') if num < cluster_capacity: clusters_helper.launch_hosts(request, name, stage, num) else: content = 'The placement capacity is full. ' \ 'Please contact your friendly Teletraan owners for immediate assistance!' messages.add_message(request, messages.ERROR, content) return redirect('/env/{}/{}/'.format(name, stage))
def view_cluster_replacement_details(request, name, stage, replacement_id): env = environs_helper.get_env_by_stage(request, name, stage) cluster_name = '{}-{}'.format(name, stage) replacement_event = clusters_helper.get_cluster_replacement_info( request, cluster_name, replacement_id) if not replacement_event: raise Exception("Replacement Id: %s Not Found.") basic_cluster_info = clusters_helper.get_cluster(request, cluster_name) capacity = basic_cluster_info.get("capacity") replacement_details = get_replacement_summary( request, cluster_name, replacement_event, capacity) config_histories = clusters_helper.get_cluster_replacement_config_histories( request, cluster_name, replacement_id) return render(request, 'clusters/cluster_replace_details.html', { "replace": replacement_details, "config_histories": config_histories, "env": env })
def view_cluster_replacement_details(request, name, stage, replacement_id): env = environs_helper.get_env_by_stage(request, name, stage) cluster_name = '{}-{}'.format(name, stage) replacement_event = clusters_helper.get_cluster_replacement_info( request, cluster_name, replacement_id) if not replacement_event: raise Exception("Replacement Id: %s Not Found.") basic_cluster_info = clusters_helper.get_cluster(request, cluster_name) capacity = basic_cluster_info.get("capacity") replacement_details = get_replacement_summary( request, cluster_name, replacement_event, capacity) config_histories = clusters_helper.get_cluster_replacement_config_histories( request, cluster_name, replacement_id) return render(request, 'clusters/cluster_replace_details.html', { "replace": replacement_details, "config_histories": config_histories, "env": env })
def get(self, request, name, stage, hostname): host = environ_hosts_helper.get_host_by_env_and_hostname(request, name, stage, hostname) show_terminate = False if host and host.get('state') and host.get('state') != 'PENDING_TERMINATE' and host.get('state') != 'TERMINATING' and host.get('state') != 'TERMINATED': show_terminate = True basic_cluster_info = clusters_helper.get_cluster(request, name, stage) # TODO deprecated it asg = '' if host and host.get('groupName'): group_info = groups_helper.get_group_info(request, host.get('groupName')) if group_info and group_info["asgStatus"] == "ENABLED": asg = host.get('groupName') # gather the env name and stage info agents = agents_helper.get_agents_by_host(request, hostname) agent_wrappers = [] for agent in agents: agent_wrapper = {} agent_wrapper["agent"] = agent envId = agent['envId'] agent_env = environs_helper.get(request, envId) agent_wrapper["env"] = agent_env agent_wrapper["error"] = "" if agent.get('lastErrno', 0) != 0: agent_wrapper["error"] = agents_helper.get_agent_error(request, agent_env['envName'], agent_env['stageName'], hostname) agent_wrappers.append(agent_wrapper) return render(request, 'hosts/host_details.html', { 'env_name': name, 'stage_name': stage, 'hostname': hostname, 'host': host, 'agent_wrappers': agent_wrappers, 'show_terminate': show_terminate, 'basic_cluster_info': basic_cluster_info, 'asg_group': asg, 'pinterest': IS_PINTEREST, })
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) cluster_provider = clusters_helper.get_cluster_provider( request, name, stage) if cluster_provider == 'null': cluster_provider = None basic_cluster_info = clusters_helper.get_cluster(request, name, stage) advanced_cluster_info = clusters_helper.get_advanced_cluster( request, name, stage, cluster_provider) return render( request, 'clusters/clusters.html', { 'env': env, 'stages': stages, 'provider_list': provider_list, 'cluster_provider': cluster_provider, 'basic_cluster_info': basic_cluster_info, 'advanced_cluster_info': advanced_cluster_info, })
def post(self, request, name, stage): query_dict = request.POST hosts_str = query_dict["hosts"] hosts = [] if hosts_str: hosts = [x.strip() for x in hosts_str.split(',')] environs_helper.update_env_capacity(request, name, stage, capacity_type="HOST", data=hosts) groups_str = query_dict["groups"] groups = [] if groups_str: groups = [x.strip() for x in groups_str.split(',')] basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if basic_cluster_info: cluster_name = '{}-{}'.format(name, stage) groups.append(cluster_name) environs_helper.update_env_capacity(request, name, stage, capacity_type="GROUP", data=groups) return self.get(request, name, stage)
def get_group_config(request, group_name): try: group_info = groups_helper.get_group_info(request, group_name) group_config = group_info.get("groupInfo") group_config = get_group_config_internal(group_config) is_cmp = False envs = environs_helper.get_all_envs_by_group(request, group_name) for env in envs: basic_cluster_info = clusters_helper.get_cluster(request, env.get('envName'), env.get('stageName')) if basic_cluster_info: is_cmp = True html = render_to_string('groups/group_config.tmpl', { "group_name": group_name, "config": group_config, "is_cmp": is_cmp, "csrf_token": get_token(request), }) except: log.error(traceback.format_exc()) raise return HttpResponse(json.dumps(html), content_type="application/json")
def get_group_config(request, group_name): try: group_info = autoscaling_groups_helper.get_group_info(request, group_name) group_config = group_info.get("groupInfo") group_config = get_group_config_internal(group_config) is_cmp = False envs = environs_helper.get_all_envs_by_group(request, group_name) for env in envs: basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName')) if basic_cluster_info: is_cmp = True html = render_to_string('groups/group_config.tmpl', { "group_name": group_name, "config": group_config, "is_cmp": is_cmp, "csrf_token": get_token(request), }) except: log.error(traceback.format_exc()) raise return HttpResponse(json.dumps(html), content_type="application/json")
def get(self, request, group_name): asg_cluster = autoscaling_groups_helper.get_group_info( request, group_name) appNames = baseimages_helper.get_image_names(request, 'AWS') appNames = sorted(appNames) is_cmp = False if asg_cluster: asg_vm_info = asg_cluster.get("launchInfo") curr_image = None if asg_vm_info: curr_image = baseimages_helper.get_by_provider_name( request, asg_vm_info["imageId"]) if asg_vm_info.get("subnets"): asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split( ',') group_info = asg_cluster.get("groupInfo") group_info = get_group_config_internal(group_info) envs = environs_helper.get_all_envs_by_group(request, group_name) for env in envs: basic_cluster_info = clusters_helper.get_cluster( request, env.get('clusterName')) if basic_cluster_info: is_cmp = True else: asg_vm_info = None group_info = None curr_image = None pas_config = autoscaling_groups_helper.get_pas_config( request, group_name) return render( request, 'groups/asg_config.html', { "asg_vm_config": asg_vm_info, "app_names": appNames, "curr_image": curr_image, "group_config": group_info, "group_name": group_name, "pas_config": pas_config, "is_cmp": is_cmp })
def get(self, request, name, stage): env = environs_helper.get_env_by_stage(request, name, stage) cluster_name = '{}-{}'.format(name, stage) page_index = request.GET.get('index') page_size = request.GET.get('size') histories = clusters_helper.get_cluster_replacement_histories( request, cluster_name, page_index, page_size) replace_summaries = [] if histories: basic_cluster_info = clusters_helper.get_cluster( request, cluster_name) capacity = basic_cluster_info.get("capacity") for history in histories: replace_summaries.append( get_replacement_summary(request, cluster_name, history, capacity)) data = {"env": env, "replace_summaries": replace_summaries} return render(request, 'clusters/replace_histories.html', data)
def cluster_replacement_progress(request, name, stage): env = environs_helper.get_env_by_stage(request, name, stage) cluster_name = '{}-{}'.format(name, stage) replacement_event = clusters_helper.get_latest_cluster_replacement_progress( request, cluster_name) if not replacement_event: log.info("There is no on-going replacement event for cluster %s." % cluster_name) return HttpResponse("There is no on-going replacement.") basic_cluster_info = clusters_helper.get_cluster(request, cluster_name) capacity = basic_cluster_info.get("capacity") replacement_progress = get_replacement_summary(request, cluster_name, replacement_event, capacity) html = render_to_string('clusters/replace_progress.tmpl', { "env": env, "replace_progress_report": replacement_progress }) response = HttpResponse(html) return response
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)})
def get(self, request, name, stage): if request.is_ajax(): env = environs_helper.get_env_by_stage(request, name, stage) html = render_to_string('configs/env_config.tmpl', { "env": env, "csrf_token": get_token(request), }) return HttpResponse(json.dumps({'html': html}), content_type="application/json") envs = environs_helper.get_all_env_stages(request, name) stages, env = common.get_all_stages(envs, stage) # get capacity to decide if we need to show the remove stage button show_remove = True # if people have already specified host capacity or group capacity but do not have cluster config # show capacity config page; otherwise, show cluster config page show_cluster_config = True hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST") if hosts: show_remove = False show_cluster_config = False else: groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") if groups: show_remove = False basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if not basic_cluster_info: show_cluster_config = False return render(request, 'configs/env_config.html', { "env": env, "stages": stages, "show_remove": show_remove, "show_cluster_config": show_cluster_config, "pinterest": IS_PINTEREST, })
def get(self, request, name, stage): env = environs_helper.get_env_by_stage(request, name, stage) cluster_name = '{}-{}'.format(name, stage) page_index = request.GET.get('index') page_size = request.GET.get('size') histories = clusters_helper.get_cluster_replacement_histories( request, cluster_name, page_index, page_size) replace_summaries = [] if histories: basic_cluster_info = clusters_helper.get_cluster( request, cluster_name) capacity = basic_cluster_info.get("capacity") for history in histories: replace_summaries.append(get_replacement_summary( request, cluster_name, history, capacity)) data = { "env": env, "replace_summaries": replace_summaries } return render(request, 'clusters/replace_histories.html', data)
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, })
def get(self, request, name, stage=None): envs = environs_helper.get_all_env_stages(request, name) if len(envs) == 0: return redirect('/') stages, env = common.get_all_stages(envs, stage) env_promote = environs_helper.get_env_promotes_config( request, name, env['stageName']) stage = env['stageName'] username = request.teletraan_user_id.name request_feedback = check_feedback_eligible(request, username) groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") metrics = environs_helper.get_env_metrics_config(request, name, stage) alarms = environs_helper.get_env_alarms_config(request, name, stage) basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if not env['deployId']: capacity_hosts = deploys_helper.get_missing_hosts( request, name, stage) provisioning_hosts = environ_hosts_helper.get_hosts( request, name, stage) response = render( request, 'environs/env_landing.html', { "env": env, "env_promote": env_promote, "stages": stages, "metrics": metrics, "alarms": alarms, "request_feedback": request_feedback, "groups": groups, "capacity_hosts": capacity_hosts, "provisioning_hosts": provisioning_hosts, "basic_cluster_info": basic_cluster_info, "pinterest": IS_PINTEREST, }) showMode = 'complete' sortByStatus = 'true' else: # Get deploy progress progress = deploys_helper.update_progress(request, name, stage) showMode = _fetch_param_with_cookie(request, 'showMode', MODE_COOKIE_NAME, 'complete') sortByStatus = _fetch_param_with_cookie(request, 'sortByStatus', STATUS_COOKIE_NAME, 'true') report = agent_report.gen_report(request, env, progress, sortByStatus=sortByStatus) report.showMode = showMode report.sortByStatus = sortByStatus response = render( request, 'environs/env_landing.html', { "env": env, "env_promote": env_promote, "stages": stages, "report": report, "has_deploy": True, "metrics": metrics, "alarms": alarms, "request_feedback": request_feedback, "groups": groups, "basic_cluster_info": basic_cluster_info, "pinterest": IS_PINTEREST, }) # save preferences response.set_cookie(ENV_COOKIE_NAME, genEnvCookie(request, name)) response.set_cookie(MODE_COOKIE_NAME, showMode) response.set_cookie(STATUS_COOKIE_NAME, sortByStatus) return response
def clone_cluster(request, src_name, src_stage): try: params = request.POST dest_name = params.get('new_environment', src_name) dest_stage = params.get('new_stage', src_stage + '_clone') src_cluster_name = '{}-{}'.format(src_name, src_stage) dest_cluster_name = '{}-{}'.format(dest_name, dest_stage) ##0. teletraan service get src env buildName src_env = environs_helper.get_env_by_stage(request, src_name, src_stage) build_name = src_env.get('buildName', None) ##1. teletraan service create a new env dest_env = environs_helper.create_env(request, { 'envName': dest_name, 'stageName': dest_stage, 'buildName': build_name }) log.info('clone_cluster, created a new env %s' % dest_env) ##2. rodimus service get src_cluster config src_cluster_info = clusters_helper.get_cluster(request, src_cluster_name) log.info('clone_cluster, src cluster info %s' % src_cluster_info) configs = src_cluster_info.get('configs') if configs: cmp_group = configs.get('cmp_group') if cmp_group: cmp_groups_set = set(cmp_group.split(',')) cmp_groups_set.remove(src_cluster_name) cmp_groups_set.remove('CMP') cmp_groups_set.add(dest_cluster_name) # CMP needs to be the first in the list configs['cmp_group'] = ','.join(['CMP'] + list(cmp_groups_set)) src_cluster_info['configs'] = configs ##3. rodimus service post create cluster src_cluster_info['clusterName'] = dest_cluster_name src_cluster_info['capacity'] = 0 log.info('clone_cluster, request clone cluster info %s' % src_cluster_info) dest_cluster_info = clusters_helper.create_cluster(request, dest_cluster_name, src_cluster_info) log.info('clone_cluster, cloned cluster info %s' % dest_cluster_info) ##4. teletraan service update_env_basic_config environs_helper.update_env_basic_config(request, dest_name, dest_stage, data={"clusterName": dest_cluster_name} ) ##5. teletraan service set up env and group relationship environs_helper.update_env_capacity(request, dest_name, dest_stage, capacity_type="GROUP", data=[dest_cluster_name]) ##6. get src script_config src_script_configs = environs_helper.get_env_script_config(request, src_name, src_stage) src_agent_configs = environs_helper.get_env_agent_config(request, src_name, src_stage) src_alarms_configs = environs_helper.get_env_alarms_config(request, src_name, src_stage) src_metrics_configs = environs_helper.get_env_metrics_config(request, src_name, src_stage) src_webhooks_configs = environs_helper.get_env_hooks_config(request, src_name, src_stage) ##8. clone all the extra configs if src_agent_configs: environs_helper.update_env_agent_config(request, dest_name, dest_stage, src_agent_configs) if src_script_configs: environs_helper.update_env_script_config(request, dest_name, dest_stage, src_script_configs) if src_alarms_configs: environs_helper.update_env_alarms_config(request, dest_name, dest_stage, src_alarms_configs) if src_metrics_configs: environs_helper.update_env_metrics_config(request, dest_name, dest_stage, src_metrics_configs) if src_webhooks_configs: environs_helper.update_env_hooks_config(request, dest_name, dest_stage, src_webhooks_configs) return HttpResponse(json.dumps(src_cluster_info), content_type="application/json") 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("Failed to clone cluster env_name: %s, stage_name: %s" % (src_name, src_stage)) log.error(traceback.format_exc()) return HttpResponse(e, status=500, content_type="application/json")
def clone_cluster(request, src_name, src_stage): try: params = request.POST dest_name = params.get('new_environment', src_name) dest_stage = params.get('new_stage', src_stage + '_clone') src_cluster_name = '{}-{}'.format(src_name, src_stage) dest_cluster_name = '{}-{}'.format(dest_name, dest_stage) ##0. teletraan service get src env buildName src_env = environs_helper.get_env_by_stage(request, src_name, src_stage) build_name = src_env.get('buildName', None) external_id = src_env.get('externalId', None) ##1. teletraan service create a new env dest_env = environs_helper.create_env( request, { 'envName': dest_name, 'stageName': dest_stage, 'buildName': build_name, 'externalId': external_id }) log.info('clone_cluster, created a new env %s' % dest_env) ##2. rodimus service get src_cluster config src_cluster_info = clusters_helper.get_cluster(request, src_cluster_name) log.info('clone_cluster, src cluster info %s' % src_cluster_info) configs = src_cluster_info.get('configs') if configs: cmp_group = configs.get('cmp_group') if cmp_group: cmp_groups_set = set(cmp_group.split(',')) cmp_groups_set.remove(src_cluster_name) cmp_groups_set.remove('CMP') cmp_groups_set.add(dest_cluster_name) # CMP needs to be the first in the list configs['cmp_group'] = ','.join(['CMP'] + list(cmp_groups_set)) src_cluster_info['configs'] = configs ##3. rodimus service post create cluster src_cluster_info['clusterName'] = dest_cluster_name src_cluster_info['capacity'] = 0 log.info('clone_cluster, request clone cluster info %s' % src_cluster_info) dest_cluster_info = clusters_helper.create_cluster_with_env( request, dest_cluster_name, dest_name, dest_stage, src_cluster_info) log.info('clone_cluster, cloned cluster info %s' % dest_cluster_info) ##4. teletraan service update_env_basic_config environs_helper.update_env_basic_config( request, dest_name, dest_stage, data={"clusterName": dest_cluster_name}) ##5. teletraan service set up env and group relationship environs_helper.update_env_capacity(request, dest_name, dest_stage, capacity_type="GROUP", data=[dest_cluster_name]) ##6. get src script_config src_script_configs = environs_helper.get_env_script_config( request, src_name, src_stage) src_agent_configs = environs_helper.get_env_agent_config( request, src_name, src_stage) src_alarms_configs = environs_helper.get_env_alarms_config( request, src_name, src_stage) src_metrics_configs = environs_helper.get_env_metrics_config( request, src_name, src_stage) src_webhooks_configs = environs_helper.get_env_hooks_config( request, src_name, src_stage) ##8. clone all the extra configs if src_agent_configs: environs_helper.update_env_agent_config(request, dest_name, dest_stage, src_agent_configs) if src_script_configs: environs_helper.update_env_script_config(request, dest_name, dest_stage, src_script_configs) if src_alarms_configs: environs_helper.update_env_alarms_config(request, dest_name, dest_stage, src_alarms_configs) if src_metrics_configs: environs_helper.update_env_metrics_config(request, dest_name, dest_stage, src_metrics_configs) if src_webhooks_configs: environs_helper.update_env_hooks_config(request, dest_name, dest_stage, src_webhooks_configs) return HttpResponse(json.dumps(src_cluster_info), content_type="application/json") 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("Failed to clone cluster env_name: %s, stage_name: %s" % (src_name, src_stage)) log.error(traceback.format_exc()) return HttpResponse(e, status=500, content_type="application/json")
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)
def get(self, request, name, stage=None): envs = environs_helper.get_all_env_stages(request, name) if len(envs) == 0: return redirect('/') stages, env = common.get_all_stages(envs, stage) env_promote = environs_helper.get_env_promotes_config(request, name, env['stageName']) stage = env['stageName'] username = request.teletraan_user_id.name request_feedback = check_feedback_eligible(request, username) groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP") metrics = environs_helper.get_env_metrics_config(request, name, stage) alarms = environs_helper.get_env_alarms_config(request, name, stage) basic_cluster_info = None if IS_PINTEREST: basic_cluster_info = clusters_helper.get_cluster(request, name, stage) if not env['deployId']: capacity_hosts = deploys_helper.get_missing_hosts(request, name, stage) provisioning_hosts = environ_hosts_helper.get_hosts(request, name, stage) if IS_PINTEREST: basic_cluster_info = clusters_helper.get_cluster(request, env['envName'], env['stageName']) if basic_cluster_info and basic_cluster_info.get('capacity'): hosts_in_cluster = clusters_helper.get_host_names(request, env['envName'], env['stageName']) num_to_fake = basic_cluster_info.get('capacity') - len(hosts_in_cluster) for i in range(num_to_fake): faked_host = {} faked_host['hostName'] = 'UNKNOWN' faked_host['hostId'] = 'UNKNOWN' faked_host['state'] = 'PROVISIONED' provisioning_hosts.append(faked_host) response = render(request, 'environs/env_landing.html', { "env": env, "env_promote": env_promote, "stages": stages, "metrics": metrics, "alarms": alarms, "request_feedback": request_feedback, "groups": groups, "capacity_hosts": capacity_hosts, "provisioning_hosts": provisioning_hosts, "basic_cluster_info": basic_cluster_info, "pinterest": IS_PINTEREST, }) showMode = 'complete' sortByStatus = 'true' else: # Get deploy progress progress = deploys_helper.update_progress(request, name, stage) showMode = _fetch_param_with_cookie( request, 'showMode', MODE_COOKIE_NAME, 'complete') sortByStatus = _fetch_param_with_cookie( request, 'sortByStatus', STATUS_COOKIE_NAME, 'true') report = agent_report.gen_report(request, env, progress, sortByStatus=sortByStatus) report.showMode = showMode report.sortByStatus = sortByStatus response = render(request, 'environs/env_landing.html', { "env": env, "env_promote": env_promote, "stages": stages, "report": report, "has_deploy": True, "metrics": metrics, "alarms": alarms, "request_feedback": request_feedback, "groups": groups, "basic_cluster_info": basic_cluster_info, "pinterest": IS_PINTEREST, }) # save preferences response.set_cookie(ENV_COOKIE_NAME, genEnvCookie(request, name)) response.set_cookie(MODE_COOKIE_NAME, showMode) response.set_cookie(STATUS_COOKIE_NAME, sortByStatus) return response
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)