'Implements PutMetricData API action.'

def put_metric_data(self, req):

    self._enforce(req, 'PutMetricData')
    con = req.context
    parms = dict(req.params)
    namespace = api_utils.get_param_value(parms, 'Namespace')
    metric_data = api_utils.extract_param_list(parms, prefix='MetricData')
    if (not len(metric_data)):
        LOG.error('Request    does    not    contain    required    MetricData')
        return exception.HeatMissingParameterError(_('MetricData    list'))
    watch_name = None
    dimensions = []
    for p in metric_data:
        dimension = api_utils.extract_param_pairs(p, prefix='Dimensions', keyname='Name', valuename='Value')
        if ('AlarmName' in dimension):
            watch_name = dimension['AlarmName']
        else:
            dimensions.append(dimension)
    data = {'Namespace': namespace, api_utils.get_param_value(metric_data[0], 'MetricName'): {'Unit': api_utils.get_param_value(metric_data[0], 'Unit'), 'Value': api_utils.get_param_value(metric_data[0], 'Value'), 'Dimensions': dimensions}}
    try:
        self.rpc_client.create_watch_data(con, watch_name, data)
    except messaging.RemoteError as ex:
        return exception.map_remote_error(ex)
    result = {'ResponseMetadata': None}
    return api_utils.format_response('PutMetricData', result)
