Revert "Removing deprecated/unused/outdated code"
[osm/RO.git] / RO / osm_ro / scripts / RO-of
1 #!/bin/bash
2
3 ##
4 # Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
5 # This file is part of openmano
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 #         http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 #
20 ##
21
22 # author: Alfonso Tierno
23
24 # to get docker id that is running:
25 # $ docker_ro=`docker service ps osm_ro -f desired-state=running --format "{{.Name}}.{{.ID}}" --no-trunc`
26 # exec with:
27 # $ docker exec -ti $docker_ro RO-of
28
29 function get_from_db()
30 {
31     echo  "select $1 from $2 where name='$3' or uuid='$3';" | mysql -h"$RO_DB_HOST" -u"$RO_DB_OVIM_USER" -p"$RO_DB_OVIM_PASSWORD" "$RO_DB_OVIM_NAME"  2>/dev/null | tail -n1
32 }
33
34 [ -z "$RO_DB_OVIM_HOST" ] && export RO_DB_OVIM_HOST="$RO_DB_HOST"
35
36 if [ -z "$1" ] ; then
37     echo "usage '$0 <sdn_controller> command'"
38     echo
39     echo "available sdn_controllers are:"
40     echo  "select uuid, name, type, ip, dpid, status from ofcs;" | mysql -h"$RO_DB_HOST" -u"$RO_DB_OVIM_USER" -p"$RO_DB_OVIM_PASSWORD" "$RO_DB_OVIM_NAME"  2>/dev/null
41     exit
42 fi
43
44
45 export OF_CONTROLLER_DPID=`get_from_db dpid ofcs $1`
46 [ -z "$OF_CONTROLLER_DPID" ] && echo "Cannot find sdn_controller '$1' at database" >&2 && exit 1
47
48 export OF_CONTROLLER_IP=`get_from_db ip ofcs $1`
49 export OF_CONTROLLER_PORT=`get_from_db port ofcs $1`
50 export OF_CONTROLLER_USER=`get_from_db user ofcs $1`
51 export OF_CONTROLLER_PASSWORD=`get_from_db password ofcs $1`
52 export OF_CONTROLLER_TYPE=`get_from_db type ofcs $1`
53
54 shift
55 openflow-lib "$@"
56
57
58