<commit_before>import requests
import argparse
import json
import logging
import sys
import os
from jinja2 import Environment, FileSystemLoader


class SpinnakerELB:

    def __init__(self):
        self.curdir = os.path.dirname(os.path.realpath(__file__))
        self.templatedir = "{}/../../templates".format(self.curdir)
        jinjaenv = Environment(loader=FileSystemLoader(self.templatedir))
        self.elb_template = jinjaenv.get_template("elb_data_template.json")
        self.gate_url = "http://spinnaker.build.example.com:8084"
        self.header = {'Content-Type': 'application/json', 'Accept': '*/*'}

    def get_vpc_id(self, account):
        url = self.gate_url + "/vpcs"
        response = requests.get(url)
        if response.ok:
            for vpc in response.json():
                if vpc['name'] == 'vpc' and vpc['account'] == account:
                    return vpc['id']
        else:
            logging.error(response.text)
            sys.exit(1)

    def create_elb(self, json_data, app):
        url = self.gate_url + '/applications/%s/tasks' %app
        response = requests.post(url, data=json.dumps(json_data), headers=self.header)
        if response.ok:
            logging.info('%s ELB Created' % app)
            logging.info(response.text)
        else:
            logging.error('Error creating %s ELB:' %app)
            logging.error(response.text)

#python create_elb.py --app testapp --stack teststack --elb_type internal --env dev --health_protocol HTTP --health_port 80 --health_path /health --security_groups sg_apps --int_listener_port 80 --int_listener_protocol HTTP --ext_listener_port 8080 --ext_listener_protocol HTTP --elb_name dougtestapp-teststack --elb_subnet internal --health_timeout=10 --health_interval 2 --healthy_threshold 4 --unhealthy_threshold 6
if __name__ == '__main__':
    elb = SpinnakerELB()
    parser = argparse.ArgumentParser(description='Example with non-optional arguments')

    parser.add_argument('--app', action="store", help="application name", required=True)
    parser.add_argument('--stack', action="store", help="application stack", required=True)
    parser.add_argument('--elb_type', action="store", help="elb type: internal/external", required=True)
    parser.add_argument('--env', action="store", help="environment: dev, stage, prod", required=True)
    parser.add_argument('--health_protocol', action="store", help="health check protocol: http/tcp", required=True)
    parser.add_argument('--health_port', action="store", help="health check port", required=True)
    parser.add_argument('--health_path', action="store", help="health check path stack", required=False, default="/health")
    parser.add_argument('--health_timeout', action="store", help="health check timeout in seconds", required=True, default=10)
    parser.add_argument('--health_interval', action="store", help="health check interval in seconds", required=True, default=20)
    parser.add_argument('--healthy_threshold', action="store", help="healthy threshold", required=True, default=2)
    parser.add_argument('--unhealthy_threshold', action="store", help="unhealthy threshold", required=True, default=5)
    parser.add_argument('--security_groups', action="store", help="security groups", required=True, default="sg_apps", nargs="+")
    parser.add_argument('--int_listener_port', action="store", help="internal listener port", required=True, default=8080)
    parser.add_argument('--int_listener_protocol', action="store", help="internal listener protocol", required=True, default="HTTP")
    parser.add_argument('--ext_listener_port', action="store", help="internal listener port", required=True, default=80)
    parser.add_argument('--ext_listener_protocol', action="store", help="external listener protocol", required=True, default="HTTP")
    parser.add_argument('--elb_name', action="store", help="elb name", required=True)
    parser.add_argument('--elb_subnet', action="store", help="elb subnet", required=True, default="internal")
    args = parser.parse_args()
    template = elb.elb_template.render(app_stack=args.stack,
                                            app_name=args.app,
                                            env=args.env,
                                            isInternal='true' if args.elb_type == 'internal' else 'false',
                                            vpc_id=elb.get_vpc_id(args.env),
                                            health_protocol=args.health_protocol,
                                            health_port=args.health_port,
                                            health_path=args.health_path,
                                            health_timeout=args.health_timeout,
                                            health_interval=args.health_interval,
                                            unhealthy_threshold=args.unhealthy_threshold,
                                            healthy_threshold=args.healthy_threshold,
                                            security_groups=args.security_groups[0],
                                            int_listener_protocol=args.int_listener_protocol,
                                            ext_listener_protocol=args.ext_listener_protocol,
                                            int_listener_port=args.int_listener_port,
                                            ext_listener_port=args.ext_listener_port,
                                            elb_name=args.elb_name,
                                            subnet_type=args.elb_subnet,
                                            elb_subnet=args.elb_subnet,
                                            hc_string=args.int_listener_protocol+':'+str(args.int_listener_port)+args.health_path)

    rendered_json = json.loads(template)
    logging.info(rendered_json)
    elb.create_elb(rendered_json, args.app)




<commit_msg>logging and sync-up<commit_after>import requests
import argparse
import json
import logging
import sys
import os
from jinja2 import Environment, FileSystemLoader


