Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2015-present Open Networking Foundation |
| 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 |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 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 | # |
| 17 | |
| 18 | # ----------------------------------------------------------------------------- |
| 19 | # Tool to compile the specified YANG file(s) using the ONOS live compilation. |
| 20 | # ----------------------------------------------------------------------------- |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 21 | function usage { |
| 22 | echo "usage: onos-compile-yang [-P port] [-u user] [-p password] [-v] \\" |
| 23 | echo " <yang-file|zip-file|jar-file|directory>" >&2 |
| 24 | exit 1 |
| 25 | } |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 26 | |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 27 | . $(dirname $0)/_rest-port |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 28 | . $(dirname $0)/_find-node |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 29 | |
| 30 | node=$(find_node $1) |
| 31 | yang=$2 |
| 32 | |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 33 | export URL=http://$node:$port/onos/yang/models |
| 34 | export curl="curl $fail -sSL --user $user:$password --noproxy ${node} " |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 35 | |
| 36 | [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage |
| 37 | |
| 38 | if [ -d $yang ]; then |
| 39 | newYang=/tmp/$(basename $yang).jar |
| 40 | jar cf $newYang $yang |
| 41 | yang=$newYang |
| 42 | fi |
| 43 | |
| 44 | file=$(basename $yang) |
| 45 | modelId="$(echo $file | sed -E 's/(.zip|.jar|.yang)$//g')" |
Thomas Vachuska | 47cd744 | 2018-07-17 11:51:54 -0700 | [diff] [blame^] | 46 | $curl $URL?modelId=$modelId -F"file=@$yang" |