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 |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 27 | return 1 |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 28 | fi |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 29 | return 0 |
| 30 | } |
| 31 | |
| 32 | find_node () { |
| 33 | if validate_number $1 ; then |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 34 | # input is a number, try to find if an OC node is defined |
| 35 | oc_try="OC$1" |
| 36 | node=${!oc_try} |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 37 | |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 38 | if [ -n "$node" ]; then |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 39 | # node lookup succeeded, return node |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 40 | echo $node |
| 41 | else |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 42 | # node lookup failed, return original input |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 43 | echo $1 |
| 44 | fi |
| 45 | else |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 46 | echo $1 |
| 47 | fi |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 48 | return 0 |
| 49 | } |