blob: 744d955ae03c5bd9e015a9ba08bbc425d472356d [file] [log] [blame]
Ray Milkey5c0d8f92017-06-09 12:26:31 -07001#!/bin/bash
2
3
4#
Brian O'Connora09fe5b2017-08-03 21:12:30 -07005# Copyright 2015-present Open Networking Foundation
Ray Milkey5c0d8f92017-06-09 12:26:31 -07006#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19
20# -----------------------------------------------------------------------------
21# Utility for converting a number of a node in a cell to the node's address
22# -----------------------------------------------------------------------------
23
24validate_number () {
25 local re="^[0-9]+$"
26 if [[ ! $1 =~ $re ]] ; then
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080027 return 1
Ray Milkey5c0d8f92017-06-09 12:26:31 -070028 fi
Ray Milkey5c0d8f92017-06-09 12:26:31 -070029 return 0
30}
31
32find_node () {
33 if validate_number $1 ; then
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080034 # input is a number, try to find if an OC node is defined
35 oc_try="OC$1"
36 node=${!oc_try}
Ray Milkey5c0d8f92017-06-09 12:26:31 -070037
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080038 if [ -n "$node" ]; then
Ray Milkey5c0d8f92017-06-09 12:26:31 -070039 # node lookup succeeded, return node
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080040 echo $node
41 else
Ray Milkey5c0d8f92017-06-09 12:26:31 -070042 # node lookup failed, return original input
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080043 echo $1
44 fi
45 else
Ray Milkey5c0d8f92017-06-09 12:26:31 -070046 echo $1
47 fi
Ray Milkey5c0d8f92017-06-09 12:26:31 -070048 return 0
49}