Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # Copyright 2015-present Open Networking Foundation |
| 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 | # ----------------------------------------------------------------------------- |
| 20 | # Tool to compile the specified YANG file(s) using the ONOS live compilation. |
| 21 | # ----------------------------------------------------------------------------- |
| 22 | |
| 23 | # If ONOS_HOME is set, respect its value. |
| 24 | # If ONOS_HOME is not set (e.g. in the init or service environment), |
| 25 | # set it based on this script's path. |
| 26 | ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)} |
| 27 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 28 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 29 | |
| 30 | . ${ONOS_HOME}/bin/_find-node |
| 31 | |
| 32 | node=$(find_node $1) |
| 33 | yang=$2 |
| 34 | |
| 35 | export URL=http://$node:8181/onos/yang/models |
| 36 | export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy localhost " |
| 37 | |
| 38 | # Prints usage help |
| 39 | function usage { |
| 40 | echo "usage: onos-compile-yang <yang-file|zip-file|jar-file|directory>" >&2 |
| 41 | exit 1 |
| 42 | } |
| 43 | |
| 44 | [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage |
| 45 | |
| 46 | if [ -d $yang ]; then |
| 47 | newYang=/tmp/$(basename $yang).jar |
| 48 | jar cf $newYang $yang |
| 49 | yang=$newYang |
| 50 | fi |
| 51 | |
| 52 | file=$(basename $yang) |
| 53 | modelId="$(echo $file | sed -E 's/(.zip|.jar|.yang)$//g')" |
| 54 | curl $URL?modelId=$modelId -F"file=@$yang" |