blob: e1bb9872ae684df33cd4efce2081e259ecc2317d [file] [log] [blame]
Thomas Vachuskaad37e372017-08-03 12:07:01 -07001#!/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
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080023ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
Thomas Vachuskaad37e372017-08-03 12:07:01 -070024ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
25
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080026. $(dirname $0)/_find-node
Thomas Vachuskaad37e372017-08-03 12:07:01 -070027
28node=$(find_node $1)
29yang=$2
30
31export URL=http://$node:8181/onos/yang/models
32export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy localhost "
33
34# Prints usage help
35function usage {
36 echo "usage: onos-compile-yang <yang-file|zip-file|jar-file|directory>" >&2
37 exit 1
38}
39
40[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
41
42if [ -d $yang ]; then
43 newYang=/tmp/$(basename $yang).jar
44 jar cf $newYang $yang
45 yang=$newYang
46fi
47
48file=$(basename $yang)
49modelId="$(echo $file | sed -E 's/(.zip|.jar|.yang)$//g')"
50curl $URL?modelId=$modelId -F"file=@$yang"