-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequireIFdescriptions.slax
More file actions
66 lines (60 loc) · 2.18 KB
/
requireIFdescriptions.slax
File metadata and controls
66 lines (60 loc) · 2.18 KB
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
version 1.1;
/* created 03APR2018 akg
this commit script requires that each PHY interface that is configured have a description.
additionally, if the interface has multiple units, then each unit must have a description
(to put another way, if a physical interface has only one unit, a description isn't required on the unit)
*/
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
template emit-warning($message) {
<xnm:warning> {
call jcs:edit-path();
<message> $message;
}
}
template emit-error($message) {
<xnm:error> {
call jcs:edit-path();
<message> $message;
}
}
match configuration {
for-each (interfaces/interface) {
if (!description) {
call emit-error {
with $message = {
expr name _ " does not have a description. All PHY interfaces require a description";
}
}
}
mvar $parentIF = name;
mvar $unitcount = 0;
mvar $unitdescriptioncount = 0;
mvar $firstunitdesc = "False";
mvar $firstunitname = "";
for-each (unit) {
set $unitcount = $unitcount + 1;
if ($unitcount == 1) { set $firstunitname = name; }
if ($unitcount == 1 && description) {
set $unitdescriptioncount = $unitdescriptioncount + 1;
set $firstunitdesc = "True";
}
if ($unitcount > 1 && !description) {
call emit-error {
with $message = {
expr "Unit " _ name _ " of interface " _ $parentIF _ " has no description. Each unit of a multi-unit interface requires a description.";
}
}
}
}
if ($unitcount > 1 && $firstunitdesc == "False") {
call emit-error {
with $message = {
expr "Unit " _ $firstunitname _ " of interface " _ $parentIF _ " has no description. Each unit of a multi-unit interface requires a description.";
}
}
}
}
}