class SpinnakerELB:

    def __init__(self):
        self.curdir = os.path.dirname(os.path.realpath(__file__))
        self.templatedir = "{}/../../templates".format(self.curdir)
        jinjaenv = Environment(loader=FileSystemLoader(self.templatedir))
        self.elb_template = jinjaenv.get_template("elb_data_template.json")
        self.gate_url = "http://spinnaker.build.example.com:8084"
        self.header = {'Content-Type': 'application/json', 'Accept': '*/*'}

    def get_vpc_id(self, account):
        url = self.gate_url + "/vpcs"
        response = requests.get(url)
        if response.ok:
            for vpc in response.json():
                if vpc['name'] == 'vpc' and vpc['account'] == account:
                    return vpc['id']
        else:
            logging.error(response.text)
            sys.exit(1)

    def create_elb(self, json_data, app):
        url = self.gate_url + '/applications/%s/tasks' %app
        response = requests.post(url, data=json.dumps(json_data), headers=self.header)
        if response.ok:
            logging.info('%s ELB Created' % app)
            logging.info(response.text)
            print(response.text)
        else:
            logging.error('Error creating %s ELB:' %app)
            logging.error(response.text)
            print(response.text)

#python create_elb.py --app testapp --stack teststack --elb_type internal --env dev --health_protocol HTTP --health_port 80 --health_path /health --security_groups sg_apps --int_listener_port 80 --int_listener_protocol HTTP --ext_listener_port 8080 --ext_listener_protocol HTTP --elb_name dougtestapp-teststack --elb_subnet internal --health_timeout=10 --health_interval 2 --healthy_threshold 4 --unhealthy_threshold 6
if __name__ == '__main__':
    elb = SpinnakerELB()
    parser = argparse.ArgumentParser(description='Example with non-optional arguments')

    parser.add_argument('--app', action="store", help="application name", required=True)
    parser.add_argument('--stack', action="store", help="application stack", required=True)
    parser.add_argument('--elb_type', action="store", help="elb type: internal/external", required=True)
    parser.add_argument('--env', action="store", help="environment: dev, stage, prod", required=True)
    parser.add_argument('--health_protocol', action="store", help="health check protocol: http/tcp", required=True)
    parser.add_argument('--health_port', action="store", help="health check port", required=True)
    parser.add_argument('--health_path', action="store", help="health check path stack", required=False, default="/health")
    parser.add_argument('--health_timeout', action="store", help="health check timeout in seconds", required=True, default=10)
    parser.add_argument('--health_interval', action="store", help="health check interval in seconds", required=True, default=20)
    parser.add_argument('--healthy_threshold', action="store", help="healthy threshold", required=True, default=2)
    parser.add_argument('--unhealthy_threshold', action="store", help="unhealthy threshold", required=True, default=5)
    parser.add_argument('--security_groups', action="store", help="security groups", required=True, default="sg_apps", nargs="+")
    parser.add_argument('--int_listener_port', action="store", help="internal listener port", required=True, default=8080)
    parser.add_argument('--int_listener_protocol', action="store", help="internal listener protocol", required=True, default="HTTP")
    parser.add_argument('--ext_listener_port', action="store", help="internal listener port", required=True, default=80)
    parser.add_argument('--ext_listener_protocol', action="store", help="external listener protocol", required=True, default="HTTP")
    parser.add_argument('--elb_name', action="store", help="elb name", required=True)
    parser.add_argument('--elb_subnet', action="store", help="elb subnet", required=True, default="internal")
    args = parser.parse_args()
    template = elb.elb_template.render(app_stack=args.stack,
                                            app_name=args.app,
                                            env=args.env,
                                            isInternal='true' if args.elb_type == 'internal' else 'false',
                                            vpc_id=elb.get_vpc_id(args.env),
                                            health_protocol=args.health_protocol,
                                            health_port=args.health_port,
                                            health_path=args.health_path,
                                            health_timeout=args.health_timeout,
                                            health_interval=args.health_interval,
                                            unhealthy_threshold=args.unhealthy_threshold,
                                            healthy_threshold=args.healthy_threshold,
                                            security_groups=args.security_groups[0],
                                            int_listener_protocol=args.int_listener_protocol,
                                            ext_listener_protocol=args.ext_listener_protocol,
                                            int_listener_port=args.int_listener_port,
                                            ext_listener_port=args.ext_listener_port,
                                            elb_name=args.elb_name,
                                            subnet_type=args.elb_subnet,
                                            elb_subnet=args.elb_subnet,
                                            hc_string=args.int_listener_protocol+':'+str(args.int_listener_port)+args.health_path)

    rendered_json = json.loads(template)
    print(rendered_json)
    logging.info(rendered_json)
    print(elb.create_elb(rendered_json, args.app))






{'fraction_non_alphanumeric': 0.11778058007566204, 'fraction_numerical': 0.005380411937788987, 'mean_word_length': 2.408595988538682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 80, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1744206', 'n_tokens_mistral': 3121, 'n_tokens_neox': 3030, 'n_words': 579}