Esempio n. 1
0
    def validate_template(self, context, template):
        """
        The validate_template method uses the stack parser to check
        the validity of a template.

        arg1 -> RPC context.
        arg3 -> Template of stack you want to create.
        arg4 -> Stack Input Params
        """
        logger.info('validate_template')
        if template is None:
            msg = _("No Template provided.")
            return webob.exc.HTTPBadRequest(explanation=msg)

        tmpl = parser.Template(template)
        resources = template.get('Resources', [])

        if not resources:
            return {'Error': 'At least one Resources member must be defined.'}

        for res in resources.values():
            if not res.get('Type'):
                return {'Error':
                        'Every Resources object must contain a Type member.'}

        def describe_param(p):
            description = {'NoEcho': p.no_echo() and 'true' or 'false',
                           'ParameterKey': p.name,
                           'Description': p.description()}
            if p.has_default():
                description['DefaultValue'] = p.default()

            return description

        params = parser.Parameters(None, tmpl).map(describe_param)

        result = {
            'Description': template.get('Description', ''),
            'Parameters': params.values(),
        }
        return result
Esempio n. 2
0
    def validate_template(self, context, template, params):
        """
        The validate_template method uses the stack parser to check
        the validity of a template.

        arg1 -> RPC context.
        arg3 -> Template of stack you want to create.
        arg4 -> Params passed from API.
        """
        auth.authenticate(context)

        logger.info('validate_template')
        if template is None:
            msg = _("No Template provided.")
            return webob.exc.HTTPBadRequest(explanation=msg)

        tmpl = parser.Template(template)
        resources = template.get('Resources', [])

        if not resources:
            return {'Error': 'At least one Resources member must be defined.'}

        for res in resources.values():
            if not res.get('Type'):
                return {'Error':
                        'Every Resources object must contain a Type member.'}

        parameters = []
        for param_key, param in template.get('Parameters', {}).items():
            parameters.append({
                'NoEcho': param.get('NoEcho', 'false'),
                'ParameterKey': param_key,
                'Description': param.get('Description', '')
            })

        result = {
            'Description': template.get('Description', ''),
            'Parameters': parameters,
        }
        return {'ValidateTemplateResult': result}
Esempio n. 3
0
    def validate_template(self, context, template):
        """
        The validate_template method uses the stack parser to check
        the validity of a template.

        arg1 -> RPC context.
        arg3 -> Template of stack you want to create.
        arg4 -> Stack Input Params
        """
        logger.info("validate_template")
        if template is None:
            msg = _("No Template provided.")
            return webob.exc.HTTPBadRequest(explanation=msg)

        tmpl = parser.Template(template)
        resources = template.get("Resources", [])

        if not resources:
            return {"Error": "At least one Resources member must be defined."}

        for res in resources.values():
            if not res.get("Type"):
                return {"Error": "Every Resources object must contain a Type member."}

        def describe_param(p):
            description = {
                "NoEcho": p.no_echo() and "true" or "false",
                "ParameterKey": p.name,
                "Description": p.description(),
            }
            if p.has_default():
                description["DefaultValue"] = p.default()

            return description

        params = parser.Parameters(None, tmpl).map(describe_param)

        result = {"Description": template.get("Description", ""), "Parameters": params.values()}
        return result