Example #1
0
def make_advanced_bunch(variant_args, template_name, cc_params):
    extra_templates = [
        'aws/dcos-config.yaml',
        'aws/templates/advanced/{}'.format(template_name)
    ]
    if cc_params['os_type'] == 'coreos':
        extra_templates += ['coreos-aws/cloud-config.yaml', 'coreos/cloud-config.yaml']
        cloud_init_implementation = 'coreos'
    elif cc_params['os_type'] == 'el7':
        cloud_init_implementation = 'canonical'
    else:
        raise RuntimeError('Unsupported os_type: {}'.format(cc_params['os_type']))

    cc_package_files = [
        '/etc/cfn_signal_metadata',
        '/etc/adminrouter.env',
        '/etc/dns_config',
        '/etc/exhibitor',
        '/etc/mesos-master-provider']

    if cc_params['node_type'] == 'master':
        cc_package_files.append('/etc/aws_dnsnames')

    results = gen.generate(
        arguments=variant_args,
        extra_templates=extra_templates,
        cc_package_files=cc_package_files)

    cloud_config = results.templates['cloud-config.yaml']

    # Add general services
    cloud_config = results.utils.add_services(cloud_config, cloud_init_implementation)

    cc_variant = deepcopy(cloud_config)
    cc_variant = results.utils.add_units(
        cc_variant,
        yaml.load(gen.template.parse_str(late_services).render(cc_params)),
        cloud_init_implementation)

    # Add roles
    cc_variant = results.utils.add_roles(cc_variant, cc_params['roles'] + ['aws'])

    # NOTE: If this gets printed in string stylerather than '|' the AWS
    # parameters which need to be split out for the cloudformation to
    # interpret end up all escaped and undoing it would be hard.
    variant_cloudconfig = results.utils.render_cloudconfig(cc_variant)

    # Render the cloudformation
    cloudformation = render_cloudformation(
        results.templates[template_name],
        cloud_config=variant_cloudconfig)
    print("Validating CloudFormation: {}".format(template_name))
    validate_cf(cloudformation)

    return gen.Bunch({
        'cloudformation': cloudformation,
        'results': results
    })
Example #2
0
File: aws.py Project: zhe-sun/dcos
def gen_advanced_template(arguments, variant_prefix, channel_commit_path,
                          os_type):
    for node_type in ['master', 'priv-agent', 'pub-agent']:
        node_template_id, node_args = groups[node_type]
        node_args = deepcopy(node_args)
        node_args.update(arguments)
        node_args['os_type'] = os_type
        params = deepcopy(cf_instance_groups[node_template_id])
        params['report_name'] = node_args.pop('report_name')
        params['os_type'] = os_type
        params['node_type'] = node_type
        template_key = 'advanced-{}'.format(node_type)
        template_name = template_key + '.json'
        if node_type == 'master':
            for num_masters in [1, 3, 5, 7]:
                master_tk = '{}-{}-{}'.format(os_type, template_key,
                                              num_masters)
                print('Building {} {} for num_masters = {}'.format(
                    os_type, node_type, num_masters))
                node_args['num_masters'] = str(num_masters)
                bunch = make_advanced_bunch(node_args, template_name, params)
                yield '{}.json'.format(master_tk), bunch

                # Zen template corresponding to this number of masters
                yield '{}-zen-{}.json'.format(
                    os_type, num_masters
                ), gen.Bunch({
                    'cloudformation':
                    render_cloudformation_transform(
                        resource_string(
                            "gen", "aws/templates/advanced/zen.json").decode(),
                        variant_prefix=variant_prefix,
                        channel_commit_path=channel_commit_path,
                        cloudformation_s3_url=get_cloudformation_s3_url(),
                        **bunch.results.arguments),
                    # TODO(cmaloney): This is hacky but quickest for now. Should not have to add
                    # extra info that there are no cluster_packages
                    'results':
                    gen.Bunch({'cluster_packages': {}})
                })
        else:
            node_args['num_masters'] = "1"
            bunch = make_advanced_bunch(node_args, template_name, params)
            yield '{}-{}'.format(os_type, template_name), bunch
