Allow multiple NTS Manager instances to run on the same machine.
[sim/o1-interface.git] / ntsimulator / yang / auto-load-yangs.sh
1 #!/bin/bash
2 ################################################################################
3 #
4 # Copyright 2019 highstreet technologies GmbH and others
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 #     http://www.apache.org/licenses/LICENSE-2.0
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ################################################################################
18
19 echo "Installing YANG models..."
20
21 set -eu -o pipefail
22
23 shopt -s failglob
24
25 : ${SYSREPOCTL:=sysrepoctl}
26 : ${SYSREPOCFG:=sysrepocfg}
27 : ${SYSREPOAPPSTART:=/opt/dev/sysrepo/build/examples/application_example}
28
29 declare -a excludedModules=()
30
31 # Uninstall the NTS Manager YANG model
32 $SYSREPOCTL -u -m network-topology-simulator
33 # $SYSREPOCTL -u -m iana-if-type
34 # $SYSREPOCTL -u -m ietf-ip
35 # $SYSREPOCTL -u -m ietf-interfaces
36
37
38 sleep 5
39
40 pyang -f clearmust *.yang
41
42 mapfile -t modelList < <(pyang -f depend --depend-recurse *.yang)
43
44 for model in *.yang
45 do
46   echo "Removing config false from $model..."
47   sed -i '/config false;/d' $model
48   echo "Removing mandatory true from $model..."
49   sed -i '/mandatory true;/d' $model
50 done
51
52 if [ ${#modelList[@]} -eq 0 ]; then
53   echo "No models present, nothing to do..."
54   exit 0
55 else
56   for model in ${modelList[@]}
57   do
58     modelName=${model%".yang"}
59     
60     skip_model=false
61     
62     for excluded in ${excludedModules[@]}; do
63       if [ "$excluded" == "$modelName" ]; then
64         skip_model=true
65       fi
66     done
67     
68     if [ "$skip_model" = true ]; then
69       echo "Skipping installation of excluded model $modelName..."
70       continue
71     fi
72     
73     echo "Installing model: $model"
74     $SYSREPOCTL --install --yang=$model --owner=root:root --permissions=666
75     
76         mapfile -t featureList < <(pyang -f listfeature $model)
77   
78     if [ ${#featureList[@]} -eq 0 ]; then
79       echo "No features, nothing to do here..."
80     else
81       for feature in ${featureList[@]}
82       do
83         $SYSREPOCTL --feature-enable=$feature --module=$modelName
84       done
85     fi
86     
87     #if the YANG model contains only typedefs, we do not need to subscribe for datastore changes
88     isTypeOnly=$(pyang -f listfeature --is-type-only $model)
89     
90     if [ "$isTypeOnly" == "False" ]; then
91       printf "\n[program:$modelName]\ncommand=/opt/dev/sysrepo/build/examples/application_example $modelName\nautorestart=false\nredirect_stderr=true\nstartretries=1\npriority=4\n" >> /etc/supervisord.conf  
92     fi
93     
94   done
95 fi
96
97 # Fix for the NETCONF notifications
98 echo "Fixing the NETCONF notifications..."
99 mkdir -p /var/run/sysrepo-subscriptions/ietf-crypto-types
100
101 echo "YANG models installation done!"
102
103 exit 0