Making REST API port as a command-line option for various admin commands.

Also cleaning up usage for consistency.

Change-Id: I1d8a10c063cab5992033b97d6efa60bba030ed9e
diff --git a/tools/package/runtime/bin/_rest-port b/tools/package/runtime/bin/_rest-port
new file mode 100644
index 0000000..15c2b15
--- /dev/null
+++ b/tools/package/runtime/bin/_rest-port
@@ -0,0 +1,44 @@
+#!/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 handling common REST API usage.
+# -----------------------------------------------------------------------------
+
+ONOS_WEB_USER=${ONOS_WEB_USER:-onos}  # ONOS WEB User defaults to 'onos'
+ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
+ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181}  # REST API port defaults to '8181'
+
+port=${ONOS_WEB_PORT}
+user=${ONOS_WEB_USER}
+password=${ONOS_WEB_PASS}
+fail="--fail"
+
+while getopts P:u:p:v?h o; do
+    case "$o" in
+        P) port=$OPTARG;;
+        u) user=$OPTARG;;
+        p) password=$OPTARG;;
+        v) fail="";;
+        *) usage;;
+    esac
+done
+
+let OPC=$OPTIND-1
+shift $OPC