'Enforce quota limits on metadata properties.'

def _check_metadata_properties_quota(self, context, metadata=None):

    if (not metadata):
        metadata = {}
    if (not isinstance(metadata, dict)):
        msg = _('Metadata    type    should    be    dict.')
        raise exception.InvalidMetadata(reason=msg)
    num_metadata = len(metadata)
    try:
        objects.Quotas.limit_check(context, metadata_items=num_metadata)
    except exception.OverQuota as exc:
        quota_metadata = exc.kwargs['quotas']['metadata_items']
        raise exception.MetadataLimitExceeded(allowed=quota_metadata)
    for (k, v) in metadata.items():
        try:
            utils.check_string_length(v)
            utils.check_string_length(k, min_length=1)
        except exception.InvalidInput as e:
            raise exception.InvalidMetadata(reason=e.format_message())
        if (len(k) > 255):
            msg = _('Metadata    property    key    greater    than    255    characters')
            raise exception.InvalidMetadataSize(reason=msg)
        if (len(v) > 255):
            msg = _('Metadata    property    value    greater    than    255    characters')
            raise exception.InvalidMetadataSize(reason=msg)
