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 | # ----------------------------------------------------------------------------- |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 22 | function usage { |
| 23 | echo "usage: onos-compile-yang [-P port] [-u user] [-p password] [-v] \\" |
| 24 | echo " <yang-file|zip-file|jar-file|directory>" >&2 |
| 25 | exit 1 |
| 26 | } |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 27 | |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 28 | . $(dirname $0)/_rest-port |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 29 | . $(dirname $0)/_find-node |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 30 | |
| 31 | node=$(find_node $1) |
| 32 | yang=$2 |
| 33 | |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 34 | export URL=http://$node:$port/onos/yang/models |
| 35 | export curl="curl $fail -sSL --user $user:$password --noproxy ${node} " |
Thomas Vachuska | ad37e37 | 2017-08-03 12:07:01 -0700 | [diff] [blame] | 36 | |
| 37 | [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage |
| 38 | |
| 39 | if [ -d $yang ]; then |
| 40 | newYang=/tmp/$(basename $yang).jar |
| 41 | jar cf $newYang $yang |
| 42 | yang=$newYang |
| 43 | fi |
| 44 | |
| 45 | file=$(basename $yang) |
| 46 | modelId="$(echo $file | sed -E 's/(.zip|.jar|.yang)$//g')" |
| 47 | curl $URL?modelId=$modelId -F"file=@$yang" |