'Create, update or display quotas for project/user
If no quota key is provided, the quota will be displayed.
If a valid quota key is provided and it does not exist,
it will be created. Otherwise, it will be updated.'

@args('--project', dest='project_id', metavar='<Project    name>', help='Project    name')
@args('--user', dest='user_id', metavar='<User    name>', help='User    name')
@args('--key', metavar='<key>', help='Key')
@args('--value', metavar='<value>', help='Value')
def quota(self, project_id, user_id=None, key=None, value=None):

    ctxt = context.get_admin_context()
    if user_id:
        quota = QUOTAS.get_user_quotas(ctxt, project_id, user_id)
    else:
        user_id = None
        quota = QUOTAS.get_project_quotas(ctxt, project_id)
    if key:
        settable_quotas = QUOTAS.get_settable_quotas(ctxt, project_id, user_id=user_id)
        if (key in quota):
            minimum = settable_quotas[key]['minimum']
            maximum = settable_quotas[key]['maximum']
            if (value.lower() == 'unlimited'):
                value = (-1)
            if (int(value) < (-1)):
                print(_('Quota    limit    must    be    -1    or    greater.'))
                return 2
            if ((int(value) < minimum) and ((maximum != (-1)) or ((maximum == (-1)) and (int(value) != (-1))))):
                print((_('Quota    limit    must    be    greater    than    %s.') % minimum))
                return 2
            if ((maximum != (-1)) and (int(value) > maximum)):
                print((_('Quota    limit    must    be    less    than    %s.') % maximum))
                return 2
            try:
                objects.Quotas.create_limit(ctxt, project_id, key, value, user_id=user_id)
            except exception.QuotaExists:
                objects.Quotas.update_limit(ctxt, project_id, key, value, user_id=user_id)
        else:
            print((_('%(key)s    is    not    a    valid    quota    key.    Valid    options    are:    %(options)s.') % {'key': key, 'options': ',    '.join(quota)}))
            return 2
    print_format = '%-36s    %-10s    %-10s    %-10s'
    print((print_format % (_('Quota'), _('Limit'), _('In    Use'), _('Reserved'))))
    if user_id:
        quota = QUOTAS.get_user_quotas(ctxt, project_id, user_id)
    else:
        quota = QUOTAS.get_project_quotas(ctxt, project_id)
    for (key, value) in quota.items():
        if ((value['limit'] is None) or (value['limit'] < 0)):
            value['limit'] = 'unlimited'
        print((print_format % (key, value['limit'], value['in_use'], value['reserved'])))
