'Implements ListMetrics API action.
Lists metric datapoints associated with a particular alarm,
or all alarms if none specified.'

def list_metrics(self, req):

    self._enforce(req, 'ListMetrics')
    def format_metric_data(d, fil=None):
        'Reformat    engine    output    into    the    AWS    "Metric"    format.\n\n                                                Takes    an    optional    filter    dict,    which    is    traversed\n                                                so    a    metric    dict    is    only    returned    if    all    keys    match\n                                                the    filter    dict.\n                                                '
        fil = (fil or {})
        dimensions = [{'AlarmName': d[rpc_api.WATCH_DATA_ALARM]}, {'Timestamp': d[rpc_api.WATCH_DATA_TIME]}]
        for key in d[rpc_api.WATCH_DATA]:
            dimensions.append({key: d[rpc_api.WATCH_DATA][key]})
        newdims = self._reformat_dimensions(dimensions)
        result = {'MetricName': d[rpc_api.WATCH_DATA_METRIC], 'Dimensions': newdims, 'Namespace': d[rpc_api.WATCH_DATA_NAMESPACE]}
        for f in fil:
            try:
                value = result[f]
                if (value != fil[f]):
                    return
            except KeyError:
                LOG.warning('Invalid    filter    key    %s,    ignoring', f)
        return result
    con = req.context
    parms = dict(req.params)
    filter_result = dict(((k, v) for (k, v) in six.iteritems(parms) if (k in ('MetricName', 'Namespace'))))
    LOG.debug(('filter    parameters    :    %s' % filter_result))
    try:
        null_kwargs = {'metric_namespace': None, 'metric_name': None}
        watch_data = self.rpc_client.show_watch_metric(con, **null_kwargs)
    except messaging.RemoteError as ex:
        return exception.map_remote_error(ex)
    res = {'Metrics': []}
    for d in watch_data:
        metric = format_metric_data(d, filter_result)
        if metric:
            res['Metrics'].append(metric)
    result = api_utils.format_response('ListMetrics', res)
    return result
