From 6b02b05e51fb2837731027ae063ecbdb2c71135d Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 2 Jun 2020 10:07:41 +0000 Subject: [PATCH 1/1] Feature 9015: use same names for quotas and roles add osmrepos to quotas Change-Id: I8cf11677b8aa5612f78ff10492d432849b33cd08 Signed-off-by: tierno --- osm_nbi/admin_topics.py | 1 + osm_nbi/base_topic.py | 12 +++++++----- osm_nbi/descriptor_topics.py | 2 ++ osm_nbi/instance_topics.py | 2 ++ osm_nbi/validation.py | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index 26c44d2..6342ba2 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -398,6 +398,7 @@ class WimAccountTopic(CommonVimWimSdn): class SdnTopic(CommonVimWimSdn): topic = "sdns" topic_msg = "sdn" + quota_name = "sdn_controllers" schema_new = sdn_new_schema schema_edit = sdn_edit_schema multiproject = True diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index 1f7f5d4..2986b81 100644 --- a/osm_nbi/base_topic.py +++ b/osm_nbi/base_topic.py @@ -69,6 +69,7 @@ class BaseTopic: # static variables for all instance classes topic = None # to_override topic_msg = None # to_override + quota_name = None # to_override. If not provided topic will be used for quota_name schema_new = None # to_override schema_edit = None # to_override multiproject = True # True if this Topic can be shared by several projects. Then it contains _admin.projects_read @@ -107,12 +108,12 @@ class BaseTopic: """ Check whether topic quota is exceeded by the given project Used by relevant topics' 'new' function to decide whether or not creation of the new item should be allowed - :param projects: projects (tuple) for which quota should be checked - :param override: boolean. If true, don't raise ValidationError even though quota be exceeded + :param session[project_id]: projects (tuple) for which quota should be checked + :param session[force]: boolean. If true, skip quota checking :return: None :raise: DbException if project not found - ValidationError if quota exceeded and not overridden + ValidationError if quota exceeded in one of the projects """ if session["force"]: return @@ -120,11 +121,12 @@ class BaseTopic: for project in projects: proj = self.auth.get_project(project) pid = proj["_id"] - quota = proj.get("quotas", {}).get(self.topic, self.default_quota) + quota_name = self.quota_name or self.topic + quota = proj.get("quotas", {}).get(quota_name, self.default_quota) count = self.db.count(self.topic, {"_admin.projects_read": pid}) if count >= quota: name = proj["name"] - raise ValidationError("quota ({}={}) exceeded for project {} ({})".format(self.topic, quota, name, pid), + raise ValidationError("quota ({}={}) exceeded for project {} ({})".format(quota_name, quota, name, pid), http_code=HTTPStatus.UNAUTHORIZED) def _validate_input_new(self, input, force=False): diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index a5cc196..517f1db 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -856,6 +856,7 @@ class NsdTopic(DescriptorTopic): class NstTopic(DescriptorTopic): topic = "nsts" topic_msg = "nst" + quota_name = "slice_templates" def __init__(self, db, fs, msg, auth): DescriptorTopic.__init__(self, db, fs, msg, auth) @@ -929,6 +930,7 @@ class NstTopic(DescriptorTopic): class PduTopic(BaseTopic): topic = "pdus" topic_msg = "pdu" + quota_name = "pduds" schema_new = pdu_new_schema schema_edit = pdu_edit_schema diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index e091abd..d58fc3d 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -34,6 +34,7 @@ __author__ = "Alfonso Tierno " class NsrTopic(BaseTopic): topic = "nsrs" topic_msg = "ns" + quota_name = "ns_instances" schema_new = ns_instantiate def __init__(self, db, fs, msg, auth): @@ -1070,6 +1071,7 @@ class NsLcmOpTopic(BaseTopic): class NsiTopic(BaseTopic): topic = "nsis" topic_msg = "nsi" + quota_name = "slice_instances" def __init__(self, db, fs, msg, auth): BaseTopic.__init__(self, db, fs, msg, auth) diff --git a/osm_nbi/validation.py b/osm_nbi/validation.py index 505201c..d93feb0 100644 --- a/osm_nbi/validation.py +++ b/osm_nbi/validation.py @@ -831,8 +831,8 @@ user_edit_schema = { } # PROJECTS -topics_with_quota = ["vnfds", "nsds", "nsts", "pdus", "nsrs", "nsis", "vim_accounts", "wim_accounts", "sdns", - "k8sclusters", "k8srepos"] +topics_with_quota = ["vnfds", "nsds", "slice_templates", "pduds", "ns_instances", "slice_instances", "vim_accounts", + "wim_accounts", "sdn_controllers", "k8sclusters", "k8srepos", "osmrepos"] project_new_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "title": "New project schema for administrators", -- 2.17.1