From f94d0dfa892f6f8720d636f4c4222952baa9d20b Mon Sep 17 00:00:00 2001 From: Noam Bloom Date: Tue, 25 Oct 2016 13:12:37 +0000 Subject: [PATCH] Added Comprised relationship to constants Change-Id: Ibb4e61cace66d4f0457f0f4a10f352a93ec34369 --- vitrage/common/constants.py | 21 +++++++++---------- .../template_validation/status_messages.py | 10 ++++----- .../template_syntax_validator.py | 8 +++---- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/vitrage/common/constants.py b/vitrage/common/constants.py index a99821f58..f32cceb7e 100644 --- a/vitrage/common/constants.py +++ b/vitrage/common/constants.py @@ -57,14 +57,11 @@ class EdgeLabel(object): MANAGED_BY = 'managed_by' COMPRISED = 'comprised' -edge_labels = [EdgeLabel.ON, - EdgeLabel.CONTAINS, - EdgeLabel.CAUSES, - EdgeLabel.ATTACHED, - EdgeLabel.ATTACHED_PRIVATE, - EdgeLabel.ATTACHED_PUBLIC, - EdgeLabel.CONNECT, - EdgeLabel.MANAGED_BY] + @staticmethod + def labels(): + return [EdgeLabel.__dict__[label] + for label in vars(EdgeLabel) + if not label.startswith(('_', 'labels'))] class SyncMode(object): @@ -83,9 +80,11 @@ class EntityCategory(object): RESOURCE = 'RESOURCE' ALARM = 'ALARM' - -entities_categories = [EntityCategory.RESOURCE, - EntityCategory.ALARM] + @staticmethod + def categories(): + return [EntityCategory.__dict__[category] + for category in vars(EntityCategory) + if not category.startswith(('_', 'categories'))] class DatasourceProperties(object): diff --git a/vitrage/evaluator/template_validation/status_messages.py b/vitrage/evaluator/template_validation/status_messages.py index 2885d5d4f..f95862653 100644 --- a/vitrage/evaluator/template_validation/status_messages.py +++ b/vitrage/evaluator/template_validation/status_messages.py @@ -11,8 +11,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from vitrage.common.constants import edge_labels -from vitrage.common.constants import entities_categories +from vitrage.common.constants import EdgeLabel +from vitrage.common.constants import EntityCategory from vitrage.evaluator.actions.base import action_types status_msgs = { @@ -33,7 +33,7 @@ status_msgs = { 42: 'Entity definition must contain category field.', 43: 'At least one entity must be defined.', 45: 'Invalid entity category. Category must be from types: ' - '%s' % entities_categories, + '{categories}'.format(categories=EntityCategory.categories()), 46: 'Entity field is required.', # metadata section status messages 60-79 @@ -50,7 +50,7 @@ status_msgs = { # relationships status messages 100-119 100: 'Invalid relation type. Relation type must be from types: ' - '%s' % edge_labels, + '{labels}'.format(labels=EdgeLabel.labels()), 101: 'Relationship field is required.', 102: 'Relationship definition must contain source field.', 103: 'Relationship definition must contain target field.', @@ -58,7 +58,7 @@ status_msgs = { # actions status messages 120-139 120: 'Invalid action type. Action type must be from types: ' - '%s' % action_types, + '{actions}'.format(actions=action_types), 121: 'At least one action must be defined.', 122: 'Action field is required.', 123: 'Relationship definition must contain action_type field.', diff --git a/vitrage/evaluator/template_validation/template_syntax_validator.py b/vitrage/evaluator/template_validation/template_syntax_validator.py index c29c7be48..a28a2ec9e 100644 --- a/vitrage/evaluator/template_validation/template_syntax_validator.py +++ b/vitrage/evaluator/template_validation/template_syntax_validator.py @@ -22,8 +22,8 @@ from voluptuous import Invalid from voluptuous import Required from voluptuous import Schema -from vitrage.common.constants import edge_labels -from vitrage.common.constants import entities_categories +from vitrage.common.constants import EdgeLabel +from vitrage.common.constants import EntityCategory from vitrage.evaluator.actions.base import action_types from vitrage.evaluator.template_fields import TemplateFields from vitrage.evaluator.template_validation.base import get_correct_result @@ -269,7 +269,7 @@ def _validate_template_id_value(msg=None): def _validate_category_field(msg=None): def f(v): - if str(v) in entities_categories: + if str(v) in EntityCategory.categories(): return str(v) else: raise Invalid(msg or 45) @@ -278,7 +278,7 @@ def _validate_category_field(msg=None): def _validate_relationship_type_field(msg=None): def f(v): - if str(v) in edge_labels: + if str(v) in EdgeLabel.labels(): return str(v) else: raise Invalid(msg or 100)