示例#1
0
文件: azure.py 项目: mjkam/dcos
def make_template(num_masters, gen_arguments, varietal, bootstrap_variant_prefix):
    '''
    Return a tuple: the generated template for num_masters and the artifact dict.

    @param num_masters: int, number of master nodes to embed in the generated template
    @param gen_arguments: dict, args to pass to the gen library. These are user
                          input arguments which get filled in/prompted for.
    @param varietal: string, indicate template varietal to build for either 'acs' or 'dcos'
    '''

    master_list_source = Source()
    master_list_source.add_must('master_list', Late(master_list_arm_json(num_masters, varietal)))
    master_list_source.add_must('num_masters', str(num_masters))

    if varietal == 'dcos':
        arm, results = gen_templates(
            gen_arguments,
            'azuredeploy',
            extra_sources=[master_list_source, azure_dcos_source])
    elif varietal == 'acs':
        arm, results = gen_templates(
            gen_arguments,
            'acs',
            extra_sources=[master_list_source, azure_acs_source])
    else:
        raise ValueError("Unknown Azure varietal specified")

    yield {'packages': results.config_package_ids}
    if results.late_package_id:
        yield {'packages': [results.late_package_id]}
    yield {
        'channel_path': 'azure/{}{}-{}master.azuredeploy.json'.format(bootstrap_variant_prefix, varietal, num_masters),
        'local_content': arm,
        'content_type': 'application/json; charset=utf-8'
    }
示例#2
0
文件: azure.py 项目: jibsonline/dcos
def make_template(num_masters, gen_arguments, varietal, bootstrap_variant_prefix):
    '''
    Return a tuple: the generated template for num_masters and the artifact dict.

    @param num_masters: int, number of master nodes to embed in the generated template
    @param gen_arguments: dict, args to pass to the gen library. These are user
                          input arguments which get filled in/prompted for.
    @param varietal: string, indicate template varietal to build for either 'acs' or 'dcos'
    '''

    master_list_source = Source()
    master_list_source.add_must('master_list', Late(master_list_arm_json(num_masters, varietal)))
    master_list_source.add_must('num_masters', str(num_masters))

    if varietal == 'dcos':
        arm, results = gen_templates(
            gen_arguments,
            'azuredeploy',
            extra_sources=[master_list_source, azure_dcos_source])
    elif varietal == 'acs':
        arm, results = gen_templates(
            gen_arguments,
            'acs',
            extra_sources=[master_list_source, azure_acs_source])
    else:
        raise ValueError("Unknown Azure varietal specified")

    yield {'packages': util.cluster_to_extra_packages(results.cluster_packages)}
    yield {
        'channel_path': 'azure/{}{}-{}master.azuredeploy.json'.format(bootstrap_variant_prefix, varietal, num_masters),
        'local_content': arm,
        'content_type': 'application/json; charset=utf-8'
    }
def test_resolve_late():
    test_late_source = Source()
    test_late_source.add_must('c', gen.internals.Late('c_str'))
    test_late_source.add_must('d_1_a', 'd_1_a_str')
    resolver = gen.internals.resolve_configuration([test_source, test_late_source], [get_test_target()])

    assert resolver.status_dict == {'status': 'ok'}
    assert resolver.late == {'c'}
示例#4
0
文件: aws.py 项目: malnick/dcos
 def make(num_masters, filename):
     num_masters_source = Source()
     num_masters_source.add_must('num_masters', str(num_masters))
     yield from gen_simple_template(
         variant_prefix,
         filename,
         variant_base_args,
         num_masters_source)
示例#5
0
 def make(num_masters, filename):
     num_masters_source = Source()
     num_masters_source.add_must('num_masters', str(num_masters))
     yield from gen_simple_template(
         variant_prefix,
         filename,
         variant_base_args,
         num_masters_source)
