コード例 #1
0
ファイル: importer.py プロジェクト: GRSEB9S/scale
def _import_config(config_dict, validating=False):
    """Applies a previously exported configuration to the current system.

    This method only exists to decouple the import logic from the atomic transaction so that this method can be reused
    for validation without making any permanent changes.

    :param config_dict: A dictionary of configuration changes to import.
    :type config_dict: dict
    :param validating: Flag to determine if running a validate or commit transaction.
    :type validating: bool
    :returns: A list of warnings discovered during the import.
    :rtype: list[:class:`port.schema.ValidationWarning`]

    :raises :class:`port.schema.InvalidConfiguration`: If any part of the configuration violates the specification.
    """
    warnings = []

    # Validate the top-level configuration structure
    config = Configuration(config_dict)

    # Build a map of row-locked models to import
    # Note the locking order matters here and must be high-level to low-level
    recipe_type_map = None
    if config.recipe_types:
        recipe_type_map = _build_recipe_type_map(config.recipe_types)
    job_type_map = None
    if config.job_types:
        job_type_map = _build_job_type_map(config.job_types)
    error_map = None
    if config.errors:
        error_map = _build_error_map(config.errors)

    # Attempt to create/edit the models
    if error_map:
        for error_dict in config.errors:
            error = error_map.get(error_dict.get('name'))
            warnings.extend(_import_error(error_dict, error))
    if job_type_map:
        for job_type_dict in config.job_types:
            job_type_key = (job_type_dict.get('name'),
                            job_type_dict.get('version'))
            job_type = job_type_map.get(job_type_key)
            warnings.extend(
                _import_job_type(job_type_dict, job_type, validating))
    if recipe_type_map:
        for recipe_type_dict in config.recipe_types:
            recipe_type_key = (recipe_type_dict.get('name'),
                               recipe_type_dict.get('version'))
            recipe_type = recipe_type_map.get(recipe_type_key)
            warnings.extend(_import_recipe_type(recipe_type_dict, recipe_type))
    return warnings
コード例 #2
0
ファイル: exporter.py プロジェクト: mnjstwins/scale
def export_config(recipe_types=None, job_types=None, errors=None):
    recipe_types = recipe_types or []
    job_types = job_types or []
    errors = errors or []

    export_config = {
        'version':
        '1.0',
        'recipe_types': [
            serializers.ConfigurationRecipeTypeSerializer(r).data
            for r in recipe_types
        ],
        'job_types': [
            serializers.ConfigurationJobTypeSerializer(j).data
            for j in job_types
        ],
        'errors':
        [serializers.ConfigurationErrorSerializer(e).data for e in errors],
    }
    return Configuration(export_config)