Example #3
0
def gen_templates(arguments):
    results = gen.generate(
        arguments=arguments,
        extra_templates=[
            'aws/templates/cloudformation.json',
            'aws/dcos-config.yaml',
            'coreos-aws/cloud-config.yaml',
            'coreos/cloud-config.yaml'],
        cc_package_files=[
            '/etc/cfn_signal_metadata',
            '/etc/adminrouter.env',
            '/etc/ui-config.json',
            '/etc/dns_config',
            '/etc/exhibitor',
            '/etc/mesos-master-provider'])

    cloud_config = results.templates['cloud-config.yaml']

    # Add general services
    cloud_config = results.utils.add_services(cloud_config, 'coreos')

    # Specialize for master, slave, slave_public
    variant_cloudconfig = {}
    for variant, params in cf_instance_groups.items():
        cc_variant = deepcopy(cloud_config)

        # Specialize the dcos-cfn-signal service
        cc_variant = results.utils.add_units(
            cc_variant,
            yaml.load(gen.template.parse_str(late_services).render(params)))

        # Add roles
        cc_variant = results.utils.add_roles(cc_variant, params['roles'] + ['aws'])

        # NOTE: If this gets printed in string stylerather than '|' the AWS
        # parameters which need to be split out for the cloudformation to
        # interpret end up all escaped and undoing it would be hard.
        variant_cloudconfig[variant] = results.utils.render_cloudconfig(cc_variant)

    # Render the cloudformation
    cloudformation = render_cloudformation(
        results.templates['cloudformation.json'],
        master_cloud_config=variant_cloudconfig['master'],
        slave_cloud_config=variant_cloudconfig['slave'],
        slave_public_cloud_config=variant_cloudconfig['slave_public']
        )

    print("Validating CloudFormation")
    validate_cf(cloudformation)

    return gen.Bunch({
        'cloudformation': cloudformation,
        'results': results
    })
Example #4
0
File: azure.py Project: zouyee/dcos
def gen_templates(user_args, arm_template):
    '''
    Render the cloud_config template given a particular set of options

    @param user_args: dict, args to pass to the gen library. These are user
                     input arguments which get filled in/prompted for.
    @param arm_template: string, path to the source arm template for rendering
                         by the gen library (e.g. 'azure/templates/azuredeploy.json')
    '''
    results = gen.generate(
        arguments=user_args,
        extra_templates=['azure/cloud-config.yaml', 'azure/templates/' + arm_template + '.json'],
        cc_package_files=[
            '/etc/exhibitor',
            '/etc/exhibitor.properties',
            '/etc/adminrouter.env',
            '/etc/ui-config.json',
            '/etc/mesos-master-provider',
            '/etc/master_list'])

    cloud_config = results.templates['cloud-config.yaml']

    # Add general services
    cloud_config = results.utils.add_services(cloud_config, 'canonical')

    # Specialize for master, slave, slave_public
    variant_cloudconfig = {}
    for variant, params in INSTANCE_GROUPS.items():
        cc_variant = deepcopy(cloud_config)

        # TODO(cmaloney): Add the dcos-arm-signal service here
        # cc_variant = results.utils.add_units(
        #     cc_variant,
        #     yaml.load(gen.template.parse_str(late_services).render(params)))

        # Add roles
        cc_variant = results.utils.add_roles(cc_variant, params['roles'] + ['azure'])

        # NOTE: If this gets printed in string stylerather than '|' the Azure
        # parameters which need to be split out for the arm to
        # interpret end up all escaped and undoing it would be hard.
        variant_cloudconfig[variant] = results.utils.render_cloudconfig(cc_variant)

    # Render the arm
    arm = render_arm(
        results.templates[arm_template + '.json'],
        variant_cloudconfig['master'],
        variant_cloudconfig['slave'],
        variant_cloudconfig['slave_public'])

    return gen.Bunch({
        'arm': arm,
        'results': results
    })
Example #5
0
def gen_supporting_template():
    for template_key in ['infra.json']:
        cf_template = 'aws/templates/advanced/{}'.format(template_key)
        cloudformation = render_cloudformation(resource_string("gen", cf_template).decode())

        print("Validating CloudFormation: {}".format(cf_template))
        validate_cf(cloudformation)

        yield template_key, gen.Bunch({
            'cloudformation': cloudformation,
            'results': '',
        })
Example #6
0
def make_advanced_bunch(variant_args, template_name, cc_params):
    results = gen.generate(
        arguments=variant_args,
        extra_templates=extra_templates + ['aws/templates/advanced/' + template_name],
        cc_package_files=[
            '/etc/cfn_signal_metadata',
            '/etc/dns_config',
            '/etc/exhibitor',
            '/etc/mesos-master-provider'])

    cloud_config = results.templates['cloud-config.yaml']

    # Add general services
    cloud_config = results.utils.add_services(cloud_config)

    cc_variant = deepcopy(cloud_config)
    cc_variant = results.utils.add_units(
        cc_variant,
        yaml.load(gen.template.parse_str(late_services).render(cc_params)))

    # Add roles
    cc_variant = results.utils.add_roles(cc_variant, cc_params['roles'] + ['aws'])

    # NOTE: If this gets printed in string stylerather than '|' the AWS
    # parameters which need to be split out for the cloudformation to
    # interpret end up all escaped and undoing it would be hard.
    variant_cloudconfig = results.utils.render_cloudconfig(cc_variant)

    # Render the cloudformation
    cloudformation = render_cloudformation(
        results.templates[template_name],
        cloud_config=variant_cloudconfig,
        )
    print("Validating CloudFormation: {}".format(template_name))
    validate_cf(cloudformation)

    return gen.Bunch({
        'cloudformation': cloudformation,
        'results': results
    })