示例#6
0
def gen_advanced_template(arguments, variant_prefix,
                          reproducible_artifact_path, os_type):
    cloudformation_full_s3_url = get_s3_url_prefix(arguments,
                                                   reproducible_artifact_path)

    for node_type in ['master', 'priv-agent', 'pub-agent']:
        # TODO(cmaloney): This forcibly overwriting arguments might overwrite a user set argument
        # without noticing (such as exhibitor_storage_backend)
        node_template_id, node_source = groups[node_type]
        local_source = Source()
        local_source.add_must('os_type', os_type)
        local_source.add_must('region_to_ami_mapping',
                              gen_ami_mapping({"coreos", "el7"}))
        params = deepcopy(cf_instance_groups[node_template_id])
        params['report_name'] = aws_advanced_report_names[node_type]
        params['os_type'] = os_type
        params['node_type'] = node_type
        template_key = 'advanced-{}'.format(node_type)
        template_name = template_key + '.json'

        def _as_artifact(filename, gen_out):
            yield from _as_artifact_and_pkg(variant_prefix, filename, gen_out)

        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))
                num_masters_source = Source()
                num_masters_source.add_must('num_masters', str(num_masters))
                bunch = make_advanced_bunch(
                    arguments, [node_source, local_source, num_masters_source],
                    template_name, params)
                yield from _as_artifact('{}.json'.format(master_tk), bunch)

                # Zen template corresponding to this number of masters
                yield _as_cf_artifact(
                    '{}{}-zen-{}.json'.format(variant_prefix, os_type,
                                              num_masters),
                    render_cloudformation_transform(
                        resource_string(
                            "gen", "aws/templates/advanced/zen.json").decode(),
                        variant_prefix=variant_prefix,
                        reproducible_artifact_path=reproducible_artifact_path,
                        cloudformation_full_s3_url=cloudformation_full_s3_url,
                        **bunch.results.arguments))
        else:
            local_source.add_must('num_masters', '1')
            local_source.add_must('nat_ami_mapping',
                                  gen_ami_mapping({"natami"}))
            bunch = make_advanced_bunch(arguments, [node_source, local_source],
                                        template_name, params)
            yield from _as_artifact('{}-{}'.format(os_type, template_name),
                                    bunch)
示例#7
0
文件: aws.py 项目: lloesche/dcos
def gen_advanced_template(arguments, variant_prefix, reproducible_artifact_path, os_type):
    for node_type in ['master', 'priv-agent', 'pub-agent']:
        # TODO(cmaloney): This forcibly overwriting arguments might overwrite a user set argument

        # without noticing (such as exhibitor_storage_backend)
        node_template_id, node_source = groups[node_type]
        local_source = Source()
        local_source.add_must('os_type', os_type)
        local_source.add_must('region_to_ami_mapping', gen_ami_mapping({"coreos", "el7", "el7prereq"}))
        params = cf_instance_groups[node_template_id]
        params['report_name'] = aws_advanced_report_names[node_type]
        params['os_type'] = os_type
        params['node_type'] = node_type
        template_key = 'advanced-{}'.format(node_type)
        template_name = template_key + '.json'

        def _as_artifact(filename, bundle):
            yield from _as_artifact_and_pkg(variant_prefix, filename, bundle)

        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))
                num_masters_source = Source()
                num_masters_source.add_must('num_masters', str(num_masters))
                bundle = make_advanced_bundle(arguments,
                                              [node_source, local_source, num_masters_source],
                                              template_name,
                                              deepcopy(params))
                yield from _as_artifact('{}.json'.format(master_tk), bundle)

                # Zen template corresponding to this number of masters
                yield _as_cf_artifact(
                    '{}{}-zen-{}.json'.format(variant_prefix, os_type, num_masters),
                    render_cloudformation_transform(
                        resource_string("gen", "aws/templates/advanced/zen.json").decode(),
                        variant_prefix=variant_prefix,
                        reproducible_artifact_path=reproducible_artifact_path,
                        **bundle[1].arguments))
        else:
            local_source.add_must('num_masters', '1')
            local_source.add_must('nat_ami_mapping', gen_ami_mapping({"natami"}))
            bundle = make_advanced_bundle(arguments,
                                          [node_source, local_source],
                                          template_name,
                                          deepcopy(params))
            yield from _as_artifact('{}-{}'.format(os_type, template_name), bundle)
