summaryrefslogtreecommitdiffstats
path: root/bundleconfig/etc/rules/aai-event/entity-vserver.groovy
blob: f6b3471199028cad3dd71cd2e6e31d6c5b820b5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * ============LICENSE_START===================================================
 * Copyright (c) 2018 Amdocs
 * ============================================================================
 * 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.
 * ============LICENSE_END=====================================================
 */

entity {
	type 'vserver'
	validation {
		useRule {name 'vserver is related to 0 or 1 image' }
		useRule {name 'vserver is related to 0 or 1 flavor' }
		useRule {name 'vserver is related to 1 pserver' }
		useRule {name 'vserver is related to vpe and vserver-name matches naming convention' }
		useRule {name 'vserver is related to vce and vserver-name matches naming convention' }
		useRule {
			name 'vserver related to TRINITY image and generic-vnf.vnf-name matches naming convention'
			attributes 'relationship-list.relationship[*]'
		}
		useRule {
			name  'vserver is related to a TRINITY image and vserver-name matches naming convention'
			attributes 'relationship-list.relationship[*]', 'vserver-name'
		}
		useRule {
			name  'vserver is related to a vnf (vce or newvce or vpe or generic-vnf)'
			attributes 'relationship-list.relationship[*].related-to'
		}
	}
}

rule {
	name        'vserver related to TRINITY image and generic-vnf.vnf-name matches naming convention'
	category    'INVALID_NAME'
	description 'Validates that if vserver is related to an image named TRINITY, then the related generic-vnf name matches naming convention'
	errorText   'Invalid name - if vserver is related to an image named TRINITY, then the related generic-vnf name must match xxxxnnnnv (where x = character and n = number)'
	severity    'MINOR'
	attributes  'relationships'
	validate    '''
                     def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName)?.getAsString() } 

					 vnf_name = relationships.findAll    { getStringProperty(it, "related-to") == "generic-vnf" }
                                             .findAll    { it."related-to-property" != null }
                                             .collect    { it."related-to-property".get(0) }
						    				 .find       { getStringProperty(it, "property-key") == "generic-vnf.vnf-name" }
										     .findResult { getStringProperty(it, "property-value") }

	  	 			 relatedToTrinity = relationships.findAll    { getStringProperty(it, "related-to") == "image" }
													 .findAll    { it."related-to-property" != null }
										             .collect    { it."related-to-property".get(0) }
									    			 .findAll    { getStringProperty(it, "property-key") == "image.image-name" }
									    	 	     .find       { getStringProperty(it, "property-value")?.startsWith("TRINITY") }

                     // If (and only if) related to TRINITY then check the generic-vnf name
                     return !relatedToTrinity || vnf_name?.matches("[a-z]{4}[0-9]{4}v")
                     '''
}

rule {
	name        'vserver is related to a vnf (vce or newvce or vpe or generic-vnf)'
	category    'MISSING_REL'
	description 'Validates that a vserver is related to a vnf (vce or newvce or vpe or generic-vnf)'
	errorText   'Missing relationship - a vserver must be related to a vnf (vce or newvce or vpe or generic-vnf)'
	severity    'MINOR'
	attributes  'related-to'
	validate    'related-to != null && (related-to.contains("vce") || related-to.contains("newvce") || related-to.contains("vpe") || related-to.contains("generic-vnf"))'
}

rule {
	name        'vserver is related to 1 pserver'
	category    'MISSING_REL'
	description 'Validates that a vserver is related to 1 pserver (and not more than 1 pserver)'
	errorText   'Missing relationship - vserver must be related to 1 pserver'
	severity    'MINOR'
	attributes  'relationship-list.relationship[*].related-to'
	validate    'related-to != null && related-to.count("pserver") == 1'
}

rule {
	name        'vserver is related to 0 or 1 image'
	category    'MISSING_REL'
	description 'Validates that a vserver is either not related to an image or related to only 1 image'
	errorText   'Missing relationship - vserver must be related to 0 or 1 image'
	severity    'MINOR'
	attributes  'relationship-list.relationship[*].related-to'
	validate    'related-to == null || related-to.count("image") <= 1'
}

rule {
	name        'vserver is related to 0 or 1 flavor'
	category    'MISSING_REL'
	description 'Validates that a vserver is either not related to a flavor or related to only 1 flavor'
	errorText   'Missing relationship - vserver must be related to 0 or 1 flavor'
	severity    'MINOR'
	attributes  'relationship-list.relationship[*].related-to'
	validate    'related-to == null || related-to.count("flavor") <= 1'
}

rule {
	name        'vserver is related to vpe and vserver-name matches naming convention'
	category    'INVALID_NAME'
	description 'Validates that if a vserver is related to a vpe then vserver-name must contain me6'
	errorText   'Invalid name - if vserver is related to vpe then vserver-name must contain me6'
	severity    'MINOR'
	attributes  'relationship-list.relationship[*].related-to', 'vserver-name'
	validate    '!related-to.contains("vpe") || vserver-name =~ "me6"'
}

rule {
	name        'vserver is related to vce and vserver-name matches naming convention'
	category    'INVALID_NAME'
	description 'Validates that if a vserver is related to a vce then vserver-name must match naming convention'
	errorText   'Invalid name - if vserver is related to vce then vserver-name must match xxxxxxxxvbcnnceb (where x = alphanumeric and n = numeric)'
	severity    'MINOR'
	attributes  'relationship-list.relationship[*].related-to', 'vserver-name'
	validate    '!related-to.contains("vce") || vserver-name =~ "[a-z0-9]{8}vbc[0-9]{2}ceb"'
}



rule {
	name          'vserver is related to a TRINITY image and vserver-name matches naming convention'
	category      'INVALID_NAME'
	description   'Validates that if vserver is related to an image named TRINITY, then the vserver name matches naming convention'
	errorText     'Invalid name - if vserver is related to an image named TRINITY, then the vserver name must match xxxxnnnnvmnnn (where x = character and n = number)'
	severity      'MINOR'
	attributes    'relationships', 'vservername'
	validate      '''
                  def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName)?.getAsString() } 

   	 			  relatedToTrinity = relationships.findAll    { getStringProperty(it, "related-to") == "image" }
												  .findAll    { it."related-to-property" != null }
												  .collect    { it."related-to-property".get(0) }
								    			  .findAll    { getStringProperty(it, "property-key") == "image.image-name" }
								    	 	      .find       { getStringProperty(it, "property-value").startsWith("TRINITY") }

	              // If (and only if) related to TRINITY then check the vserver name
	              return !relatedToTrinity || vservername != null && vservername ==~ "[a-z]{4}[0-9]{4}vm[0-9]{3}"
	              '''
}