blob: 3f6547404eb45041fd06d8206dba8d062e3692ae [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
27 return 1
28 fi
29
30 return 0
31}
32
33find_node () {
34 if validate_number $1 ; then
35 # input is a number, try to find if an OC node is defined
36
37 oc_try="OC$1"
38 node=${!oc_try}
39
40 if [ -n "$node" ]; then
41 # node lookup succeeded, return node
42 echo $node
43 else
44 # node lookup failed, return original input
45 echo $1
46 fi
47
48 else
49 echo $1
50 fi
51
52 return 0
53}