2 ################################################################################
4 # Copyright 2020 highstreet technologies GmbH and others
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 ################################################################################
19 # Script linting 3GPP yang modules
25 IMPORT="${DIR}/external-yams"
27 _3GPP_REPO=https://forge.etsi.org/rep/3GPP/SA5/data-models
32 echo "Usage: yang-linter [options] <directory>"
34 echo "As much as possible automatic yang linter"
37 echo " -3, --3gpp Clone and lint 3GPP SA5 yang modules and exit"
38 echo " -h, --help Show this help message and exit"
40 echo " -i=IMPORTDIR, --imports=IMPORTDiR"
41 echo " Defines an import directory for standard yang modules"
43 echo " -s, --status Show app status information and exit"
45 echo " -t=TARGETDIR, --target=TARGETDIR"
46 echo " Defines the target output directory"
48 echo " -v, --version Show version number and exit"
50 echo " <directory> The folder containng yang modules"
55 message " INFO | Clone from $_3GPP_REPO"
57 # git clone "$_3GPP_REPO" "./_3GPP"
58 DIR="./_3GPP"/"$_3GPP_DIR"
59 IMPORT="${DIR}/external-yams"
63 FNAME="$(basename ${@})"
64 echo " INFO | Linting ... ($FNAME)"
66 # pyang --strict --path "${IMPORT}" --path "${DIR}" $@
67 pyang --format yang --yang-canonical --yang-remove-unused-imports --output "${TARGET}/${FNAME}" --path "${IMPORT}" --path "${DIR}" $@
74 function error-message () {
80 function show-status {
81 PYANG="$(pyang --version)"
82 GIT="$(git --version)"
83 if [[ $PYANG == pyang* ]] && [[ $GIT == git* ]]
89 echo "Status: Please install latest pyang and git"
90 echo " - https://github.com/mbj4668/pyang"
91 echo " - sudo apt install git-all"
96 function show-version {
97 echo "yang-linter $VERSION"
107 [[ "$#" != "0" ]] || error-message "1 argument required, $# provided"
128 # message " WARN | Unknown option: $i"
133 [[ -d "$DIR" ]] || error-message "Directory '$DIR' does not exist"
136 echo TARGET = ${TARGET}
140 for yang in ${DIR}/*.yang
142 [ -f "$yang" ] || break
151 for key in "${!mapping[@]}"
153 sequence="$sequence s!@$key@!${mapping[$key]}!g; "
155 body=http-post-body.xml
156 sed -e "$sequence" http-post-body.template.xml > $body;
158 uri=$protocol://$controller:$port/$path/node/$nodeId/yang-ext:mount/ietf-netconf:get
160 body=http-post-body.xml
161 sed -e "$sequence" http-post-body.template.xml > $body;
163 curl -i -k -u $basicAuth -H $content -H $accept -X POST -d @${body} $uri