#!/bin/bash completion for ocicli

if [ -r /usr/share/openstack-cluster-installer/variables.json ] ; then
	VARIABLE_FILE=/usr/share/openstack-cluster-installer/variables.json
elif [ -r /etc/ocicli/variables.json ] ; then
	VARIABLE_FILE=/etc/ocicli/variables.json
fi

_ocicli() {
	local cur prev cmd_name
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	cmd_name="${COMP_WORDS[1]}"

	opts="machine-list machine-console machine-wipe machine-show machine-blk profile-list machine-guessed-profile machine-check-megacli-applied machine-megacli-apply machine-megacli-reset-raid machine-guess-racking machine-auto-add machine-auto-rack machine-to-dns machine-out-of-dns machine-out-of-monitoring machine-to-monitoring machine-gen-root-pass machine-forget-root-pass machine-report-counter-reset machine-set machine-add machine-remove machine-destroy machine-replace machine-reboot-on-hdd machine-reboot-on-live machine-ipmi-reboot-on-hdd machine-ipmi-reboot-on-live machine-hpe-ilo-license-install machine-hpe-activate-ipmi-over-lan machine-ipmi-cmd machine-install-os machine-display-install-cmd machine-install-log machine-set-ipmi machine-apply-ipmi machine-ip-add machine-ip-list machine-ip-remove machine-renew-ipmi-password ipmi-assign-check check-all-ipmi location-list location-create location-delete network-create network-list network-delete network-add network-remove network-set cluster-list cluster-create cluster-delete cluster-set cluster-show cluster-show-networks cluster-show-machines cluster-show-ips cluster-install cluster-reset cluster-rolecounts-list cluster-rolecounts-set swift-region-list swift-region-create swift-region-delete swift-calculate-ring swift-publish-ring role-list role-create role-delete filebeat-output-host-list filebeat-output-host-create filebeat-output-host-delete"
	iface_names="none eth0 eth1 eth2 eth3 eth4 eth5 10m1 10m2 10m3 10m4 100m1 100m2 100m3 100m4 1g1 1g2 1g3 1g4 10g1 10g2 10g3 10g4"

	case "${cmd_name}" in
	machine-list)
		if [ "${prev}" = "-o" ] || [ "${prev}" = "--order" ] ; then
			COMPREPLY=( $(compgen -W "hostname racking zoning" -- ${cur}) )
		else
			COMPREPLY=( $(compgen -W "--all --order -o --versions -v --status -s --zones -z --racking -r --network -n --ethernet -e --hardware -h --blockdevs -b --ipmi -i --links -l" -- ${cur}) )
		fi
		return 0
	;;
	machine-replace|machine-show|machine-blk|machine-apply-ipmi|machine-destroy|machine-reboot-on-hdd|machine-reboot-on-live|machine-ipmi-reboot-on-hdd|machine-ipmi-reboot-on-live|machine-hpe-ilo-license-install|machine-hpe-activate-ipmi-over-lan|machine-ipmi-cmd|machine-set-ipmi|machine-guessed-profile|machine-check-megacli-applied|machine-guess-racking|machine-auto-add|machine-auto-rack|machine-to-monitoring|machine-to-dns|machine-out-of-dns|machine-to-monitoring|machine-out-of-monitoring|machine-gen-root-pass|machine-forget-root-pass|machine-megacli-reset-raid|machine-report-counter-reset|machine-renew-ipmi-password)
		local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | cut -d, -f1 | tr \\n " ")
		local hostname_list=$(ocicli -csv machine-list | q -d, -H "SELECT hostname FROM - WHERE hostname!='-'" | cut -d, -f1 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
		return 0
	;;
	machine-check-megacli-applied|machine-megacli-apply)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | cut -d, -f1 | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list | q -d, -H "SELECT hostname FROM - WHERE hostname!='-'" | cut -d, -f1 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		3)
			local profile_list=$(ocicli -csv profile-list | q -d, -H "SELECT profile_name FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${profile_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-install-os|machine-display-install-cmd)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE cluster NOT LIKE '-' AND status='live'" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT hostname FROM - WHERE hostname!='-' AND cluster NOT LIKE '-' AND status='live'" | cut -d, -f1 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-install-log)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE cluster NOT LIKE '-' AND (status='installing' OR (status='installed' AND puppet='running'))" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT hostname FROM - WHERE cluster NOT LIKE '-' AND (status='installing' OR (status='installed' AND puppet='running'))" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-console|machine-wipe)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list | q -d, -H "SELECT hostname FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-remove)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE cluster NOT LIKE '-'" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT hostname FROM - WHERE cluster NOT LIKE '-'" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-set)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list | q -d, -H "SELECT hostname FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		3|5|7|9|11|13|15|17|19|21|23|25|27|29|31|33|35|37|39|41|43|45|47|49|51|53|55|57|59|61|63|65|67|69)
			ALL_OPTIONS=""
			if [ -r ${VARIABLE_FILE} ] ; then
				for OPTION in $(cat /etc/ocicli/variables.json | jq -r '.machines | keys[]' | tr '\n' ' ') ; do
					ALL_OPTIONS="${ALL_OPTIONS} --"$(echo ${OPTION} | sed 's/_/-/g')
				done
			fi
			COMPREPLY=( $(compgen -W "--use_ceph_if_available --dest-blk --install-on-raid --raid-type --raid-dev0 --raid-dev1 --raid-dev2 --raid-dev3 --raid-dev4 --serial-console-device --dc --row --rack --ustart --uend --use-gpu --gpu-name --gpu-vendor-id --gpu-produc-id --gpu-device-type --vfio-ids --nested-virt --cpu-mode --cpu-model --cpu-model-extra-flags --force-dhcp-agent --swift-store-account --swift-store-container --swift-store-object --hostname --notes --ipmi-use --ipmi-call-chassis-bootdev --ipmi-username --ipmi-password --ipmi-addr --ipmi-port --ipmi-netmask --ipmi-default-gw --ipmi-vlan --ceph-osd-initial-setup --force-no-bgp2host ${ALL_OPTIONS}" -- ${cur}) )
			return 0
		;;
		4|6|8|10|12|14|16|18|20|22|24|26|28|30|32|34|36|38|42|44|46|48|50|52|54|56|58|60|62|64|66|68|70)
			case "${prev}" in
                        "--use_ceph_if_available"|"--install-on-raid"|"--use-gpu"|"--swift-store-account"|"--swift-store-container"|"--swift-store-object"|"--force-dhcp-agent"|"--ipmi-call-chassis-bootdev"|"--ipmi-use"|"--force-no-bgp2host"|"--ceph-osd-initial-setup")
				COMPREPLY=( $(compgen -W "yes no" -- ${cur}) )
				return 0
			;;
                        "--nested-virt")
				COMPREPLY=( $(compgen -W "yes no cluster_value" -- ${cur}) )
				return 0
			;;
			"--dest-blk")
				local machine_name=${COMP_WORDS[2]}
				local blk_list=$(ocicli -csv machine-blk $machine_name | q -d, -H "SELECT name FROM -" | tr \\n " ")
				COMPREPLY=( $(compgen -W "$blk_list" -- ${cur}) )
				return 0
			;;
			"--raid-type")
				COMPREPLY=( $(compgen -W "0 1 10" -- ${cur}) )
				return 0
			;;
			"--raid-dev0"|"--raid-dev1"|"--raid-dev2"|"--raid-dev3")
				local machine_name=${COMP_WORDS[2]}
				local blk_list=$(ocicli -csv machine-blk $machine_name | q -d, -H "SELECT name FROM -" | tr \\n " ")
				COMPREPLY=( $(compgen -W "$blk_list" -- ${cur}) )
				return 0
			;;
			"--serial-console-device")
				COMPREPLY=( $(compgen -W "ttyS0 ttyS1 ttyS2 ttyS4 none" -- ${cur}) )
				return 0
			;;
			"--cpu-mode")
				COMPREPLY=( $(compgen -W "cluster_value host-model host-passthrough custom" -- ${cur}) )
				return 0
			;;
			"--cpu-model")
				COMPREPLY=( $(compgen -W "Broadwell-IBRS Broadwell-noTSX-IBRS Broadwell-noTSX Broadwell Conroe EPYC-IBPB EPYC Haswell-IBRS Haswell-noTSX-IBRS Haswell-noTSX Haswell IvyBridge-IBRS IvyBridge Nehalem-IBRS Nehalem Opteron_G1 Opteron_G2 Opteron_G3 Opteron_G4 Opteron_G5 Penryn SandyBridge-IBRS SandyBridge Skylake-Client-IBRS Skylake-Client Skylake-Server-IBRS Skylake-Server Westmere-IBRS Westmere athlon core2duo coreduo kvm32 kvm64 n270 pentium pentium2 pentium3 phenom qemu32 qemu64 base max" -- ${cur}) )
				return 0
			;;
			"--gpu-device-type")
				COMPREPLY=( $(compgen -W "type-PCI type-PF type-VF" -- ${cur}) )
				return 0
			;;
			*)
				return 0
			;;
			esac
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-add)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE cluster='null' OR cluster='-'" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} --fixed-ip" -- ${cur}) )
			return 0
		;;
		3)
			if [ ${COMP_WORDS[2]} = "--fixed-ip" ] ; then
				return 0
			fi
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		4)
			if [ ${COMP_WORDS[2]} = "--fixed-ip" ] ; then
				local serial_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE cluster='null' OR cluster='-'" | tr \\n " ")
				COMPREPLY=( $(compgen -W "${serial_list}" -- ${cur}) )
				return 0
			else
				local role_list=$(ocicli -csv role-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "${role_list}" -- ${cur}) )
				return 0
			fi
		;;
		5)
			if [ ${COMP_WORDS[2]} = "--fixed-ip" ] ; then
				local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
				return 0
			else
				local location_list=$(ocicli -csv location-list | grep -v "id,name,swiftregion" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "${location_list}" -- ${cur}) )
				return 0
			fi
		;;
		6)
			if [ ${COMP_WORDS[2]} = "--fixed-ip" ] ; then
				local role_list=$(ocicli -csv role-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "${role_list}" -- ${cur}) )
				return 0
			else
				return 0
			fi
		;;
		7)
			if [ ${COMP_WORDS[2]} = "--fixed-ip" ] ; then
				local location_list=$(ocicli -csv location-list | grep -v "id,name,swiftregion" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "${location_list}" -- ${cur}) )
				return 0
			else
				return 0
			fi
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-ip-remove)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list | q -d, -H "SELECT hostname FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		3)
			local ip_list=$(ocicli -csv machine-ip-list ${prev} | q -d, -H "SELECT ipaddr FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${ip_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-ip-add)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list | q -d, -H "SELECT serial FROM -" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list | q -d, -H "SELECT hostname FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list} ${hostname_list}" -- ${cur}) )
			return 0
		;;
		3)
			local network_list=$(ocicli -csv network-list | grep -v "name,ip,cidr" | cut -d, -f1 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${network_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	machine-ip-list)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE cluster='null' OR cluster='-'" | tr \\n " ")
			local hostname_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT hostname FROM - WHERE cluster='null' OR cluster='-'" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	cluster-set)
		case ${COMP_CWORD} in
		2)
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		3|5|7|9|11|13|15|17|19|21|23|25|27|29|31|33|35|37|39|41|43|45|47|49|51|53|55|57|59|61|63|65|67|69|71|73|75|77)
                        ALL_OPTIONS=""
			if [ -r ${VARIABLE_FILE} ] ; then
				for OPTION in $(cat /etc/ocicli/variables.json | jq -r '.clusters | keys[]' | tr '\n' ' ') ; do
					ALL_OPTIONS="${ALL_OPTIONS} --"$(echo ${OPTION} | sed 's/_/-/g')
				done
			fi
			COMPREPLY=( $(compgen -W "--time-server-host --nameserver-v4-primary --nameserver-v4-secondary --nameserver-v6-primary --nameserver-v6-secondary --region-name --vip-hostname --swift-part-power --swift-proxy-hostname --swift-encryption-key-id --swift-disable-encryption --swift-object-replicator-concurrency --swift-rsync-connection-limit --swift-public-cloud-middlewares --swift-ac-on-proxy --amp-secgroup-list --amp-boot-network-list --disable-notifications --enable-monitoring-graphs --monitoring-graphite-host --monitoring-graphite-port --self-signed-api-cert --statsd-hostname --initial-cluster-setup --extswift-use-external --extswift-auth-url --extswift-region --extswift-proxy-url --extswift-project-name --extswift-project-domain-name --extswift-user-name --extswift-user-domain-name --extswift-password --nested-virt --use-ovs-ifaces --cpu-mode --cpu-model --cpu-model-extra-flags --first-master --cephosd-automatic-provisionning ${ALL_OPTIONS}" -- ${cur}) )
			return 0
		;;
		4|6|8|10|12|14|16|18|20|22|24|26|28|30|32|34|36|38|40|42|44|46|48|50|52|54|56|58|60|62|64|66|68|70|72|74|76|78)
			if [ "${prev}" = "--swift-disable-encryption" ] || [ "${prev}" = "--disable-notifications" ] || [ "${prev}" = "--enable-monitoring-graphs" ] || [ "${prev}" = "--self-signed-api-cert" ]  || [ "${prev}" = "--initial-cluster-setup" ] || [ "${prev}" = "--swift-ac-on-proxy" ] || [ "${prev}" = "--extswift-use-external" ] || [ "${prev}" = "--nested-virt" ] || [ "${prev}" = "--use-ovs-ifaces" ] || [ "${prev}" = "--cephosd-automatic-provisionning" ]; then
				COMPREPLY=( $(compgen -W "yes no" -- ${cur}) )
			elif [ "${prev}" = "--cpu-mode" ] ; then
				COMPREPLY=( $(compgen -W "host-model host-passthrough custom" -- ${cur}) )
			elif [ "${prev}" = "--cpu-model" ] ; then
				COMPREPLY=( $(compgen -W "Broadwell-IBRS Broadwell-noTSX-IBRS Broadwell-noTSX Broadwell Conroe EPYC-IBPB EPYC Haswell-IBRS Haswell-noTSX-IBRS Haswell-noTSX Haswell IvyBridge-IBRS IvyBridge Nehalem-IBRS Nehalem Opteron_G1 Opteron_G2 Opteron_G3 Opteron_G4 Opteron_G5 Penryn SandyBridge-IBRS SandyBridge Skylake-Client-IBRS Skylake-Client Skylake-Server-IBRS Skylake-Server Westmere-IBRS Westmere athlon core2duo coreduo kvm32 kvm64 n270 pentium pentium2 pentium3 phenom qemu32 qemu64 base max" -- ${cur}) )
			elif [ "${prev}" = "--first-master" ] ; then
				local machine_list=$(ocicli -csv machine-list -a | q -d, -H "SELECT serial FROM - WHERE role='controller'" | tr \\n " ")
				COMPREPLY=( $(compgen -W "${machine_list}" -- ${cur}) )
			fi
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	cluster-rolecounts-set)
		case ${COMP_CWORD} in
		2)
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		3)
			local role_list=$(ocicli -csv role-list | q -H -d, "SELECT name FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${role_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	swift-calculate-ring)
		case ${COMP_CWORD} in
		2)
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		*)
			COMPREPLY=( $(compgen -W "--ec-only 1000 yes no" -- ${cur}) )
			return 0
		;;
		esac
	;;
	filebeat-output-host-create)
		case ${COMP_CWORD} in
		2)
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	filebeat-output-host-delete)
		case ${COMP_CWORD} in
		2)
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		3)
			local cluster_list=$(ocicli -csv filebeat-output-host-list ${COMP_WORDS[COMP_CWORD-1]} | q -H -d, "SELECT hostname FROM -" | tr '\n' ' ')
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		4)
			local cluster_list=$(ocicli -csv filebeat-output-host-list ${COMP_WORDS[COMP_CWORD-2]} | q -H -d, "SELECT port FROM -" | tr '\n' ' ')
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	cluster-show-machines|cluster-show-networks|cluster-show-ips|cluster-delete|cluster-show|cluster-install|cluster-reset|cluster-rolecounts-list|swift-publish-ring|filebeat-output-host-list)
		local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
		return 0
	;;
	network-remove)
		local network_list=$(ocicli -csv network-list | q -d, -H "SELECT name FROM - WHERE cluster_name NOT LIKE 'null' AND cluster_name NOT LIKE '-'" | cut -d, -f1 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${network_list}" -- ${cur}) )
		return 0
	;;
	network-add)
		case ${COMP_CWORD} in
		2)
			local serial_list=$(ocicli -csv network-list | q -d, -H "SELECT name FROM - WHERE cluster_name='null' OR cluster_name='-'" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${serial_list}" -- ${cur}) )
			return 0
		;;
		3)
			local cluster_list=$(ocicli -csv cluster-list | grep -v "id,name,domain" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${cluster_list}" -- ${cur}) )
			return 0
		;;
		4)
			local role_list=$(ocicli -csv role-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "all vm-net ovs-bridge ceph-cluster ipmi ${role_list}" -- ${cur}) )
			return 0
		;;
		5|6)
			COMPREPLY=( $(compgen -W "${iface_names}" -- ${cur}) )
			return 0
		;;
		*)
		;;
		esac
	;;
	network-create)
		case ${COMP_CWORD} in
		4)
			COMPREPLY=( $(compgen -W "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32" -- ${cur}) )
			return 0
		;;
		5)
			local location_list=$(ocicli -csv location-list | grep -v "id,name,swiftregion" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${location_list}" -- ${cur}) )
			return 0
		;;
		6)
			local location_list=$(ocicli -csv location-list | grep -v "id,name,swiftregion" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "yes no" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	network-delete)
		local network_list=$(ocicli -csv network-list | grep -v name,ip,cidr,is_public,cluster,role,iface1,iface2,location_id | cut -d, -f1 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${network_list}" -- ${cur}) )
		return 0
	;;
	network-set)
		case ${COMP_CWORD} in
		2)
			local network_list=$(ocicli -csv network-list | q -H -d, "SELECT name FROM -" | tr \\n " ")
			COMPREPLY=( $(compgen -W "${network_list}" -- ${cur}) )
			return 0
		;;
		3|5|7|9|11|13|15|17|19|21|23|25|27|29)
			COMPREPLY=( $(compgen -W "--role --iface1 --iface2 --ip --cidr --is-public --mtu --vlan --location --bridge-name --ipmi-match-addr --ipmi-match-cidr --first-ip --last-ip" -- ${cur}) )
			return 0
		;;
		4|6|8|10|12|14|16|18|20|22|24|26|28|30)
			case "${prev}" in
			"--role")
				local role_list=$(ocicli -csv role-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "all vm-net ${role_list}" -- ${cur}) )
				return 0
			;;
			"--iface1"|"--iface2")
				COMPREPLY=( $(compgen -W "${iface_names}" -- ${cur}) )
				return 0
			;;
			"--ip"|"--mtu"|"--vlan")
				return 0
			;;
			"--cidr"|"--ipmi-match-cidr")
				COMPREPLY=( $(compgen -W "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32" -- ${cur}) )
				return 0
			;;
			"--is-public")
				COMPREPLY=( $(compgen -W "yes no" -- ${cur}) )
				return 0
			;;
			"--location")
				local location_list=$(ocicli -csv location-list | grep -v "id,name,swiftregion" | cut -d, -f2 | tr \\n " ")
				COMPREPLY=( $(compgen -W "${location_list}" -- ${cur}) )
				return 0
			;;
			*)
				return 0
			;;
			esac
		;;
		*)
		;;
		esac
	;;
	role-delete)
		local role_list=$(ocicli -csv role-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${role_list}" -- ${cur}) )
		return 0
	;;
	swift-region-delete)
		local swiftregion_list=$(ocicli -csv swift-region-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${swiftregion_list}" -- ${cur}) )
		return 0
	;;
	location-create)
		case ${COMP_CWORD} in
		3)
			local swiftregion_list=$(ocicli -csv swift-region-list | grep -v "id,name" | cut -d, -f2 | tr \\n " ")
			COMPREPLY=( $(compgen -W "${swiftregion_list}" -- ${cur}) )
			return 0
		;;
		*)
			return 0
		;;
		esac
	;;
	location-delete)
		local location_list=$(ocicli -csv location-list | grep -v "id,name,swiftregion" | cut -d, -f2 | tr \\n " ")
		COMPREPLY=( $(compgen -W "${location_list}" -- ${cur}) )
		return 0
	;;
	*)
	;;
	esac

	COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
}

complete -F _ocicli ocicli
