Example #1
0
    def _validate_and_create_env(cls, name, spec):
        """Validated and create env and platforms DB records.

        Do NOT use this method directly. Call create() method instead.

        - Restore full name of plugin. If only platform name is specified
        plugin with name existing@<platform_name> is going to be used
        - Validates spec using standard plugin validation mechanism
        - Creates env and platforms DB records in DB

        :returns: dict that contains env record stored in DB
        """

        try:
            jsonschema.validate(spec, SPEC_SCHEMA)
        except jsonschema.ValidationError as err:
            raise exceptions.ManagerInvalidSpec(
                mgr="Env", spec=spec, errors=[str(err)])

        spec.pop("!version", None)
        config = spec.pop("!config", {})
        extras = spec.pop("!extras", {})
        description = spec.pop("!description", "")

        existing_platforms = {}
        for p_name, p_spec in spec.items():
            if "@" not in p_name:
                spec["existing@%s" % p_name] = p_spec
                spec.pop(p_name)

            platform_name = p_name.split("@")[1] if "@" in p_name else p_name
            if platform_name in existing_platforms:
                raise exceptions.ManagerInvalidSpec(
                    mgr="Env", spec=spec,
                    errors=["Using multiple plugins [%s, %s] with the same "
                            "platform in single Env is not supported: "
                            % (p_name, existing_platforms[platform_name])]
                )
            existing_platforms[platform_name] = p_name

        errors = []
        for p_name, p_spec in spec.items():
            errors.extend(platform.Platform.validate(p_name, {}, spec, p_spec))
        if errors:
            raise exceptions.ManagerInvalidSpec(
                mgr="Env", spec=spec, errors=errors)

        _platforms = []
        for p_name, p_spec in spec.items():
            _platforms.append({
                "status": platform.STATUS.INIT,
                "plugin_name": p_name,
                "plugin_spec": p_spec,
                "platform_name": p_name.split("@")[1]
            })

        return cls(db.env_create(name, STATUS.INIT, description, extras,
                                 config, spec, _platforms))
Example #2
0
    def _validate_and_create_env(cls, name, description, extras, spec):
        """Validated and create env and platforms DB records.

        Do NOT use this method directly. Call create() method instead.

        - Restore full name of plugin. If only platform name is specified
        plugin with name existing@<platform_name> is going to be used
        - Validates spec using standard plugin validation mechanism
        - Creates env and platforms DB records in DB

        :returns: dict that contains env record stored in DB
        """
        for p_name, p_spec in spec.items():
            if "@" not in p_name:
                spec["existing@%s" % p_name] = p_spec
                spec.pop(p_name)

        errors = []
        for p_name, p_spec in spec.items():
            errors.extend(platform.Platform.validate(p_name, {}, spec, p_spec))
        if errors:
            raise exceptions.ManagerInvalidSpec(mgr="Env",
                                                spec=spec,
                                                errors=errors)

        _platforms = []
        for p_name, p_spec in spec.items():
            _platforms.append({
                "status": platform.STATUS.INIT,
                "plugin_name": p_name,
                "plugin_spec": p_spec,
                "platform_name": p_name.split("@")[1]
            })

        return cls(
            db.env_create(name, STATUS.INIT, description, extras, spec,
                          _platforms))