'Replaces the aggregate\'s existing metadata with new metadata.'

@extensions.expected_errors((400, 404))
@wsgi.action('set_metadata')
@validation.schema(aggregates.set_metadata)
def _set_metadata(self, req, id, body):

    context = _get_context(req)
    context.can((aggr_policies.POLICY_ROOT % 'set_metadata'))
    metadata = body['set_metadata']['metadata']
    try:
        aggregate = self.api.update_aggregate_metadata(context, id, metadata)
    except exception.AggregateNotFound as e:
        raise exc.HTTPNotFound(explanation=e.format_message())
    except exception.InvalidAggregateAction as e:
        raise exc.HTTPBadRequest(explanation=e.format_message())
    return self._marshall_aggregate(req, aggregate)
