'Implements the ValidateTemplate API action.
Validates the specified template.'

def validate_template(self, req):

    self._enforce(req, 'ValidateTemplate')
    con = req.context
    try:
        templ = self._get_template(req)
    except socket.gaierror:
        msg = _('Invalid    Template    URL')
        return exception.HeatInvalidParameterValueError(detail=msg)
    if (templ is None):
        msg = _('TemplateBody    or    TemplateUrl    were    not    given.')
        return exception.HeatMissingParameterError(detail=msg)
    try:
        template = template_format.parse(templ)
    except ValueError:
        msg = _('The    Template    must    be    a    JSON    or    YAML    document.')
        return exception.HeatInvalidParameterValueError(detail=msg)
    LOG.info('validate_template')
    def format_validate_parameter(key, value):
        'Reformat    engine    output    into    AWS    "ValidateTemplate"    format.'
        return {'ParameterKey': key, 'DefaultValue': value.get(rpc_api.PARAM_DEFAULT, ''), 'Description': value.get(rpc_api.PARAM_DESCRIPTION, ''), 'NoEcho': value.get(rpc_api.PARAM_NO_ECHO, 'false')}
    try:
        res = self.rpc_client.validate_template(con, template)
        if ('Error' in res):
            return api_utils.format_response('ValidateTemplate', res['Error'])
        res['Parameters'] = [format_validate_parameter(k, v) for (k, v) in res['Parameters'].items()]
        return api_utils.format_response('ValidateTemplate', res)
    except Exception as ex:
        return exception.map_remote_error(ex)
