| Server IP : 152.69.216.235 / Your IP : 80.80.80.28 Web Server : Apache/2.4.37 (Oracle Linux Server) System : Linux ust-wp4-prod 5.15.0-310.184.5.2.el8uek.x86_64 #2 SMP Wed Jul 9 16:08:33 PDT 2025 x86_64 User : apache ( 48) PHP Version : 8.4.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /bin/ |
Upload File : |
#!/bin/bash
# Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
# This utility assists with configuring iscsi storage on Oracle Cloud
# Infrastructure instances. See the manual page for more information.
_PY3=/usr/bin/python3.6
_PY_CMD=oci_network_config_main.py
s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null`
declare COMMAND
declare cmd_line=""
declare -i post_operation_show=0
# included items. Can be a VNIC OCID, an IP address or a VLAN interface name.
declare -A INCLUDED_ITEMS
# excluded items. Can be a VNIC OCID, an IP address or a VLAN interface name.
declare -A EXCLUDED_ITEMS
# second IP address map indexed by VNIC ocid
declare -a SECONDARY_PRIVATE_IPS
declare -a SECONDARY_PRIVATE_VNICS
declare -i COUNT=0
# private ip when specified on --create-vnic or --configure action
declare PRIVATE_IP
declare VNIC_OCID
declare OCID_OR_IP
# former implementation of oci-network-config was mixing options and sub-commands.
# oci-network-config-main.py now expect proper command line like '<sub-command> <options>'
# translate the command line accordingly (as expected by new implementation)
# if first token does not start by '-' we consider that command line is following the new format
if [ "${1:0:1}" != '-' ]
then
if [ $# -eq 0 ]
then
# former behavior : no option means '--show'
exec ${_PY3} ${s_dir}/${_PY_CMD} show --compat-output
fi
# execute as is as the command line do not start with an option dash-<something>
exec ${_PY3} ${s_dir}/${_PY_CMD} $@
fi
PARSED_ARGUMENTS=$(getopt -a --quiet -o hsacde:n:rX:I:q --long help,show,create-vnic,nic-index:,ipv4,ipv6,detach-vnic:,add-private-ip,del-private-ip:,private-ip:,subnet:,vnic-name:,assign-public-ip,vnic:,auto,configure,deconfigure,ns,sshd,exclude:,include:,quiet -- "$@")
eval set -- "$PARSED_ARGUMENTS"
while :
do
case "$1" in
-s | --show) if [ -z ${COMMAND} ]
then
COMMAND="show --compat-output"
else
# display information after operation. Used to be an option
# change this to call ourself again with the show command
post_operation_show=1
fi
shift
;;
-a|--auto|-c|--configure) COMMAND="configure"; post_operation_show=1 ; shift ;;
-d|--deconfigure) COMMAND="unconfigure"; post_operation_show=1 ; shift ;;
--create-vnic) COMMAND="attach-vnic"; post_operation_show=1 ; shift ;;
--detach-vnic) COMMAND="detach-vnic"; OCID_OR_IP=$2 ; post_operation_show=1 ; shift 2 ;;
--add-private-ip) COMMAND="add-secondary-addr"; post_operation_show=1 ; shift ;;
--del-private-ip) COMMAND="remove-secondary-addr" ; cmd_line="${cmd_line} --ip-address=$2"; post_operation_show=1 ; shift 2 ;;
-X|--exclude) if [ -z ${COMMAND} ]
then
COMMAND="show --compat-output";
cmd_line="${cmd_line} --exclude $2"
else
EXCLUDED_ITEMS[${COMMAND}]+="$2"
fi
shift 2
;;
-I|--include) if [ -z ${COMMAND} ]
then
COMMAND="show --compat-output";
cmd_line="${cmd_line} --include $2"
else
EXCLUDED_ITEMS[${COMMAND}]+="$2"
fi
shift 2
;;
-q|--quiet) cmd_line="${cmd_line} --quiet" ; shift ;;
-e) SECONDARY_PRIVATE_IPS[$COUNT]+="$2"; COUNT=COUNT+1 ; shift 2 ;;
-n|--ns) cmd_line="${cmd_line} --namespace=$2" ; shift 2 ;;
-r|--sshd) cmd_line="${cmd_line} --start-sshd" ; shift ;;
--vnic) VNIC_OCID=$2 ; shift 2 ;;
--vnic-name) cmd_line="${cmd_line} --name=$2" ; shift 2 ;;
--assign-public-ip) cmd_line="${cmd_line} --assign-public-ip" ; shift ;;
--subnet) cmd_line="${cmd_line} --subnet=$2" ; shift 2 ;;
--nic-index) cmd_line="${cmd_line} --nic-index=$2" ; shift 2 ;;
--private-ip) PRIVATE_IP=$2 ; shift 2 ;;
--ipv4) echo ""; echo "--ipv4 ia an invalid option in compatible mode"; echo ""; COMMAND="usage"; post_operation_show=0; break ;;
--ipv6) echo ""; echo "--ipv6 ia an invalid option in compatible mode"; echo ""; COMMAND="usage"; post_operation_show=0; break ;;
--help)
if [ -z ${COMMAND} ]
then
COMMAND="usage"
else
# not displaying the overall usage but command specific one.
cmd_line="${cmd_line} --help"
fi
break
;;
# end of parsing , everything getopt did not understood is after that , we do not care in our case
--) shift; break ;;
*) COMMAND="usage" ; break ;;
esac
done
shift $((OPTIND-1))
read -r -a LEFT_OVERS <<<"$@"
# special case for -e option. former syntax was '-e IP VNIC'. This cannot be handle
# with getopt. i.e "oci-network-config -e 1.2.3.4 foo -e 5.6.7.8 bar" is
# parsed as: -e '1.2.3.4' -e '5.6.7.8' -- 'foo' 'bar'
# So we consider -e option to be without argument and we fetch left overs during a second pass
# IF we have parsed -e option VNIC ocid will be within LEFT_OVERS
for (( i=0; i<${#SECONDARY_PRIVATE_IPS[@]}; i++ ))
do
cmd_line="$cmd_line --secondary-ip ${SECONDARY_PRIVATE_IPS[$i]} ${LEFT_OVERS[$i]}"
done
if [ -z "${COMMAND}" ]
then
COMMAND="show"
cmd_line="--compat-output"
fi
if [ -n "${OCID_OR_IP}" ]
then
if [ ${OCID_OR_IP:0:6} == 'ocid1.' ]
then
cmd_line="${cmd_line} --ocid=${OCID_OR_IP}"
else
cmd_line="${cmd_line} --ip-address=${OCID_OR_IP}"
fi
fi
if [ "${COMMAND}" == "attach-vnic" ]
then
if [ -n "${PRIVATE_IP}" ]
then
cmd_line="${cmd_line} --ip-address=${PRIVATE_IP}"
fi
elif [ "${COMMAND}" == "detach-vnic" ]
then
if [ -n "${VNIC_OCID}" ]
then
cmd_line="$cmd_line --ocid=${VNIC_OCID}"
fi
if [ -n "${PRIVATE_IP}" ]
then
cmd_line="$cmd_line --ip-address=${PRIVATE_IP}"
fi
# else
# obsolete comment # if we have found --private-ip and --vnic we gonne add an ip to a vnic
# if [ -n "${VNIC_OCID}" ] && [ -n "${PRIVATE_IP}" ]
# then
# force command to be
# COMMAND="add-secondary-addr"
# cmd_line="$cmd_line --ip-address=${PRIVATE_IP} --ocid=${VNIC_OCID}"
# fi
elif [ "${COMMAND}" == "add-secondary-addr" ]
then
# --vnic is an option for --add-private-ip only, the requirement for --private-ip is not necessary
# and the --vnic option should only be required if there is more than 1 vnic.
# if --vnic option specified, translate to --ocid optione
if [ -n "${VNIC_OCID}" ]
then
cmd_line="$cmd_line --ocid=${VNIC_OCID}"
fi
if [ -n "${PRIVATE_IP}" ]
then
cmd_line="$cmd_line --ip-address=${PRIVATE_IP}"
fi
# else
# echo "_GT_ ${COMMAND} handled elsewhere"
fi
if [ ${EXCLUDED_ITEMS[${COMMAND}]+_} ] && [ -n "${EXCLUDED_ITEMS[${COMMAND}]}" ]
then
for i in ${EXCLUDED_ITEMS[${COMMAND}]}
do
cmd_line="${cmd_line} --exclude ${i}"
done
fi
if [ ${INCLUDED_ITEMS[${COMMAND}]+_} ] && [ -n "${INCLUDED_ITEMS[${COMMAND}]}" ]
then
for i in ${INCLUDED_ITEMS[${COMMAND}]}
do
cmd_line="${cmd_line} --include ${i}"
done
fi
if [ $post_operation_show -eq 1 ]
then
${_PY3} ${s_dir}/${_PY_CMD} $COMMAND ${cmd_line}
# print things as we used to do : include system interface as table , vnic as list etc..
if [ $? -eq 0 ]
then
exec ${_PY3} ${s_dir}/${_PY_CMD} show --compat-output
fi
else
exec ${_PY3} ${s_dir}/${_PY_CMD} $COMMAND ${cmd_line}
fi