| #!/bin/bash |
| |
| |
| # |
| # Copyright 2015-present Open Networking Foundation |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| # ----------------------------------------------------------------------------- |
| # Utility for converting a number of a node in a cell to the node's address |
| # ----------------------------------------------------------------------------- |
| |
| validate_number () { |
| local re="^[0-9]+$" |
| if [[ ! $1 =~ $re ]] ; then |
| return 1 |
| fi |
| return 0 |
| } |
| |
| find_node () { |
| if validate_number $1 ; then |
| # input is a number, try to find if an OC node is defined |
| oc_try="OC$1" |
| node=${!oc_try} |
| |
| if [ -n "$node" ]; then |
| # node lookup succeeded, return node |
| echo $node |
| else |
| # node lookup failed, return original input |
| echo $1 |
| fi |
| else |
| echo $1 |
| fi |
| return 0 |
| } |