Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
| 4 | # |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 5 | # Copyright 2015-present Open Networking Foundation |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 6 | # |
| 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 | |
| 24 | validate_number () { |
| 25 | local re="^[0-9]+$" |
| 26 | if [[ ! $1 =~ $re ]] ; then |
| 27 | return 1 |
| 28 | fi |
| 29 | |
| 30 | return 0 |
| 31 | } |
| 32 | |
| 33 | find_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 | } |