Exemplo n.º 1
0
 def post(self, request, name, stage):
     configs = self.parse_configs(request.POST)
     flavor = request.POST.get('flavor', 'AC')
     if flavor == AC_FLAVOR:
         environs_helper.update_env_agent_config(request,
                                                 name,
                                                 stage,
                                                 data=configs)
         configs = environs_helper.get_env_agent_config(
             request, name, stage)
     else:
         environs_helper.update_env_script_config(request,
                                                  name,
                                                  stage,
                                                  data=configs)
         configs = environs_helper.get_env_script_config(
             request, name, stage)
     env = environs_helper.get_env_by_stage(request, name, stage)
     html = render_to_string(
         'configs/config_map.tmpl', {
             "env": env,
             "configs": configs,
             "customization": CUSTOMIZATION[flavor],
             "csrf_token": get_token(request),
         })
     return HttpResponse(json.dumps({'html': html}),
                         content_type="application/json")
Exemplo n.º 2
0
    def get(self, request, name, stage):
        flavor = request.GET.get('flavor', 'AC')
        if flavor == AC_FLAVOR:
            configs = environs_helper.get_env_agent_config(
                request, name, stage)
        else:
            configs = environs_helper.get_env_script_config(
                request, name, stage)
        if request.is_ajax():
            # return data for ajax calls
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string(
                'configs/config_map.tmpl', {
                    "env": env,
                    "configs": configs,
                    "customization": CUSTOMIZATION[flavor],
                    "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)
        return render(
            request, 'configs/config_map.html', {
                "env": env,
                "stages": stages,
                "configs": configs,
                "customization": CUSTOMIZATION[flavor],
            })
Exemplo n.º 3
0
def clone_from_stage_name(request, env_name, stage_name, from_env_name,
                          from_stage_name, description):
    from_stage = environs_helper.get_env_by_stage(request, from_env_name,
                                                  from_stage_name)
    agent_configs = environs_helper.get_env_agent_config(
        request, from_env_name, from_stage_name)
    script_configs = environs_helper.get_env_script_config(
        request, from_env_name, from_stage_name)
    alarms_configs = environs_helper.get_env_alarms_config(
        request, from_env_name, from_stage_name)
    metrics_configs = environs_helper.get_env_metrics_config(
        request, from_env_name, from_stage_name)
    webhooks_configs = environs_helper.get_env_hooks_config(
        request, from_env_name, from_stage_name)
    promotes_configs = environs_helper.get_env_promotes_config(
        request, from_env_name, from_stage_name)

    new_data = {}
    new_data['envName'] = env_name
    new_data['stageName'] = stage_name
    new_data['description'] = description
    new_data['buildName'] = from_stage['buildName']
    new_data['branch'] = from_stage['branch']
    new_data['chatroom'] = from_stage['chatroom']
    new_data['maxParallel'] = from_stage['maxParallel']
    new_data['priority'] = from_stage['priority']
    new_data['stuckThreshold'] = from_stage['stuckThreshold']
    new_data['successThreshold'] = from_stage['successThreshold']
    new_data['acceptanceType'] = from_stage['acceptanceType']
    new_data['emailRecipients'] = from_stage['emailRecipients']
    new_data['notifyAuthors'] = from_stage['notifyAuthors']
    new_data['watchRecipients'] = from_stage['watchRecipients']
    new_data['maxDeployNum'] = from_stage['maxDeployNum']
    new_data['maxDeployDay'] = from_stage['maxDeployDay']
    new_data['overridePolicy'] = from_stage['overridePolicy']

    new_stage = environs_helper.create_env(request, new_data)

    # now clone all the extra configs
    if agent_configs:
        environs_helper.update_env_agent_config(request, env_name, stage_name,
                                                agent_configs)
    if script_configs:
        environs_helper.update_env_script_config(request, env_name, stage_name,
                                                 script_configs)
    if alarms_configs:
        environs_helper.update_env_alarms_config(request, env_name, stage_name,
                                                 alarms_configs)
    if metrics_configs:
        environs_helper.update_env_metrics_config(request, env_name,
                                                  stage_name, metrics_configs)
    if webhooks_configs:
        environs_helper.update_env_hooks_config(request, env_name, stage_name,
                                                webhooks_configs)
    if promotes_configs:
        environs_helper.update_env_promotes_config(request, env_name,
                                                   stage_name,
                                                   promotes_configs)

    return new_stage
Exemplo n.º 4
0
    def get(self, request, name, stage):
        flavor = request.GET.get('flavor', 'AC')
        if flavor == AC_FLAVOR:
            configs = environs_helper.get_env_agent_config(request, name, stage)
        else:
            configs = environs_helper.get_env_script_config(request, name, stage)
        if request.is_ajax():
            # return data for ajax calls
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string('configs/config_map.tmpl', {
                "env": env,
                "configs": configs,
                "customization": CUSTOMIZATION[flavor],
                "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)
        return render(request, 'configs/config_map.html', {
            "envs": envs,
            "env": env,
            "stages": stages,
            "configs": configs,
            "customization": CUSTOMIZATION[flavor],
        })
Exemplo n.º 5
0
def clone_from_stage_name(request, env_name, stage_name, from_env_name, from_stage_name,
                          description, external_id):
    from_stage = environs_helper.get_env_by_stage(request, from_env_name, from_stage_name)
    agent_configs = environs_helper.get_env_agent_config(request, from_env_name, from_stage_name)
    script_configs = environs_helper.get_env_script_config(request, from_env_name, from_stage_name)
    alarms_configs = environs_helper.get_env_alarms_config(request, from_env_name, from_stage_name)
    metrics_configs = environs_helper.get_env_metrics_config(request, from_env_name,
                                                             from_stage_name)
    webhooks_configs = environs_helper.get_env_hooks_config(request, from_env_name, from_stage_name)
    promotes_configs = environs_helper.get_env_promotes_config(request, from_env_name,
                                                               from_stage_name)

    new_data = {}
    new_data['envName'] = env_name
    new_data['stageName'] = stage_name
    new_data['description'] = description
    new_data['buildName'] = from_stage['buildName']
    new_data['branch'] = from_stage['branch']
    new_data['chatroom'] = from_stage['chatroom']
    new_data['maxParallel'] = from_stage['maxParallel']
    new_data['priority'] = from_stage['priority']
    new_data['stuckThreshold'] = from_stage['stuckThreshold']
    new_data['successThreshold'] = from_stage['successThreshold']
    new_data['acceptanceType'] = from_stage['acceptanceType']
    new_data['emailRecipients'] = from_stage['emailRecipients']
    new_data['notifyAuthors'] = from_stage['notifyAuthors']
    new_data['watchRecipients'] = from_stage['watchRecipients']
    new_data['maxDeployNum'] = from_stage['maxDeployNum']
    new_data['maxDeployDay'] = from_stage['maxDeployDay']
    new_data['overridePolicy'] = from_stage['overridePolicy']
    new_data['externalId'] = external_id

    new_stage = environs_helper.create_env(request, new_data)

    # now clone all the extra configs
    if agent_configs:
        environs_helper.update_env_agent_config(request, env_name, stage_name, agent_configs)
    if script_configs:
        environs_helper.update_env_script_config(request, env_name, stage_name, script_configs)
    if alarms_configs:
        environs_helper.update_env_alarms_config(request, env_name, stage_name, alarms_configs)
    if metrics_configs:
        environs_helper.update_env_metrics_config(request, env_name, stage_name, metrics_configs)
    if webhooks_configs:
        environs_helper.update_env_hooks_config(request, env_name, stage_name, webhooks_configs)
    if promotes_configs:
        environs_helper.update_env_promotes_config(request, env_name, stage_name, promotes_configs)

    return new_stage
Exemplo n.º 6
0
 def post(self, request, name, stage):
     configs = self.parse_configs(request.POST)
     flavor = request.POST.get('flavor', 'AC')
     if flavor == AC_FLAVOR:
         environs_helper.update_env_agent_config(request, name, stage, data=configs)
         configs = environs_helper.get_env_agent_config(request, name, stage)
     else:
         environs_helper.update_env_script_config(request, name, stage, data=configs)
         configs = environs_helper.get_env_script_config(request, name, stage)
     env = environs_helper.get_env_by_stage(request, name, stage)
     html = render_to_string('configs/config_map.tmpl', {
         "env": env,
         "configs": configs,
         "customization": CUSTOMIZATION[flavor],
         "csrf_token": get_token(request),
     })
     return HttpResponse(json.dumps({'html': html}), 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")
Exemplo n.º 8
0
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")