Added Comprised relationship to constants

Change-Id: Ibb4e61cace66d4f0457f0f4a10f352a93ec34369
This commit is contained in:
Noam Bloom 2016-10-25 13:12:37 +00:00
parent d6d4f4c6f4
commit f94d0dfa89
3 changed files with 19 additions and 20 deletions

View File

@ -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):

View File

@ -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.',

View File

@ -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)