2 * ============LICENSE_START===================================================
3 * Copyright (c) 2018 Amdocs
4 * ============================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=====================================================
22 useRule {name 'vserver is related to 0 or 1 image' }
23 useRule {name 'vserver is related to 0 or 1 flavor' }
24 useRule {name 'vserver is related to 1 pserver' }
25 useRule {name 'vserver is related to vpe and vserver-name matches naming convention' }
26 useRule {name 'vserver is related to vce and vserver-name matches naming convention' }
28 name 'vserver related to TRINITY image and generic-vnf.vnf-name matches naming convention'
29 attributes 'relationship-list.relationship[*]'
32 name 'vserver is related to a TRINITY image and vserver-name matches naming convention'
33 attributes 'relationship-list.relationship[*]', 'vserver-name'
36 name 'vserver is related to a vnf (vce or newvce or vpe or generic-vnf)'
37 attributes 'relationship-list.relationship[*].related-to'
43 name 'vserver related to TRINITY image and generic-vnf.vnf-name matches naming convention'
44 category 'INVALID_NAME'
45 description 'Validates that if vserver is related to an image named TRINITY, then the related generic-vnf name matches naming convention'
46 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)'
48 attributes 'relationships'
50 def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName)?.getAsString() }
52 vnf_name = relationships.findAll { getStringProperty(it, "related-to") == "generic-vnf" }
53 .findAll { it."related-to-property" != null }
54 .collect { it."related-to-property".get(0) }
55 .find { getStringProperty(it, "property-key") == "generic-vnf.vnf-name" }
56 .findResult { getStringProperty(it, "property-value") }
58 relatedToTrinity = relationships.findAll { getStringProperty(it, "related-to") == "image" }
59 .findAll { it."related-to-property" != null }
60 .collect { it."related-to-property".get(0) }
61 .findAll { getStringProperty(it, "property-key") == "image.image-name" }
62 .find { getStringProperty(it, "property-value")?.startsWith("TRINITY") }
64 // If (and only if) related to TRINITY then check the generic-vnf name
65 return !relatedToTrinity || vnf_name?.matches("[a-z]{4}[0-9]{4}v")
70 name 'vserver is related to a vnf (vce or newvce or vpe or generic-vnf)'
71 category 'MISSING_REL'
72 description 'Validates that a vserver is related to a vnf (vce or newvce or vpe or generic-vnf)'
73 errorText 'Missing relationship - a vserver must be related to a vnf (vce or newvce or vpe or generic-vnf)'
75 attributes 'related-to'
76 validate 'related-to != null && (related-to.contains("vce") || related-to.contains("newvce") || related-to.contains("vpe") || related-to.contains("generic-vnf"))'
80 name 'vserver is related to 1 pserver'
81 category 'MISSING_REL'
82 description 'Validates that a vserver is related to 1 pserver (and not more than 1 pserver)'
83 errorText 'Missing relationship - vserver must be related to 1 pserver'
85 attributes 'relationship-list.relationship[*].related-to'
86 validate 'related-to != null && related-to.count("pserver") == 1'
90 name 'vserver is related to 0 or 1 image'
91 category 'MISSING_REL'
92 description 'Validates that a vserver is either not related to an image or related to only 1 image'
93 errorText 'Missing relationship - vserver must be related to 0 or 1 image'
95 attributes 'relationship-list.relationship[*].related-to'
96 validate 'related-to == null || related-to.count("image") <= 1'
100 name 'vserver is related to 0 or 1 flavor'
101 category 'MISSING_REL'
102 description 'Validates that a vserver is either not related to a flavor or related to only 1 flavor'
103 errorText 'Missing relationship - vserver must be related to 0 or 1 flavor'
105 attributes 'relationship-list.relationship[*].related-to'
106 validate 'related-to == null || related-to.count("flavor") <= 1'
110 name 'vserver is related to vpe and vserver-name matches naming convention'
111 category 'INVALID_NAME'
112 description 'Validates that if a vserver is related to a vpe then vserver-name must contain me6'
113 errorText 'Invalid name - if vserver is related to vpe then vserver-name must contain me6'
115 attributes 'relationship-list.relationship[*].related-to', 'vserver-name'
116 validate '!related-to.contains("vpe") || vserver-name =~ "me6"'
120 name 'vserver is related to vce and vserver-name matches naming convention'
121 category 'INVALID_NAME'
122 description 'Validates that if a vserver is related to a vce then vserver-name must match naming convention'
123 errorText 'Invalid name - if vserver is related to vce then vserver-name must match xxxxxxxxvbcnnceb (where x = alphanumeric and n = numeric)'
125 attributes 'relationship-list.relationship[*].related-to', 'vserver-name'
126 validate '!related-to.contains("vce") || vserver-name =~ "[a-z0-9]{8}vbc[0-9]{2}ceb"'
132 name 'vserver is related to a TRINITY image and vserver-name matches naming convention'
133 category 'INVALID_NAME'
134 description 'Validates that if vserver is related to an image named TRINITY, then the vserver name matches naming convention'
135 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)'
137 attributes 'relationships', 'vservername'
139 def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName)?.getAsString() }
141 relatedToTrinity = relationships.findAll { getStringProperty(it, "related-to") == "image" }
142 .findAll { it."related-to-property" != null }
143 .collect { it."related-to-property".get(0) }
144 .findAll { getStringProperty(it, "property-key") == "image.image-name" }
145 .find { getStringProperty(it, "property-value").startsWith("TRINITY") }
147 // If (and only if) related to TRINITY then check the vserver name
148 return !relatedToTrinity || vservername != null && vservername ==~ "[a-z]{4}[0-9]{4}vm[0-9]{3}"