示例#8
0
def test_resolve_simple():

    test_source = Source({
        'validate': [validate_a],
        'default': {
            'a': 'a_str',
            'd': 'd_1',
        },
        'must': {
            'b': 'b_str'
        },
        'conditional': {
            'd': {
                'd_1': {
                    'must': {
                        'd_1_b': 'd_1_b_str'
                    }
                },
                'd_2': {
                    'must': {
                        'd_2_b': 'd_2_b_str'
                    }
                }
            }
        }
    })

    def get_test_target():
        return Target({'a', 'b', 'c'}, {
            'd':
            Scope(
                'd', {
                    'd_1': Target({'d_1_a', 'd_1_b'}),
                    'd_2': Target({'d_2_a', 'd_2_b'})
                })
        })

    test_user_source = Source(is_user=True)
    test_user_source.add_must('c', 'c_str')
    test_user_source.add_must('d_1_a', 'd_1_a_str')

    resolver = gen.internals.resolve_configuration(
        [test_source, test_user_source], [get_test_target()])
    print(resolver)
    assert resolver.status_dict == {'status': 'ok'}

    # Make sure having a unset variable results in a non-ok status
    test_partial_source = Source(is_user=True)
    test_partial_source.add_must('d_1_a', 'd_1_a_str')
    resolver = gen.internals.resolve_configuration(
        [test_source, test_partial_source], [get_test_target()])
    print(resolver)
    assert resolver.status_dict == {
        'status': 'errors',
        'errors': {},
        'unset': {'c'}
    }
示例#9
0
def test_resolve_simple():

    test_source = Source({
        'validate': [validate_a],
        'default': {
            'a': 'a_str',
            'd': 'd_1',
        },
        'must': {
            'b': 'b_str'
        },
        'conditional': {
            'd': {
                'd_1': {
                    'must': {
                        'd_1_b': 'd_1_b_str'
                    }
                },
                'd_2': {
                    'must': {
                        'd_2_b': 'd_2_b_str'
                    }
                }
            }
        }
    })

    def get_test_target():
        return Target(
            {'a', 'b', 'c'},
            {'d': Scope(
                'd', {
                    'd_1': Target({'d_1_a', 'd_1_b'}),
                    'd_2': Target({'d_2_a', 'd_2_b'})
                })})

    test_user_source = Source(is_user=True)
    test_user_source.add_must('c', 'c_str')
    test_user_source.add_must('d_1_a', 'd_1_a_str')

    resolver = gen.internals.resolve_configuration([test_source, test_user_source], [get_test_target()])
    print(resolver)
    assert resolver.status_dict == {'status': 'ok'}

    # Make sure having a unset variable results in a non-ok status
    test_partial_source = Source(is_user=True)
    test_partial_source.add_must('d_1_a', 'd_1_a_str')
    resolver = gen.internals.resolve_configuration([test_source, test_partial_source], [get_test_target()])
    print(resolver)
    assert resolver.status_dict == {'status': 'errors', 'errors': {}, 'unset': {'c'}}
def test_resolve_simple():

    test_user_source = Source(is_user=True)
    test_user_source.add_must('c', 'c_str')
    test_user_source.add_must('d_1_a', 'd_1_a_str')

    resolver = gen.internals.resolve_configuration([test_source, test_user_source], [get_test_target()])
    print(resolver)
    assert resolver.status_dict == {'status': 'ok'}

    # Make sure having a unset variable results in a non-ok status
    test_partial_source = Source(is_user=True)
    test_partial_source.add_must('d_1_a', 'd_1_a_str')
    resolver = gen.internals.resolve_configuration([test_source, test_partial_source], [get_test_target()])
    print(resolver)
    assert resolver.status_dict == {'status': 'errors', 'errors': {}, 'unset': {'c'}}