'Implements DescribeAlarms API action.'

def describe_alarms(self, req):

    self._enforce(req, 'DescribeAlarms')
    def format_metric_alarm(a):
        'Reformat    engine    output    into    the    AWS    "MetricAlarm"    format.'
        keymap = {rpc_api.WATCH_ACTIONS_ENABLED: 'ActionsEnabled', rpc_api.WATCH_ALARM_ACTIONS: 'AlarmActions', rpc_api.WATCH_TOPIC: 'AlarmArn', rpc_api.WATCH_UPDATED_TIME: 'AlarmConfigurationUpdatedTimestamp', rpc_api.WATCH_DESCRIPTION: 'AlarmDescription', rpc_api.WATCH_NAME: 'AlarmName', rpc_api.WATCH_COMPARISON: 'ComparisonOperator', rpc_api.WATCH_DIMENSIONS: 'Dimensions', rpc_api.WATCH_PERIODS: 'EvaluationPeriods', rpc_api.WATCH_INSUFFICIENT_ACTIONS: 'InsufficientDataActions', rpc_api.WATCH_METRIC_NAME: 'MetricName', rpc_api.WATCH_NAMESPACE: 'Namespace', rpc_api.WATCH_OK_ACTIONS: 'OKActions', rpc_api.WATCH_PERIOD: 'Period', rpc_api.WATCH_STATE_REASON: 'StateReason', rpc_api.WATCH_STATE_REASON_DATA: 'StateReasonData', rpc_api.WATCH_STATE_UPDATED_TIME: 'StateUpdatedTimestamp', rpc_api.WATCH_STATE_VALUE: 'StateValue', rpc_api.WATCH_STATISTIC: 'Statistic', rpc_api.WATCH_THRESHOLD: 'Threshold', rpc_api.WATCH_UNIT: 'Unit'}
        a[rpc_api.WATCH_DIMENSIONS].append({'StackId': a[rpc_api.WATCH_STACK_ID]})
        a[rpc_api.WATCH_DIMENSIONS] = self._reformat_dimensions(a[rpc_api.WATCH_DIMENSIONS])
        return api_utils.reformat_dict_keys(keymap, a)
    con = req.context
    parms = dict(req.params)
    try:
        name = parms['AlarmName']
    except KeyError:
        name = None
    try:
        watch_list = self.rpc_client.show_watch(con, watch_name=name)
    except messaging.RemoteError as ex:
        return exception.map_remote_error(ex)
    res = {'MetricAlarms': [format_metric_alarm(a) for a in watch_list]}
    result = api_utils.format_response('DescribeAlarms', res)
    return result
