Chaoyi Huang b350bfe6ba Quota management for Nova-APIGW and Cinder-APIGW(part2)
Port and modify the quota management code mostly from Cinder, for
Cinder has implemented for hierarchy multi-tenancy quota management

The code is modified as following:
1. combine the Nova quota resources
2. add AllQuotaEngine and QuotaSetOperation
3. not implemented the volume_type, user based quota management
4. not process is_force
5. update and add test use cases to reflect the new added code and
   resources

The quota management and control in Tricircle is described in the
design doc:
https://docs.google.com/document/d/18kZZ1snMOCD9IQvUKI5NVDzSASpw-QKj7l2zNqMEd3g/

BP: https://blueprints.launchpad.net/tricircle/+spec/implement-stateless

Change-Id: I636d21b5bd7e51949f1431d642dac49321496fbd
Signed-off-by: Chaoyi Huang <joehuang@huawei.com>
2016-02-18 10:14:56 +08:00

84 lines
2.5 KiB
Python

# Copyright 2015 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from tricircle.common.i18n import _
def get_import_path(cls):
return cls.__module__ + "." + cls.__name__
def get_ag_name(pod_name):
return 'ag_%s' % pod_name
def get_az_name(pod_name):
return 'az_%s' % pod_name
def get_node_name(pod_name):
return "cascade_%s" % pod_name
def validate_required_fields_set(body, fields):
for field in fields:
if field not in body:
return False
return True
TRUE_STRINGS = ('1', 't', 'true', 'on', 'y', 'yes')
FALSE_STRINGS = ('0', 'f', 'false', 'off', 'n', 'no')
def is_valid_boolstr(val):
"""Check if the provided string is a valid bool string or not."""
val = str(val).lower()
return (val in TRUE_STRINGS) or (val in FALSE_STRINGS)
def bool_from_string(subject, strict=False, default=False):
"""Interpret a string as a boolean.
A case-insensitive match is performed such that strings matching 't',
'true', 'on', 'y', 'yes', or '1' are considered True and, when
`strict=False`, anything else returns the value specified by 'default'.
Useful for JSON-decoded stuff and config file parsing.
If `strict=True`, unrecognized values, including None, will raise a
ValueError which is useful when parsing values passed in from an API call.
Strings yielding False are 'f', 'false', 'off', 'n', 'no', or '0'.
"""
if not isinstance(subject, six.string_types):
subject = six.text_type(subject)
lowered = subject.strip().lower()
if lowered in TRUE_STRINGS:
return True
elif lowered in FALSE_STRINGS:
return False
elif strict:
acceptable = ', '.join(
"'%s'" % s for s in sorted(TRUE_STRINGS + FALSE_STRINGS))
msg = _("Unrecognized value '%(val)s', acceptable values are:"
" %(acceptable)s") % {'val': subject,
'acceptable': acceptable}
raise ValueError(msg)
else:
return default