#!/bin/sh

set -e

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

usage (){
	echo $(basename $0)": configure your baremetal cluster through the OCI API."
	echo "See the ocicli(1) manpage for details on parameters."
	echo "Here's just a quick list of what can be done with $0."
	echo "Note that the OCI_API_URL must be set in order to run $0."
	echo ""
	echo $(basename $0)" <action>"
	echo ""
	echo "Actions are:"
	echo "  machine-list [-a|--all -v|--versions -s|--status -z|--zones -r|--racking -n|--network -h|--hardware -i|--blockdevs -b|--ipmi |--links -l]"
	echo "  machine-show <machine_serial>"
	echo "  machine-set <machine_serial> --ceph-use-if-available <yes/no> --ceph-az <0/1/2/3/4/5/6/7/8/9>--install-on-raid <yes/no> --raid-type <0/1/10/5> --raid-dev0 sda --raid-dev1 sdb --raid-dev2 sdc --raid-dev3 sdd --serial-console-device <ttyS0/ttyS1/none> --dc --row --rack --ustart --uend --use-gpu --gpu-name --gpu-vendor-id --gpu-produc-id --vfio-ids <ids> --gpu-device-type <type-PCI/type-PF/type-VF> --cpu-mode <host-model/host-passthrough/custom/cluster_value> --cpu-model <MODEL> --cpu-model-extra-flags <FLAG1,FLAG2> --nested-virt <yes/no> --swift-store-account <yes/no> --swift-store-container <yes/no> --swift-store-object <yes/no> --hostname <hostname> --servers-per-port <int> --disk-chunk-size <int> --network-chunk-size <int> --ceph-osd-initial-setup <yes/no> --force-no-bgp2host <yes/no> [--lvm-backend-name <LVM_HDD_1>] [--notes <NOTE>]"
	echo "  machine-add [--fixed-ip <ip-addr>] <machine_serial> <cluster_name> <role_name> <location_name>: add a machine to a cluster"
	echo "  machine-remove <machine_serial>: remove a machine from a cluster"
	echo "  machine-destroy <machine_serial>: completely remove a machine from OCI's db"
	echo "  machine-display-install-cmd <machine_serial>: display install command (without running it)"
	echo "  machine-reboot-on-hdd <machine_serial>"
	echo "  machine-reboot-on-live <machine_serial>"
	echo "  machine-ipmi-reboot-on-hdd <machine_serial>"
	echo "  machine-ipmi-reboot-on-live <machine_serial>"
	echo "  machine-hpe-ilo-license-install <machine_serial>"
	echo "  machine-activate-ipmi-over-lan <machine_serial>"
	echo "  machine-ipmi-cmd <machine_serial> <command>"
	echo "  machine-ipmi-assign-ip <machine_serial> <ipmi-network>"
	echo "  machine-ipmi-adopt <machine_serial>"
	echo "  machine-install-os <machine_serial>"
	echo "  machine-install-log <machine_serial>"
	echo "  machine-set-ipmi [--do-ipmitool-cmds] [--ipmi-defgw GATEWAY] [--ipmi-netmask NETMASK] [--ipmi-call-chassis-bootdev yes/no] <serial> <use-ipmi:yes/no> <ipmi-ip-addr> <ipmi-port> <ipmi-username> <ipmi-password>"
	echo "  machine-apply-ipmi <machine_serial>"
	echo "  machine-console <machine_serial>"
	echo "  machine-ip-list <machine_serial>"
	echo "  machine-ip-add <machine_serial> <network-name> <ip-address>"
	echo "  machine-ip-remove <machine_serial> <ip-address>"
	echo "  machine-guessed-profile <machine_serial> [-d --debug]"
	echo "  machine-check-megacli-applied <machine_serial> [hardware_profile_name]"
	echo "  machine-megacli-apply <machine_serial> [hardware_profile_name]"
	echo "  machine-megacli-reset-raid <machine_serial>"
	echo "  machine-guess-racking <machine_serial>"
	echo "  machine-auto-rack <machine_serial>"
	echo "  machine-auto-add <machine_serial>"
	echo "  machine-to-dns <machine_serial>"
	echo "  machine-out-of-dns <machine_serial>"
	echo "  machine-to-monitoring <machine_serial>"
	echo "  machine-out-of-monitoring <machine_serial>"
	echo "  machine-gen-root-pass <machine_serial>"
	echo "  machine-forget-pass <machine_serial>"
	echo "  machine-report-counter-reset <machine_serial>"
	echo "  machine-renew-ipmi-password <machine_serial>"
	echo "  machine-replace <old_machine_serial> <new_machine_serial>"
	echo "  machine-wait-for-install <machine_serial>"
	echo "  machine-wait-for-puppet <machine_serial>"
	echo "  ipmi-assign-check"
	echo "  check-all-ipmi [filter]"
	echo "  password-list"
	echo "  password-show <id>"
	echo "  password-set <id> <password1> [password2]"
	echo ""
	echo "  network-list"
	echo "  network-set <network-name> [--cidr MASK] [--iface1 IFDEFINITION] [--iface2 IFDEFINITION] [--lldp-match SQL_MATCH_STRING] [--ip IPv4] [--is-public yes/no] [--location location-name] [--mtu MTU] [--role ROLE] [--vlan VLAN_NUM] [--bridge-name NAME] [--ipmi-match-addr <IP-ADDR>] [--ipmi-match-cidr <CIDR>] [--ipmi-mode <ocimanaged/externaldhcp>] [--nameserver-v4-primary <IPv4>] [--nameserver-v4-secondary <IPv4>] [--nameserver-v6-primary <IPv6>] [--nameserver-v6-secondary <IPv6>]"
	echo "  network-create <network-name> <ip> <cidr_mask> <location-name> <is-public:yes/no>"
	echo "  network-delete <network-name>"
	echo "  network-add <network-name> <cluster_name> <role_name> <iface1> <iface2>"
	echo "  network-remove <network-name>"
	echo ""
	echo "  location-list"
	echo "  location-create <location-name> <swiftregion-name>"
	echo "  location-delete <location-name>"
	echo ""
	echo "  swift-region-list"
	echo "  swift-region-create <swiftregion-name>"
	echo "  swift-region-delete <swiftregion-name>"
	echo ""
	echo "  swift-calculate-ring <cluster-name> [--ec-only] [<initial_account_weight> <initial_container_weight> <initial_object_weight>]"
	echo "  swift-add-machine-to-ring <machine_serial> [--ec-only] [<initial_account_weight> <initial_container_weight> <initial_object_weight>]"
	echo "  swift-publish-ring <cluster-name>"
	echo ""
	echo "  cluster-list"
	echo "  cluster-create <cluster-name> <domaine-name.com>"
	echo "  cluster-delete <cluster-name>"
	echo "  cluster-show <cluster-name>"
	echo "  cluster-set <cluster-name> [--time-server-host <time-server-hostname>] [--vip-hostname <hostname>] [--swift-part-power <int>] [--swift-proxy-hostname <hostname>] [--swift-encryption-key-id <UUID>] [--swift-disable-encryption <yes/no>] [--amp-secgroup-list <SECGROUP-UUID-LIST>] [ --amp-boot-network-list <AMP_BOOT_NETWORK_LIST>] [--disable-notifications <yes/no>] [--enable-monitoring-graphs <yes/no>] [--monitoring-graphite-host <hostname>] [--monitoring-graphite-port <port>] [--statsd-hostname <hostname>] [--extswift-use-external <yes/no>] [--extswift-auth-url <https://api.example.com/identity/v3>] [--extswift-proxy-url <https://prx.example.com/object/v1/AUTH_>] [--extswift-project-name <myproj>] [--extswift-project-domain-name <default>] [--extswift-user-name <myuser>] [--extswift-user-domain-name <default>] [--extswift-password <password>] [--self-signed-api-cert <yes/no>] [--use-ovs-ifaces <yes/no>] [--cpu-mode <host-model/host-passthrough/custom>] [--cpu-model <MODEL>] [--cpu-model-extra-flags <FLAG1,FLAG2>] [--nested-virt <yes/no>] [--first-master <machine_serial>] [--haproxy-timeout-http-request <time>] [--haproxy-timeout-queue <time>] [--haproxy-timeout-connect <time>] [--haproxy-timeout-client <time>] [--haproxy-timeout-server <time>] [--haproxy-timeout-check <time>] [--neutron-dnsmasq-dns-servers <list-of-nameservers>]"
	echo "  cluster-show-networks <cluster-name>"
	echo "  cluster-show-machines <cluster-name>"
	echo "  cluster-show-ips <cluster-name>"
	echo "  cluster-install <cluster-name>"
	echo "  cluster-reset <cluster-name>"
	echo "  cluster-rolecounts-list <cluster-name>"
	echo "  cluster-rolecounts-set <cluster-name> <role> <count>"
	echo ""
	echo "  role-list"
	echo "  role-create <name>"
	echo "  role-delete <name>"
	echo ""
	echo "  filebeat-output-host-list <cluster-name>"
	echo "  filebeat-output-host-create <cluster-name> <hostname> <port>"
	echo "  filebeat-output-host-delete <cluster-name> <hostname> <port>"
	exit 1
}

# Parameter: $1 = URL param
# return: API_RESPONSE_FILE
# The function exits printing API message if status != success
ocicli_call (){
	local STATUS MESSAGE URL_PARAM
	if [ -z "${1}" ] ; then
		echo "Missing URL_PARAM when calling ocicli_call()"
		exit 1
	fi
	URL_PARAM="${1}"

	if [ -n "${OCI_LOGIN}" ] && [ -n "${OCI_PASS}" ] ; then
		URL_PARAM="${URL_PARAM}&oci_login=${OCI_LOGIN}&oci_pass=${OCI_PASS}"
	fi

	API_RESPONSE_FILE=$(mktemp -t oci-poc-install-cluster.XXXXXX)
	if [ "${DEBUG}" = "on" ] ; then
		echo "curl -s \"${OCI_API_URL}${URL_PARAM}\""
	fi
	curl -s ${OCI_API_URL}${URL_PARAM} >${API_RESPONSE_FILE}
	STATUS=$(cat ${API_RESPONSE_FILE} | jq -r '.["status"]')
	if ! [ "${STATUS}" = "success" ] ; then
		echo "Could not query API:"
		MESSAGE=$(cat ${API_RESPONSE_FILE} | jq -r '.["message"]')
		echo $MESSAGE
		rm ${API_RESPONSE_FILE}
		exit 1
	fi
}

# Param: $1 size
# return: $RET smart string size
ocicli_smart_size (){
	local SIZE LEN
	SIZE=$1
	# PB
	if [ "${SIZE}" -gt $((1024 * 1024 * 1024 * 1024 * 1024 * 10)) ] ; then
		RET=$(( ${SIZE} / $((1024 * 1024 * 1024 * 1024 * 1024)) ))
		RET="${RET}PB"
	# TB
	elif [ "${SIZE}" -gt $((1024 * 1024 * 1024 * 1024 * 10)) ] ; then
		RET=$(( ${SIZE} / $((1024 * 1024 * 1024 * 1024)) ))
		RET="${RET}TB"
	# GB
	elif [ "${SIZE}" -gt $((1024 * 1024 * 1024 * 10)) ] ; then
		RET=$(( ${SIZE} / $((1024 * 1024 * 1024)) ))
		RET="${RET}GB"
	# MB
	elif [ "${SIZE}" -gt $((1024 * 1024 * 10)) ] ; then
		RET=$(( ${SIZE} / $((1024 * 1024)) ))
		RET="${RET}GB"
	# kB
	elif [ "${SIZE}" -gt $((1024 * 10)) ] ; then
		RET=$(( ${SIZE} / $((1024 )) ))
		RET="${RET}GB"
	# B
	else
		RET="${SIZE}B"
	fi
}

ocicli_password_list (){
	ocicli_call "action=password_list"

	for i in $@ ; do
	case "${1}" in
	"-f"|"--filter")
		FILTER_OPT=${2}
		shift
		shift
	;;
	esac
	done

	if [ -n "${FILTER_OPT}" ] ; then
		TR_FILTER_OPT=$(echo "${FILTER_OPT}" | tr ',' ' ')
		for FILTER in $TR_FILTER_OPT ; do
			FILTER_FLD=$(echo $FILTER | cut -d= -f1)
			FILTER_VAL=$(echo $FILTER | cut -d= -f2)
			F="${F} | select (.${FILTER_FLD} == \"${FILTER_VAL}\")"
		done
	fi

	echo "id,cluster,service,passtype,az"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"][] '"${F}"' | "\(.id),\(.cluster),\(.service),\(.passtype),\(.az)"'
}

ocicli_machine_list (){
	ocicli_call "action=machine_list"

	SORTING_FIELD=".serial"
	HEAD="serial,hostname,Cur_ip,status"
	# Default ordering: see -o option below.
	ORDERING=".role,(.hostname|length),.hostname,.product_name,.serial"
	HEAD_VERSION=""
	JQFL_VERSION=""
	HEAD_STATUS=""
	JQFL_STATUS=""
	HEAD_ZONE=""
	JQFL_ZONE=""
	HEAD_RACKING=""
	JQFL_RACKING=""
	HEAD_HARDWARE=""
	JQFL_HARDWARE=""
	HEAD_BLOCKDEVS=""
	JQFL_BLOCKDEVS=""
	HEAD_ETHERNET=""
	JQFL_ETHERNET=""
	HEAD_LINKS=""
	JQFL_LINKS=""
	HEAD_NETWORK=""
	JQFL_NETWORK=""
	HEAD_IPMI=""
	JQFL_IPMI=""
	FILTER_OPT=""

	if [ -z "${1}" ] ; then
		# This is if no parameter is given (ie: the default)
		echo -n ""
		JQFL='.["data"]|=sort_by(.cluster_name,'${ORDERING}')|.["data"][] | "\(.serial),\(.hostname),\(.ipaddr),\(.status)'
	else
		for i in $@ ; do
		case "${1}" in
		"-f"|"--filter")
			FILTER_OPT=${2}
			shift
			shift
		;;
		"-o"|"--order")
			case "${2}" in
			"hostname")
				ORDERING=".role,(.hostname|length),.hostname,.product_name,.serial"
			;;
			"racking")
				ORDERING=".role,.loc_dc,.loc_row,(.loc_rack|length),.loc_rack,(.loc_u_start|length),.loc_u_start"
			;;
			"zoning")
				ORDERING=".role,.swiftregion_name,.location_name,(.hostname|length),.hostname,.product_name,.serial"
			;;
			esac
			shift
			shift
		;;
		# Display all fields
		"-a"|"--all")
			HEAD_VERSION=',BIOSver,Lifecycle,IPMIver'
			JQFL_VERSION=',\(.bios_version),\(.dell_lifecycle_version),\(.ipmi_firmware_version)'
			HEAD_STATUS=',puppet,lastseen,role,cephosd'
			JQFL_STATUS=',\(.puppet_status),\(.lastseen),\(.role),\(.compute_is_cephosd)'
			HEAD_ZONE=',cluster,location,swiftregion,ceph_az'
			JQFL_ZONE=',\(.cluster_name),\(.location_name),\(.swiftregion_name),\(.ceph_az)'
			HEAD_RACKING=',notes,dc,row,rack,ustart,uend'
			JQFL_RACKING=',\(.notes),\(.loc_dc),\(.loc_row),\(.loc_rack),\(.loc_u_start),\(.loc_u_end)'
			HEAD_NETWORK=',dhcp_ip,ladvd'
			JQFL_NETWORK=',\(.dhcp_ip),\(.ladvd_report)'
			HEAD_HARDWARE=',system_manufacturer,product_name,memory,boot_uefi,secure_boot,nics,cpu_vendor,cpu_model_name,cpu_core_per_socket,cpu_sockets'
			JQFL_HARDWARE=',\(.system_manufacturer),\(.product_name),\(.memory),\(.boot_uefi),\(.secure_boot),\(.nics),\(.cpu_vendor),\(.cpu_model_name),\(.cpu_core_per_socket),\(.cpu_sockets)'
			HEAD_BLOCKDEVS=',blockdevices'
			JQFL_BLOCKDEVS=',\(.blockdevices)'
			HEAD_IPMI=',IPMI_IP,detected_ipmi_addr,ipmi_port,ipmi_username,ipmi_password'
			JQFL_IPMI=',\(.ipmi_addr),\(.ipmi_detected_ip),\(.ipmi_port),\(.ipmi_username),\(.ipmi_password)'
			shift
		;;
		# Display "versions": product_name, BIOS, Lifecycle and IPMI versions
		"-v"|"--versions")
			HEAD_VERSION=',BIOSver,Lifecycle,IPMIver'
			JQFL_VERSION=',\(.bios_version),\(.dell_lifecycle_version),\(.ipmi_firmware_version)'
			shift
		;;
		# Display "status": install status, puppet status, last seen time
		"-s"|"--status")
			HEAD_STATUS=',puppet,lastseen,role,cephosd'
			JQFL_STATUS=',\(.puppet_status),\(.lastseen),\(.role),\(.compute_is_cephosd)'
			shift
		;;
		# Display "zones": cluster, location and region names
		"-z"|"--zones")
			HEAD_ZONE=',cluster,location,swiftregion,ceph_az'
			JQFL_ZONE=',\(.cluster_name),\(.location_name),\(.swiftregion_name),\(.ceph_az)'
			shift
		;;
		# Display "racking": notes, and physical location infos
		"-r"|"--racking")
			HEAD_RACKING=',notes,dc,row,rack,ustart,uend'
			JQFL_RACKING=',\(.notes),\(.loc_dc),\(.loc_row),\(.loc_rack),\(.loc_u_start),\(.loc_u_end)'
			shift
		;;
		# Display "network": current IP, DHCP IP, ladvd
		"-n"|"--network")
			HEAD_NETWORK=',dhcp_ip,ladvd,mgmt_ip'
			JQFL_NETWORK=',\(.dhcp_ip),\(.ladvd_report),\(.mgmt_ip)'
			shift
		;;
		# Display "hardware": product_name, memory
		"-h"|"--hardware")
			HEAD_HARDWARE=',system_manufacturer,product_name,memory,boot_uefi,secure_boot,cpu_vendor,cpu_model_name,cpu_core_per_socket,cpu_sockets'
			JQFL_HARDWARE=',\(.system_manufacturer),\(.product_name),\(.memory),\(.boot_uefi),\(.secure_boot),\(.cpu_vendor),\(.cpu_model_name),\(.cpu_core_per_socket),\(.cpu_sockets)'
			shift
		;;
		# Display "hardware": product_name, memory
		"-b"|"--blockdevs")
			HEAD_BLOCKDEVS=',blockdevices'
			JQFL_BLOCKDEVS=',\(.blockdevices)'
			shift
		;;
		"-e"|"--ethernet")
			HEAD_ETHERNET=',nics'
			JQFL_ETHERNET=',\(.nics)'
			shift
		;;
		"-l"|"--links")
			HEAD_LINKS=',links'
			JQFL_LINKS=',\(.links)'
			shift
		;;
		# Display "IPMI":
		"-i"|"--ipmi")
			HEAD_IPMI=',IPMI_IP,detected_ipmi_addr,ipmi_port,ipmi_username,ipmi_password'
			JQFL_IPMI=',\(.ipmi_addr),\(.ipmi_detected_ip),\(.ipmi_port),\(.ipmi_username),\(.ipmi_password)'
			shift
		;;
		*)
		;;
		esac
		done

		if [ -n "${FILTER_OPT}" ] ; then
			TR_FILTER_OPT=$(echo "${FILTER_OPT}" | tr ',' ' ')
			for FILTER in $TR_FILTER_OPT ; do
				FILTER_FLD=$(echo $FILTER | cut -d= -f1)
				FILTER_VAL=$(echo $FILTER | cut -d= -f2)
				F="${F} | select (.${FILTER_FLD} == \"${FILTER_VAL}\")"
			done
		fi

		JQFL='.["data"]|=sort_by('${ORDERING}')|.["data"][] '"${F}"'| "\(.serial),\(.hostname),\(.ipaddr),\(.status)'

		HEAD="${HEAD}${HEAD_VERSION}${HEAD_ETHERNET}${HEAD_HARDWARE}${HEAD_BLOCKDEVS}${HEAD_STATUS}${HEAD_NETWORK}${HEAD_LINKS}${HEAD_IPMI}${HEAD_ZONE}${HEAD_RACKING}"
		JQFL="${JQFL}${JQFL_VERSION}${JQFL_ETHERNET}${JQFL_HARDWARE}${JQFL_BLOCKDEVS}${JQFL_STATUS}${JQFL_NETWORK}${JQFL_LINKS}${JQFL_IPMI}${JQFL_ZONE}${JQFL_RACKING}"
	fi
	JQFL=${JQFL}'"'

	echo ${HEAD}
	cat ${API_RESPONSE_FILE} | jq -r "${JQFL}"
#	if [ "${1}" = "-a" ] ; then
#		echo "serial,Cur_ip,dhcp_ip,memory,status,puppet,lastseen,cluster,location,swiftregion,ladvd,product_name,BIOSver,Lifecycle,IPMIver,IPMI_IP,hostname,notes,dc,row,rack,ustart,uend"
#		cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.product_name,.serial)|.["data"][] | "\(.serial),\(.ipaddr),\(.dhcp_ip),\(.memory),\(.status),\(.puppet_status),\(.lastseen),\(.cluster_name),\(.location_name),\(.swiftregion_name),\(.ladvd_report),\(.product_name),\(.bios_version),\(.dell_lifecycle_version),\(.ipmi_firmware_version),\(.ipmi_detected_ip),\(.hostname),\(.notes),\(.loc_dc),\(.loc_row),\(.loc_rack),\(.loc_u_start),\(.loc_u_end)"'
#	else
#		echo "serial,Cur_ip,status,puppet,cluster,IPMI_IP,hostname"
#		cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.product_name,.serial)|.["data"][] | "\(.serial),\(.ipaddr),\(.status),\(.puppet_status),\(.cluster),\(.ipmi_detected_ip),\(.hostname)"'
#	fi
}

ocicli_machine_show (){
	local ROLES OPTION DISPLAY role DESCR SIZE_MB SIZE_GB network_name SPEED MACADDR H_SPEED MACADDR DISPLAY_SPEED CNT
	ocicli_call "action=machine_show&machine_serial=${1}"
#	echo "Attribute,value"
	# Normal attributes
	OCICLI_MACHINE_SHOW_SERIAL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.serial)"')
	OCICLI_MACHINE_SHOW_IPADDR=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipaddr)"')
	OCICLI_MACHINE_SHOW_MEMORY=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.memory)"')
	OCICLI_MACHINE_SHOW_STATUS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.status)"')
	OCICLI_MACHINE_SHOW_CLUSTER_ID=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cluster)"')
	OCICLI_MACHINE_SHOW_PUPPET=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.puppet_status)"')
	OCICLI_MACHINE_SHOW_LASTSEEN=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.lastseen)"')
	OCICLI_MACHINE_SHOW_REPORT_COUNTER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.report_counter)"')
	OCICLI_MACHINE_SHOW_ROLE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.role)"')
	OCICLI_MACHINE_SHOW_LADVD=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ladvd_report)"')
	OCICLI_MACHINE_SHOW_SYSTEM_MANUFACTURER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.system_manufacturer)"')
	OCICLI_MACHINE_SHOW_PRODUCT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.product_name)"')
	OCICLI_MACHINE_SHOW_BIOS_VER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.bios_version)"')
	OCICLI_MACHINE_SHOW_BOOT_UEFI=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.boot_uefi)"')
	OCICLI_MACHINE_SHOW_SECURE_BOOT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.secure_boot)"')
	OCICLI_MACHINE_SHOW_DELL_LIFECYCLE_VER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.dell_lifecycle_version)"')
	OCICLI_MACHINE_SHOW_LADVD_REPORT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ladvd_report)"')

	# CPU infos
	OCICLI_MACHINE_SHOW_CPU_VENDOR=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_vendor)"')
	OCICLI_MACHINE_SHOW_CPU_THREADS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_threads)"')
	OCICLI_MACHINE_SHOW_CPU_CORE_PER_SOCKET=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_core_per_socket)"')
	OCICLI_MACHINE_SHOW_CPU_SOCKETS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_sockets)"')
	OCICLI_MACHINE_SHOW_CPU_MODEL_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_model_name)"' | sed s/,//g)
	OCICLI_MACHINE_SHOW_CPU_MHZ=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_mhz)"')

	# Location attributes
	OCICLI_MACHINE_SHOW_LOC_DC=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.loc_dc)"')
	OCICLI_MACHINE_SHOW_LOC_ROW=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.loc_row)"')
	OCICLI_MACHINE_SHOW_LOC_RACK=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.loc_rack)"')
	OCICLI_MACHINE_SHOW_LOC_USTART=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.loc_u_start)"')
	OCICLI_MACHINE_SHOW_LOC_UEND=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.loc_u_end)"')
	OCICLI_MACHINE_SHOW_NOTES=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.notes)"')


	OCICLI_MACHINE_SHOW_IPMI_VER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_firmware_version)"')
	OCICLI_MACHINE_SHOW_IPMI_DETECTED_IP=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_detected_ip)"')
	OCICLI_MACHINE_SHOW_USE_IPMI=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_use)"')
	OCICLI_MACHINE_SHOW_CALL_IPMI_BOOTDEV=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_call_chassis_bootdev)"')
	OCICLI_MACHINE_SHOW_IPMI_ADDR=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_addr)"')
	OCICLI_MACHINE_SHOW_IPMI_PORT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_port)"')
	OCICLI_MACHINE_SHOW_IPMI_VLAN=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_vlan)"')
	OCICLI_MACHINE_SHOW_IPMI_NETMASK=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_netmask)"')
	OCICLI_MACHINE_SHOW_IPMI_DEFAULT_GW=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_default_gw)"')
	OCICLI_MACHINE_SHOW_IPMI_USERNAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_username)"')
	OCICLI_MACHINE_SHOW_IPMI_PASSWORD=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ipmi_password)"')

	OCICLI_MACHINE_SHOW_HOSTNAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.hostname)"')
	OCICLI_MACHINE_SHOW_NOTES=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.notes)"')
	OCICLI_MACHINE_SHOW_USE_CEPH=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.use_ceph_if_available)"')
	OCICLI_MACHINE_SHOW_NESTED_VIRT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nested_virt)"')

	OCICLI_MACHINE_SHOW_DEST_BLK=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.dest_blk)"')
	OCICLI_MACHINE_SHOW_INSTALL_ON_RAID=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.install_on_raid)"')
	OCICLI_MACHINE_SHOW_RAID_TYPE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.raid_type)"')
	OCICLI_MACHINE_SHOW_RAID_DEV0=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.raid_dev0)"')
	OCICLI_MACHINE_SHOW_RAID_DEV1=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.raid_dev1)"')
	OCICLI_MACHINE_SHOW_RAID_DEV2=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.raid_dev2)"')
	OCICLI_MACHINE_SHOW_RAID_DEV3=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.raid_dev3)"')

	OCICLI_MACHINE_SHOW_SERIAL_CONSOLE_DEV=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.serial_console_dev)"')

	OCICLI_MACHINE_SHOW_USE_GPU=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.use_gpu)"')
	OCICLI_MACHINE_SHOW_GPU_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.gpu_name)"')
	OCICLI_MACHINE_SHOW_GPU_VENDOR_ID=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.gpu_vendor_id)"')
	OCICLI_MACHINE_SHOW_GPU_PRODUCT_ID=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.gpu_product_id)"')
	OCICLI_MACHINE_SHOW_GPU_DEVICE_TYPE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.gpu_device_type)"')
	OCICLI_MACHINE_SHOW_VFIO_IDS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.vfio_ids)"')

	# From cluster
	OCICLI_MACHINE_SHOW_CLUSTER_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.machine_cluster.name)"')

	OCICLI_MACHINE_SHOW_CPU_MODE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_mode)"')
	OCICLI_MACHINE_SHOW_CPU_MODEL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_model)"')
	OCICLI_MACHINE_SHOW_CPU_MODEL_EXTRA_FLAGS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_model_extra_flags)"')
	OCICLI_MACHINE_SHOW_HW_MACHINE_TYPE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.hw_machine_type)"')
	OCICLI_MACHINE_SHOW_FORCE_DHCP_AGENT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.force_dhcp_agent)"')
	OCICLI_MACHINE_SHOW_NOVA_SKIP_CPU_COMPARE_ON_DEST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nova_skip_cpu_compare_on_dest)"')
	OCICLI_MACHINE_SHOW_NOVA_SKIP_CPU_COMPARE_AT_STARTUP=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nova_skip_cpu_compare_at_startup)"')
	OCICLI_MACHINE_SHOW_NOVA_SKIP_HYPERVISOR_VERSION_CHECK_ON_LM=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nova_skip_hypervisor_version_check_on_lm)"')

	OCICLI_MACHINE_SHOW_SWIFT_STORE_ACCOUNT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_store_account)"')
	OCICLI_MACHINE_SHOW_SWIFT_STORE_CONTAINER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_store_container)"')
	OCICLI_MACHINE_SHOW_SWIFT_STORE_OBJECT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_store_object)"')

	OCICLI_MACHINE_SHOW_CEPH_OSD_INITIAL_SETUP=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.ceph_osd_initial_setup)"')
	OCICLI_MACHINE_SHOW_FORCE_NO_BGP2HOST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.force_no_bgp2host)"')
	OCICLI_MACHINE_SHOW_FORCE_FRR=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.force_frr)"')
	OCICLI_MACHINE_SHOW_FORCE_FRR_NIC1=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.force_frr_nic1)"')
	OCICLI_MACHINE_SHOW_FORCE_FRR_NIC2=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.force_frr_nic2)"')
	OCICLI_MACHINE_SHOW_FORCE_FRR_VLAN=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.force_frr_vlan)"')

	echo "Field,Value"
	echo "===== MACHINE ID =====,==============================================="
	echo "Serial:,${OCICLI_MACHINE_SHOW_SERIAL}"
	echo "Hostname:,${OCICLI_MACHINE_SHOW_HOSTNAME}"

	echo "====== CLUSTER =======,==============================================="
	echo "Cluster name:,${OCICLI_MACHINE_SHOW_CLUSTER_NAME}"
	echo "Cluster ID:,${OCICLI_MACHINE_SHOW_CLUSTER_ID}"
	echo "Role:,${OCICLI_MACHINE_SHOW_ROLE}"
	echo "Location:,DC:${OCICLI_MACHINE_SHOW_LOC_DC}/Row:${OCICLI_MACHINE_SHOW_LOC_ROW}/Rack:${OCICLI_MACHINE_SHOW_LOC_RACK}/U:${OCICLI_MACHINE_SHOW_LOC_USTART}-${OCICLI_MACHINE_SHOW_LOC_UEND}"
	echo "Notes:,${OCICLI_MACHINE_SHOW_NOTES}"

	echo "=== INSTALL STATUS ===,==============================================="
	echo "Status:,${OCICLI_MACHINE_SHOW_STATUS}"
	echo "Puppet:,${OCICLI_MACHINE_SHOW_PUPPET}"
	echo "Last report date:,${OCICLI_MACHINE_SHOW_LASTSEEN}"
	echo "Report counter:,${OCICLI_MACHINE_SHOW_REPORT_COUNTER}"

	echo "=== HARDWARE SPECS ===,==============================================="
	echo "System manufacturer:,${OCICLI_MACHINE_SHOW_SYSTEM_MANUFACTURER}"
	echo "Product name:,${OCICLI_MACHINE_SHOW_PRODUCT}"
	echo "Memory:,${OCICLI_MACHINE_SHOW_MEMORY}"
	echo "BIOS version:,${OCICLI_MACHINE_SHOW_BIOS_VER}"
	echo "Boot over UEFI:,${OCICLI_MACHINE_SHOW_BOOT_UEFI}"
	echo "Secure boot:,${OCICLI_MACHINE_SHOW_SECURE_BOOT}"
	echo "Dell Lifecycle:,${OCICLI_MACHINE_SHOW_DELL_LIFECYCLE_VER}"
	echo -n "Block devices:,"
	for i in $(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.machine_blockdevices)"' | jq -r '.[].name') ; do
		SIZE_MB=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_blockdevices"] | last(.[] | select(.name == "'${i}'")) | .["size_mb"]')
		SIZE_GB=$((${SIZE_MB} / 1024))
		echo -n "${i}:${SIZE_GB}G "
	done
	echo ""

	if cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_phys_blockdevices"][]' 1>/dev/null 2>/dev/null ; then
		echo -n "Physical block devices:,"
		CNT=0
		for i in $(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.machine_phys_blockdevices)"' | jq -r '.[].id') ; do
			PBD_MODEL=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["machine_phys_blockdevices"][] | select(.id == "'${i}'") | .["model"]')
			PBD_SERIAL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_phys_blockdevices"][] | select(.id == "'${i}'") | .["serial"]')
			PBD_SIZE=$(cat ${API_RESPONSE_FILE}   | jq -r '.["data"]["machine_phys_blockdevices"][] | select(.id == "'${i}'") | .["size"]')
			ocicli_smart_size ${PBD_SIZE}
			PBD_SIZE=${RET}
			PBD_STATE=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["machine_phys_blockdevices"][] | select(.id == "'${i}'") | .["state"]')

			if [ ${CNT} -ge 1 ] ; then
				echo ""
				echo -n " ,"
			fi
			echo -n "slot${i}:${PBD_MODEL}:${PBD_SERIAL}:${PBD_SIZE}:${PBD_STATE}"
			CNT=$(( ${CNT} + 1 ))
		done
		echo ""
	fi

	if cat ${API_RESPONSE_FILE} | jq -r '.["data"]["blkdev_ctrl"][]' 1>/dev/null 2>/dev/null ; then
		echo -n "Block device controllers:,"
		CNT=0
		for i in $(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.blkdev_ctrl)"' | jq -r '.[].id') ; do
			HWID=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["blkdev_ctrl"][] | select(.id == "'${i}'") | .["hwid"]')
			BDC_VENDOR=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["blkdev_ctrl"][] | select(.id == "'${i}'") | .["vendor"]')
			BDC_PRODUCT=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["blkdev_ctrl"][] | select(.id == "'${i}'") | .["product"]')
			BDC_TYPE=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["blkdev_ctrl"][] | select(.id == "'${i}'") | .["ctrl_type"]')
			BDC_FW_VER=$(cat ${API_RESPONSE_FILE}  | jq -r '.["data"]["blkdev_ctrl"][] | select(.id == "'${i}'") | .["firmware_version"]')
			if [ ${CNT} -ge 1 ] ; then
				echo ""
				echo -n " ,"
			fi
			echo -n "${HWID}:${BDC_VENDOR}:${BDC_PRODUCT}:${BDC_TYPE}:${BDC_FW_VER}"
			CNT=$(( ${CNT} + 1 ))
		done
		echo ""
	fi

	echo -n "Interfaces:,"
	CNT=0
	for i in $(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.machine_ifs)"' | jq -r '.[].name') ; do
		SPEED=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_ifs"][] | select(.name == "'${i}'") | .["max_speed"]')
		MACADDR=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_ifs"][] | select(.name == "'${i}'") | .["macaddr"]')
		DRIVER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_ifs"][] | select(.name == "'${i}'") | .["driver"]')
		FW_VERS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["machine_ifs"][] | select(.name == "'${i}'") | .["firmware_version"]')
		if [ "${SPEED}" -lt 1000 ] ; then
			H_SPEED="${SPEED}Mb/s"
		else
			DISPLAY_SPEED=$(( ${SPEED} / 1000 ))
			H_SPEED="${DISPLAY_SPEED}Gb/s"
		fi

		if [ ${CNT} -ge 1 ] ; then
			echo ""
			echo -n " ,"
		fi

		echo -n "${i} (${MACADDR}@${H_SPEED} ${DRIVER} ${FW_VERS}) "
		CNT=$(( ${CNT} + 1 ))
	done
	echo ""

	echo "==== CPU =============,==============================================="
	echo "Vendor:,${OCICLI_MACHINE_SHOW_CPU_VENDOR}"
	echo "Model name:,${OCICLI_MACHINE_SHOW_CPU_MODEL_NAME}"
	echo "MHz:,${OCICLI_MACHINE_SHOW_CPU_MHZ}"
	echo "Threads:,${OCICLI_MACHINE_SHOW_CPU_THREADS}"
	echo "Core per socket:,${OCICLI_MACHINE_SHOW_CPU_CORE_PER_SOCKET}"
	echo "Sockets:,${OCICLI_MACHINE_SHOW_CPU_SOCKETS}"

	echo "==== NETWORKING ======,==============================================="
	echo "LADVD report:,${OCICLI_MACHINE_SHOW_LADVD_REPORT}"
	echo "Last seen:,${OCICLI_MACHINE_SHOW_LASTSEEN}"
	echo "Current IP address:,${OCICLI_MACHINE_SHOW_IPADDR}"
	echo -n "IPs:,"
	CNT=1
	for i in $(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.machine_ips)"' | jq -r '.[].ipaddr') ; do
		network_name=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.machine_ips)"' | jq -r '.[].networkname' | head -n ${CNT} | tail -n 1)
		if [ ${CNT} -ge 2 ] ; then
			echo ""
			echo -n " ,"
		fi
		echo -n "${i} (${network_name}) "
		CNT=$(( ${CNT} + 1 ))
	done
	echo ""
	echo "Force no BGP-to-the-host:,${OCICLI_MACHINE_SHOW_FORCE_NO_BGP2HOST}"
	echo "Force frr:,${OCICLI_MACHINE_SHOW_FORCE_FRR}"
	if [ "${OCICLI_MACHINE_SHOW_FORCE_FRR}" = "yes" ] ; then
		echo "Force frr nic1:,${OCICLI_MACHINE_SHOW_FORCE_FRR_NIC1}"
		echo "Force frr nic2:,${OCICLI_MACHINE_SHOW_FORCE_FRR_NIC2}"
		echo "Force frr vlan:,${OCICLI_MACHINE_SHOW_FORCE_FRR_VLAN}"
	fi

	echo "======= IPMI =========,==============================================="
	echo "IPMI firmware:,${OCICLI_MACHINE_SHOW_IPMI_VER}"
	echo "Detected IPMI IP:,${OCICLI_MACHINE_SHOW_IPMI_DETECTED_IP}"
	echo "Use IPMI:,${OCICLI_MACHINE_SHOW_USE_IPMI}"
	echo "Call IPMI bootdev:,${OCICLI_MACHINE_SHOW_CALL_IPMI_BOOTDEV}"
	echo "IPMI addr:,${OCICLI_MACHINE_SHOW_IPMI_ADDR}"
	echo "IPMI default gateway:,${OCICLI_MACHINE_SHOW_IPMI_DEFAULT_GW}"
	echo "IPMI netmask:,${OCICLI_MACHINE_SHOW_IPMI_NETMASK}"
	echo "IPMI port:,${OCICLI_MACHINE_SHOW_IPMI_PORT}"
	echo "IPMI VLAN:,${OCICLI_MACHINE_SHOW_IPMI_VLAN}"
	echo "IPMI username:,${OCICLI_MACHINE_SHOW_IPMI_USERNAME}"
	echo "IPMI password:,${OCICLI_MACHINE_SHOW_IPMI_PASSWORD}"

	echo "======= RAID =========,==============================================="
	if [ "${OCICLI_MACHINE_SHOW_DEST_BLK}" = "none" ] ; then
	 	echo "Dest blk:,${OCICLI_MACHINE_SHOW_DEST_BLK} (none specified)"
	else
	 	echo "Dest blk:,${OCICLI_MACHINE_SHOW_DEST_BLK}"
	fi
	echo "Install on RAID:,${OCICLI_MACHINE_SHOW_INSTALL_ON_RAID}"
	if [ "${OCICLI_MACHINE_SHOW_INSTALL_ON_RAID}" = "yes" ] ; then
		echo "Raid type:,${OCICLI_MACHINE_SHOW_RAID_TYPE}"
		echo "Raid device 0:,${OCICLI_MACHINE_SHOW_RAID_DEV0}"
		echo "Raid device 1:,${OCICLI_MACHINE_SHOW_RAID_DEV1}"
		case ${OCICLI_MACHINE_SHOW_RAID_TYPE} in
		0|1)
			echo -n ""
		;;
		5|10)
			echo "Raid device 2:,${OCICLI_MACHINE_SHOW_RAID_DEV2}"
			echo "Raid device 3:,${OCICLI_MACHINE_SHOW_RAID_DEV3}"
		;;
		esac
	fi

	echo "====== CONSOLE =======,==============================================="
	echo "Serial console device:,${OCICLI_MACHINE_SHOW_SERIAL_CONSOLE_DEV}"

	if [ "${OCICLI_MACHINE_SHOW_ROLE}" = "" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "compute" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "swiftstore" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "swiftproxy" ] ; then
		echo "=== ROLE-SPECIFIC ===,==============================================="
	fi
	if [ "${OCICLI_MACHINE_SHOW_ROLE}" = "" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "compute" ] ; then
		echo "Use Ceph if available:,${OCICLI_MACHINE_SHOW_USE_CEPH}"
		echo "Use GPU:,${OCICLI_MACHINE_SHOW_USE_GPU}"
		echo "GPU name:,${OCICLI_MACHINE_SHOW_GPU_NAME}"
		echo "GPU vendor ID:,${OCICLI_MACHINE_SHOW_GPU_VENDOR_ID}"
		echo "GPU product ID:,${OCICLI_MACHINE_SHOW_GPU_PRODUCT_ID}"
		echo "GPU device type:,${OCICLI_MACHINE_SHOW_GPU_DEVICE_TYPE}"
		echo "VFIO id list:,${OCICLI_MACHINE_SHOW_VFIO_IDS}"
		echo "Nested virtualization:,${OCICLI_MACHINE_SHOW_NESTED_VIRT}"

		echo "CPU mode:,${OCICLI_MACHINE_SHOW_CPU_MODE}"
		echo "CPU model:,${OCICLI_MACHINE_SHOW_CPU_MODEL}"
		echo "CPU model extra flags:,\"${OCICLI_MACHINE_SHOW_CPU_MODEL_EXTRA_FLAGS}\""
		echo "Hardware machine type:,${OCICLI_MACHINE_SHOW_HW_MACHINE_TYPE}"
		echo "Nova skip cpu compare on dest:,${OCICLI_MACHINE_SHOW_NOVA_SKIP_CPU_COMPARE_ON_DEST}"
		echo "Nova skip cpu compare at startup:,${OCICLI_MACHINE_SHOW_NOVA_SKIP_CPU_COMPARE_AT_STARTUP}"
		echo "Nova skip hypervisor version check on live mig:,${OCICLI_MACHINE_SHOW_NOVA_SKIP_HYPERVISOR_VERSION_CHECK_ON_LM}"
		echo "Force DHCP agent deployment:,${OCICLI_MACHINE_SHOW_FORCE_DHCP_AGENT}"
	fi

	if [ "${OCICLI_MACHINE_SHOW_ROLE}" = "" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "swiftstore" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "swiftproxy" ] ; then
		echo "Swift store account:,${OCICLI_MACHINE_SHOW_SWIFT_STORE_ACCOUNT}"
		echo "Swift store container:,${OCICLI_MACHINE_SHOW_SWIFT_STORE_CONTAINER}"
		echo "Swift store object:,${OCICLI_MACHINE_SHOW_SWIFT_STORE_OBJECT}"
	fi
	if [ "${OCICLI_MACHINE_SHOW_ROLE}" = "" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "compute" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "cephosd" ] || [ "${OCICLI_MACHINE_SHOW_ROLE}" = "billosd" ] ; then
		echo "Ceph OSD initial setup:,${OCICLI_MACHINE_SHOW_CEPH_OSD_INITIAL_SETUP}"
	fi
	if [ -r ${VARIABLE_FILE} ] && [ -n "${OCICLI_MACHINE_SHOW_ROLE}" ] ; then
		for OPTION in $(cat ${VARIABLE_FILE} | jq -r '.machines | keys[]' | tr '\n' ' ') ; do
			VALUE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.'${OPTION}')"')
			ROLES=$(cat ${VARIABLE_FILE} | jq -r '.machines.'${OPTION}'.roles[]' | tr '\n' ' ' | sed -e 's/ $//')
			DISPLAY=no
			if [ "${OCICLI_MACHINE_SHOW_ROLE}" = "" ] || [ "${ROLES}" = "all" ] ; then
				DISPLAY=yes
			else
				for role in ${ROLES} ; do
					if [ "${OCICLI_MACHINE_SHOW_ROLE}" = "${role}" ] ; then
						DISPLAY=yes
					fi
				done
			fi
			if [ "${DISPLAY}" = "yes" ] ; then
				DESCR=$(cat ${VARIABLE_FILE} | jq -r ".machines.${OPTION}.description")
				echo "${DESCR},${VALUE}"
			fi
		done
	# If no role, then we display all.
	else
		for OPTION in $(cat ${VARIABLE_FILE} | jq -r '.machines | keys[]' | tr '\n' ' ') ; do
			VALUE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.'${OPTION}')"')
			DESCR=$(cat ${VARIABLE_FILE} | jq -r ".machines.${OPTION}.description")
			echo "${DESCR},${VALUE}"
		done
	fi
}

ocicli_machine_blk (){
	ocicli_call "action=machine_blk&machine_serial=${1}"
	echo "name,realdev,size_mb"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]["blks"]|=sort_by(.name) | .["data"]["blks"][] | "\(.name),\(.realdev),\(.size_mb)"'
}

ocicli_machine_set (){
	SERIAL=${1}
	shift
	CALL="action=machine_set&machine_serial=${SERIAL}"
	for i in $@ ; do
		case "${1}" in
		"--use_ceph_if_available"|"--ceph-use-if-available")
			CALL="${CALL}&use_ceph=${2}"
			shift
			shift
		;;
		"--ceph-az")
			CALL="${CALL}&ceph_az=${2}"
			shift
			shift
		;;
		"--dest-blk")
			CALL="${CALL}&dest_blk=${2}"
			shift
			shift
		;;
		"--install-on-raid")
			CALL="${CALL}&install_on_raid=${2}"
			shift
			shift
		;;
		"--raid-type")
			CALL="${CALL}&raid_type=${2}"
			shift
			shift
		;;
		"--raid-dev0")
			CALL="${CALL}&raid_dev0=${2}"
			shift
			shift
		;;
		"--raid-dev1")
			CALL="${CALL}&raid_dev1=${2}"
			shift
			shift
		;;
		"--raid-dev2")
			CALL="${CALL}&raid_dev2=${2}"
			shift
			shift
		;;
		"--raid-dev3")
			CALL="${CALL}&raid_dev3=${2}"
			shift
			shift
		;;
		"--serial-console-device")
			CALL="${CALL}&serial_console_device=${2}"
			shift
			shift
		;;
		"--dc")
			CALL="${CALL}&loc_dc=${2}"
			shift
			shift
		;;
		"--row")
			CALL="${CALL}&loc_row=${2}"
			shift
			shift
		;;
		"--rack")
			CALL="${CALL}&loc_rack=${2}"
			shift
			shift
		;;
		"--ustart")
			CALL="${CALL}&loc_u_start=${2}"
			shift
			shift
		;;
		"--uend")
			CALL="${CALL}&loc_u_end=${2}"
			shift
			shift
		;;
		"--use-gpu")
			CALL="${CALL}&use_gpu=${2}"
			shift
			shift
		;;
		"--gpu-name")
			NAMES=$(echo ${2} | tr ',' '+')
			CALL="${CALL}&gpu_name=${NAMES}"
			shift
			shift
		;;
		"--gpu-vendor-id")
			IDS=$(echo ${2} | tr ',' '+')
			CALL="${CALL}&gpu_vendor_id=${IDS}"
			shift
			shift
		;;
		"--gpu-produc-id")
			IDS=$(echo ${2} | tr ',' '+')
			CALL="${CALL}&gpu_product_id=${IDS}"
			shift
			shift
		;;
		"--gpu-device-type")
			CALL="${CALL}&gpu_device_type=${2}"
			shift
			shift
		;;
		"--vfio-ids")
			IDS=$(echo ${2} | tr ',' '+')
			CALL="${CALL}&vfio_ids=${IDS}"
			shift
			shift
		;;
		"--nested-virt")
			CALL="${CALL}&nested_virt=${2}"
			shift
			shift
		;;
		"--cpu-mode")
			if [ -z "${2}" ] ; then
				echo "No parameter for --cpu-mode"
				usage
				exit 1
			fi
			if [ "${2}" != "host-model" ] && [ "${2}" != "host-passthrough" ] && [ "${2}" != "custom" ] && [ "${2}" != "cluster_value" ] ; then
				echo "Wrong parameter for --cpu-mode"
				usage
				exit 1
			fi
			CALL="${CALL}&cpu_mode=${2}"
			shift
			shift
		;;
		"--cpu-model")
			if [ -z "${2}" ] ; then
				echo "No parameter for --cpu-model"
				usage
				exit 1
			fi
			CALL="${CALL}&cpu_model=${2}"
			shift
			shift
		;;
		"--cpu-model-extra-flags")
			if [ -z "${2}" ] ; then
				CALL="${CALL}&cpu_model_extra_flags="
			else
				ENCODED=$(urlencode ${2})
				CALL="${CALL}&cpu_model_extra_flags=${ENCODED}"
			fi
			shift
			shift
		;;
		"--hw-machine-type")
			if [ -z "${2}" ] ; then
				CALL="${CALL}&hw_machine_type="
			else
				ENCODED=$(urlencode ${2})
				CALL="${CALL}&hw_machine_type=${ENCODED}"
			fi
			shift
			shift
		;;
		"--nova-skip-cpu-compare-on-dest")
			if [ "${2}" = "yes" ] ; then
				CALL="${CALL}&nova_skip_cpu_compare_on_dest=yes"
			elif [ "${2}" = "no" ] ; then
				CALL="${CALL}&nova_skip_cpu_compare_on_dest=no"
			else
				CALL="${CALL}&nova_skip_cpu_compare_on_dest=cluster_value"
			fi
			shift
			shift
		;;
		"--nova-skip-cpu-compare-at-startup")
			if [ "${2}" = "yes" ] ; then
				CALL="${CALL}&nova_skip_cpu_compare_at_startup=yes"
			elif [ "${2}" = "no" ] ; then
				CALL="${CALL}&nova_skip_cpu_compare_at_startup=no"
			else
				CALL="${CALL}&nova_skip_cpu_compare_at_startup=cluster_value"
			fi
			shift
			shift
		;;
		"--nova-skip-hypervisor-version-check-on-lm")
			if [ "${2}" = "yes" ] ; then
				CALL="${CALL}&nova_skip_hypervisor_version_check_on_lm=yes"
			elif [ "${2}" = "no" ] ; then
				CALL="${CALL}&nova_skip_hypervisor_version_check_on_lm=no"
			else
				CALL="${CALL}&nova_skip_hypervisor_version_check_on_lm=cluster_value"
			fi
			shift
			shift
		;;
		"--force-dhcp-agent")
			if [ -z "${2}" ] ; then
				echo "No parameter for --force-dhcp-agent"
				usage
				exit 1
			fi
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --force-dhcp-agent"
				usage
				exit 1
			fi
			CALL="${CALL}&force_dhcp_agent=${2}"
			shift
			shift
		;;
		"--swift-store-account")
			if [ -z "${2}" ] ; then
				echo "No parameter for --swift-store-account"
				usage
				exit 1
			fi
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --swift-store-account"
				usage
				exit 1
			fi
			CALL="${CALL}&swift_store_account=${2}"
			shift
			shift
		;;
		"--swift-store-container")
			if [ -z "${2}" ] ; then
				echo "No parameter for --swift-store-container"
				usage
				exit 1
			fi
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --swift-store-container"
				usage
				exit 1
			fi
			CALL="${CALL}&swift_store_container=${2}"
			shift
			shift
		;;
		"--swift-store-object")
			if [ -z "${2}" ] ; then
				echo "No parameter for --swift-store-object"
				usage
				exit 1
			fi
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --swift-store-object"
				usage
				exit 1
			fi
			CALL="${CALL}&swift_store_object=${2}"
			shift
			shift
		;;
		"--hostname")
			if [ -z "${2}" ] ; then
				echo "No parameter for --hostname"
				usage
				exit 1
			fi
			CALL="${CALL}&hostname=${2}"
			shift
			shift
		;;
		"--notes")
			if [ -z "${2}" ] ; then
				echo "No parameter for --notes"
				usage
				exit 1
			fi
			CALL="${CALL}&notes=${2}"
			shift
			shift
		;;
		"--ipmi-use")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-use"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_use=${2}"
			shift
			shift
		;;
		"--ipmi-call-chassis-bootdev")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-call-chassis-bootdev"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_call_chassis_bootdev=${2}"
			shift
			shift
		;;
		"--ipmi-username")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-username"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_username=${2}"
			shift
			shift
		;;
		"--ipmi-password")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-password"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_password=${2}"
			shift
			shift
		;;
		"--ipmi-addr")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-addr"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_addr=${2}"
			shift
			shift
		;;
		"--ipmi-port")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-port"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_port=${2}"
			shift
			shift
		;;
		"--ipmi-netmask")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-netmask"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_netmask=${2}"
			shift
			shift
		;;
		"--ipmi-default-gw")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-default-gw"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_default_gw=${2}"
			shift
			shift
		;;
		"--ipmi-vlan")
			if [ -z "${2}" ] ; then
				echo "No parameter for --ipmi-vlan"
				usage
				exit 1
			fi
			CALL="${CALL}&ipmi_vlan=${2}"
			shift
			shift
		;;
		"--ceph-osd-initial-setup")
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --ceph-osd-initial-setup"
				usage
				exit 1
			fi
			CALL="${CALL}&ceph_osd_initial_setup=${2}"
			shift
			shift
		;;
		"--force-no-bgp2host")
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --force-no-bgp2host"
				usage
				exit 1
			fi
			CALL="${CALL}&force_no_bgp2host=${2}"
			shift
			shift
		;;
		"--force-frr")
			if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
				echo "Wrong parameter for --force-frr"
				usage
				exit 1
			fi
			CALL="${CALL}&force_frr=${2}"
			shift
			shift
		;;
		"--force-frr-nic1")
			CALL="${CALL}&force_frr_nic1=${2}"
			shift
			shift
		;;
		"--force-frr-nic2")
			CALL="${CALL}&force_frr_nic2=${2}"
			shift
			shift
		;;
		"--force-frr-vlan")
			CALL="${CALL}&force_frr_vlan=${2}"
			shift
			shift
		;;
		*)
			if [ -r ${VARIABLE_FILE} ] ; then
				OPTIONS=$(cat ${VARIABLE_FILE} | jq -r '.machines | keys[]' | tr '\n' ' ')
				for OPTION in ${OPTIONS} ; do
					MY_OPTION="--"$(echo ${OPTION} | sed 's/_/-/g')
					if [ "${MY_OPTION}" = "${1}" ] ; then
						ENCODED_PARM=$(urlencode ${2})
						CALL="${CALL}&${OPTION}=${ENCODED_PARM}"
						shift
						shift
						continue
					fi
				done
			else
				echo -n ""
			fi
		;;
		esac
	done
	ocicli_call ${CALL}
	ocicli_display_status
}

ocicli_location_list (){
	ocicli_call "action=location_list"
	echo "id,name,swiftregion"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"][] | "\(.id),\(.name),\(.swiftregion)"'
}


ocicli_network_list (){
	ocicli_call "action=network_list"
	DATA=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]' 2>/dev/null)
	HEAD="name,ip,cidr,first_ip,last_ip,is_public,cluster_name,role,vip_usage,iface1,iface2,lldp_match,bridgename,vlan,mtu,location,ipmi_match_addr,ipmi_match_cidr,ipmi_mode"
	if [ "${DATA}" = "null" ] ; then
		echo ${HEAD}
	else
		echo ${HEAD}
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.name)|.["data"][] | "\(.name),\(.ip),\(.cidr),\(.first_ip),\(.last_ip),\(.is_public),\(.cluster_name),\(.role),\(.vip_usage),\(.iface1),\(.iface2),\(.lldp_match),\(.bridgename),\(.vlan),\(.mtu),\(.location),\(.ipmi_match_addr),\(.ipmi_match_cidr),\(.ipmi_mode)"'
	fi
}

ocicli_cluster_list (){
	ocicli_call "action=cluster_list"
	echo "id,name,domain"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.name)|.["data"][] | "\(.id),\(.name),\(.domain)"'
}

ocicli_machine_ip_list (){
	ocicli_call "action=machine_ip_list&serial=${1}"
	echo "networkname,ipaddr,usefor"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.networkname)|.["data"][] | "\(.networkname),\(.ipaddr),\(.usefor)"'
}

ocicli_cluster_show (){
	ocicli_call "action=cluster_show&name=${1}"
	OCICLI_CLUSTER_SHOW_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.name)"')
	OCICLI_CLUSTER_SHOW_DOMAIN=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.domain)"')
	OCICLI_CLUSTER_SHOW_REGION_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.region_name)"')
	OCICLI_CLUSTER_SHOW_FIRST_MASTER_SERIAL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.first_master_machine_serial)"')
	OCICLI_CLUSTER_SHOW_INITIAL_CLUSTER_SETUP=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.initial_cluster_setup)"')
	OCICLI_CLUSTER_SHOW_VIP_HOSTNAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.vip_hostname)"')
	OCICLI_CLUSTER_SHOW_SWIFT_PART_POWER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_part_power)"')
	OCICLI_CLUSTER_SHOW_SWIFT_REPLICAS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_replicas)"')
	OCICLI_CLUSTER_SHOW_SWIFT_MIN_PART_HOURS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_min_part_hours)"')
	OCICLI_CLUSTER_SHOW_SWIFT_PROXY_HOSTNAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_proxy_hostname)"')
	OCICLI_CLUSTER_SHOW_SWIFT_ENCRYPTION_KEY=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_encryption_key_id)"')
	OCICLI_CLUSTER_SHOW_SWIFT_DISABLE_ENCRYPTION=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_disable_encryption)"')
	OCICLI_CLUSTER_SHOW_SWIFT_OBJECT_REPLICATOR_CONCURRENCY=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_object_replicator_concurrency)"')
	OCICLI_CLUSTER_SHOW_SWIFT_RSYNC_CONNECTION_LIMIT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_rsync_connection_limit)"')
	OCICLI_CLUSTER_SHOW_SWIFT_PUBLIC_CLOUD_MIDDLEWARES=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.swift_public_cloud_middlewares)"')

	OCICLI_CLUSTER_SHOW_EXTSWIFT_USE_EXTERNAL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_use_external)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_AUTH_URL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_auth_url)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_REGION=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_region)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_PROXY_URL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_proxy_url)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_PROJECT_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_project_name)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_PROJECT_DOMAIN_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_project_domain_name)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_USER_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_user_name)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_USER_DOMAIN_NAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_user_domain_name)"')
	OCICLI_CLUSTER_SHOW_EXTSWIFT_PASSWORD=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.extswift_password)"')

	OCICLI_CLUSTER_SHOW_TIME_SERVER_HOST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.time_server_host)"')
	OCICLI_CLUSTER_SHOW_V4_NS1=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nameserver_v4_prim)"')
	OCICLI_CLUSTER_SHOW_V4_NS2=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nameserver_v4_sec)"')
	OCICLI_CLUSTER_SHOW_V6_NS1=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nameserver_v6_prim)"')
	OCICLI_CLUSTER_SHOW_V6_NS2=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nameserver_v6_sec)"')


	OCICLI_CLUSTER_SHOW_HAPROXY_CUSTOM_URL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.haproxy_custom_url)"')
	OCICLI_CLUSTER_SHOW_STATSD_HOSTNAME=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.statsd_hostname)"')
	OCICLI_CLUSTER_SHOW_AMP_SECGROUP_LIST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.amp_secgroup_list)"' | sed 's/,/ /')
	OCICLI_CLUSTER_SHOW_AMP_BOOT_NETWORK_LIST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.amp_boot_network_list)"' | sed 's/,/ /')
	OCICLI_CLUSTER_SHOW_DISABLE_NOTIFICATIONS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.disable_notifications)"')
	OCICLI_CLUSTER_SHOW_ENABLE_MONITORING_GRAPHS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.enable_monitoring_graphs)"')
	OCICLI_CLUSTER_SHOW_MONITORING_GRAPHITE_HOST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.monitoring_graphite_host)"')
	OCICLI_CLUSTER_SHOW_MONITORING_GRAPHITE_PORT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.monitoring_graphite_port)"')
	OCICLI_CLUSTER_SHOW_SELF_SIGNED_API_CERT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.self_signed_api_cert)"')
	OCICLI_CLUSTER_SHOW_NESTED_VIRT=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nested_virt)"')
	OCICLI_CLUSTER_SHOW_USE_OVS_IFACES=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.use_ovs_ifaces)"')

	OCICLI_CLUSTER_SHOW_CPU_MODE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_mode)"')
	OCICLI_CLUSTER_SHOW_CPU_MODEL=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_model)"')
	OCICLI_CLUSTER_SHOW_CPU_MODEL_EXTRA_FLAGS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cpu_model_extra_flags)"')
	OCICLI_CLUSTER_SHOW_HW_MACHINE_TYPE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.hw_machine_type)"')
	OCICLI_CLUSTER_SHOW_NOVA_SKIP_CPU_COMPARE_ON_DEST=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nova_skip_cpu_compare_on_dest)"')
	OCICLI_CLUSTER_SHOW_NOVA_SKIP_CPU_COMPARE_AT_STARTUP=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nova_skip_cpu_compare_at_startup)"')
	OCICLI_CLUSTER_SHOW_NOVA_SKIP_HYPERVISOR_VERSION_CHECK_ON_LM=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.nova_skip_hypervisor_version_check_on_lm)"')

	OCICLI_CLUSTER_SHOW_CEPHOSD_AUTOMATIC_PROVISIONNING=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.cephosd_automatic_provisionning)"')

	echo "Field,Value"
	echo "Name:,${OCICLI_CLUSTER_SHOW_NAME}"
	echo "Domain:,${OCICLI_CLUSTER_SHOW_DOMAIN}"
	echo "Region name:,${OCICLI_CLUSTER_SHOW_REGION_NAME}"
	echo "First master machine serial:,${OCICLI_CLUSTER_SHOW_FIRST_MASTER_SERIAL}"
	echo "Initial cluster setup:,${OCICLI_CLUSTER_SHOW_INITIAL_CLUSTER_SETUP}"
	if [ "${OCICLI_CLUSTER_SHOW_VIP_HOSTNAME}" = "" ] ; then
		echo "VIP Hostname:,default (ie: ${OCICLI_CLUSTER_SHOW_NAME}-api.${OCICLI_CLUSTER_SHOW_DOMAIN})"
	else
		echo "VIP Hostname:,${OCICLI_CLUSTER_SHOW_VIP_HOSTNAME}"
	fi
	echo "Self signed API cert:,${OCICLI_CLUSTER_SHOW_SELF_SIGNED_API_CERT}"
	echo "Haproxy custom url (redirection for the / of API):,${OCICLI_CLUSTER_SHOW_HAPROXY_CUSTOM_URL}"
	if [ -z "${OCICLI_CLUSTER_SHOW_SWIFT_PROXY_HOSTNAME}" ] ; then
		echo "Swift proxy hostname:,none (using controller HAproxy)"
	else
		echo "Swift proxy hostname:,${OCICLI_CLUSTER_SHOW_SWIFT_PROXY_HOSTNAME}"
	fi
	if [ -z "${OCICLI_CLUSTER_SHOW_SWIFT_ENCRYPTION_KEY}" ] ; then
		echo "Swift encryption key uuid:,none (please create one using swift-openrc)"
	else
		echo "Swift encryption key uuid:,${OCICLI_CLUSTER_SHOW_SWIFT_ENCRYPTION_KEY}"
	fi
	echo "Swift disable encryption:,${OCICLI_CLUSTER_SHOW_SWIFT_DISABLE_ENCRYPTION}"
	echo "Swift part power:,${OCICLI_CLUSTER_SHOW_SWIFT_PART_POWER}"
	echo "Swift replicas:,${OCICLI_CLUSTER_SHOW_SWIFT_REPLICAS}"
	echo "Swift min part hours:,${OCICLI_CLUSTER_SHOW_SWIFT_MIN_PART_HOURS}"
	echo "Swift object replicator concurrency:,${OCICLI_CLUSTER_SHOW_SWIFT_OBJECT_REPLICATOR_CONCURRENCY}"
	echo "Swift rsync connection limit:,${OCICLI_CLUSTER_SHOW_SWIFT_RSYNC_CONNECTION_LIMIT}"
	echo "Swift public cloud middlewares:,${OCICLI_CLUSTER_SHOW_SWIFT_PUBLIC_CLOUD_MIDDLEWARES}"

	echo "External swift use:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_USE_EXTERNAL}"
	echo "External swift auth URL:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_AUTH_URL}"
	echo "External swift region:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_REGION}"
	echo "External swift proxy URL:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_PROXY_URL}"
	echo "External swift project name:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_PROJECT_NAME}"
	echo "External swift project domain name:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_PROJECT_DOMAIN_NAME}"
	echo "External swift user name:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_USER_NAME}"
	echo "External swift user domain name:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_USER_DOMAIN_NAME}"
	echo "External swift password:,${OCICLI_CLUSTER_SHOW_EXTSWIFT_PASSWORD}"

	echo "Time server host:,${OCICLI_CLUSTER_SHOW_TIME_SERVER_HOST}"
	echo "Nameserver v4 primary:,${OCICLI_CLUSTER_SHOW_V4_NS1}"
	echo "Nameserver v4 secondary:,${OCICLI_CLUSTER_SHOW_V4_NS2}"
	echo "Nameserver v6 primary:,${OCICLI_CLUSTER_SHOW_V6_NS1}"
	echo "Nameserver v6 secondary:,${OCICLI_CLUSTER_SHOW_V6_NS2}"

	echo "Statsd hostname:,${OCICLI_CLUSTER_SHOW_STATSD_HOSTNAME}"
	echo "amp_secgroup_list (Octavia):,${OCICLI_CLUSTER_SHOW_AMP_SECGROUP_LIST}"
	echo "amp_boot_network_list (Octavia):,${OCICLI_CLUSTER_SHOW_AMP_BOOT_NETWORK_LIST}"
	echo "disable_notifications:,${OCICLI_CLUSTER_SHOW_DISABLE_NOTIFICATIONS}"
	echo "enable_monitoring_graphs (graphite):,${OCICLI_CLUSTER_SHOW_ENABLE_MONITORING_GRAPHS}"
	echo "monitoring_graphite_host:,${OCICLI_CLUSTER_SHOW_MONITORING_GRAPHITE_HOST}"
	echo "monitoring_graphite_port:,${OCICLI_CLUSTER_SHOW_MONITORING_GRAPHITE_PORT}"
	echo "Nested virtualization:,${OCICLI_CLUSTER_SHOW_NESTED_VIRT}"
	echo "Use OpenVSwitch /etc/network/interfaces:,${OCICLI_CLUSTER_SHOW_USE_OVS_IFACES}"

	echo "CPU mode:,${OCICLI_CLUSTER_SHOW_CPU_MODE}"
	if [ "${OCICLI_CLUSTER_SHOW_CPU_MODE}" = "host-passthrough" ] ; then
		echo "CPU model:,none (using host-passthrough)"
		echo "CPU model extra flags:,none (using host-passthrough)"
	else
		echo "CPU model:,${OCICLI_CLUSTER_SHOW_CPU_MODEL}"
		echo "CPU model extra flags:,\"${OCICLI_CLUSTER_SHOW_CPU_MODEL_EXTRA_FLAGS}\""
	fi
	echo "Hardware machine type:,${OCICLI_CLUSTER_SHOW_HW_MACHINE_TYPE}"
	echo "Nova skip cpu compare on dest:,${OCICLI_CLUSTER_SHOW_NOVA_SKIP_CPU_COMPARE_ON_DEST}"
	echo "Nova skip cpu compare at startup:,${OCICLI_CLUSTER_SHOW_NOVA_SKIP_CPU_COMPARE_AT_STARTUP}"
	echo "Nova skip hypervisor version check on live mig:,${OCICLI_CLUSTER_SHOW_NOVA_SKIP_HYPERVISOR_VERSION_CHECK_ON_LM}"

	echo "Ceph OSD automatic provisionning:,${OCICLI_CLUSTER_SHOW_CEPHOSD_AUTOMATIC_PROVISIONNING}"

	if [ -r ${VARIABLE_FILE} ] ; then
		for OPTION in $(cat ${VARIABLE_FILE} | jq -r '.clusters | keys[]' | tr '\n' ' ') ; do
			VALUE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]| "\(.'${OPTION}')"')
			DESCR=$(cat ${VARIABLE_FILE} | jq -r ".clusters.${OPTION}.description")
			echo "${DESCR},${VALUE}"
		done
	fi

}

ocicli_profile_list (){
	ocicli_call "action=profile_list"
	PROFILE_NAMES=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"] | keys[]' | tr '\n' ' ')
	echo "profile_name,role,product_names,ram_min,ram_max"
	for profile_name in ${PROFILE_NAMES} ; do
		ROLE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["'${profile_name}'"]["role"]')
		PRODS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["'${profile_name}'"]["product-name"][]' | tr '\n' '/' | sed 's/\/$//')
		RAM_MIN=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["'${profile_name}'"]["ram"]["min"]')
		RAM_MAX=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["'${profile_name}'"]["ram"]["max"]')
		echo "${profile_name},${ROLE},${PRODS},${RAM_MIN},${RAM_MAX}"
	done
}

ocicli_swiftregion_list () {
	ocicli_call "action=swiftregion_list"
	echo "id,name"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.name)|.["data"][] | "\(.id),\(.name)"'
}

ocicli_cluster_show_networks (){
	ocicli_call "action=cluster_show_networks&cluster_name=${1}"
	echo "name,ip,cidr,is_public,cluster,role,iface1,iface2,location_id"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.name)|.["data"][] | "\(.name),\(.ip),\(.cidr),\(.is_public),\(.cluster),\(.role),\(.iface1),\(.iface2),\(.location_id)"'
}

ocicli_cluster_show_machines (){
	ocicli_call "action=cluster_show_machines&cluster_name=${1}"
	echo "serial,ipaddr,memory,status,lastseen,hostname"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.serial)|.["data"][] | "\(.serial),\(.ipaddr),\(.memory),\(.status),\(.lastseen),\(.hostname)"'
}

ocicli_cluster_wait_for () {
	local MACHINE_SERIAL=$1
	local FIELD=$2
	local VALUE=$3
	local CNT=1800
	while [ "${CNT}" -gt 0 ] && [ ""$(ocicli -csv machine-list -a | q -H -d, "SELECT ${FIELD} FROM - WHERE serial='${MACHINE_SERIAL}' OR hostname='${MACHINE_SERIAL}'" 2>/dev/null) != "${VALUE}" ] ; do
		echo -n "."
		sleep 2
		CNT=$((${CNT} - 1))
	done
	if [ "${CNT}" = 0 ] ; then
		echo "timed out."
		exit 1
	else
		echo "ok."
	fi
}

ocicli_cluster_wait_for_puppet () {
	local MACHINE_SERIAL=$1
	local CNT=6000
	local PUPPET_STATUS=$(ocicli -csv machine-list -s | q -H -d, "SELECT puppet FROM - WHERE serial='${MACHINE_SERIAL}' OR hostname='${MACHINE_SERIAL}'" 2>/dev/null)
	while [ "${CNT}" -gt 0 ] && [ "${PUPPET_STATUS}" != "success" ] && [ "${PUPPET_STATUS}" != "failure" ] ; do
		echo -n "."
		sleep 2
		PUPPET_STATUS=$(ocicli -csv machine-list -s | q -H -d, "SELECT puppet FROM - WHERE serial='${MACHINE_SERIAL}' OR hostname='${MACHINE_SERIAL}'" 2>/dev/null)
		CNT=$((${CNT} - 1))
	done
	if [ "${CNT}" = 0 ] ; then
		echo "timed out."
		exit 1
	else
		echo "ok."
	fi
}

ocicli_machine_wait_for_install () {
	local MACHINE_TO_WAIT_FOR
	MACHINE_TO_WAIT_FOR=${1}
	echo -n "Waiting for ${MACHINE_TO_WAIT_FOR} to be installed:"
	ocicli_cluster_wait_for ${MACHINE_TO_WAIT_FOR} status installed
}

ocicli_machine_wait_for_puppet () {
	local MACHINE_TO_WAIT_FOR
	MACHINE_TO_WAIT_FOR=${1}
	echo -n "Waiting for ${MACHINE_TO_WAIT_FOR} puppet run:"
	ocicli_cluster_wait_for_puppet ${MACHINE_TO_WAIT_FOR}
}

ocicli_cluster_install () {
	local DOMAIN_NAME CLUSTER_ID CEPH_MONS CEPH_OSDS CONTROLLERS COMPUTES VOLUMES
	local CLUSTER_NAME=${1}
	local EXISTS=$(ocicli -csv cluster-list | q -H -d, "SELECT COUNT(id) FROM - WHERE name='${CLUSTER_NAME}'")
	if [ "${EXISTS}" != "1" ] ; then
		echo "Could not find cluster named ${CLUSTER_NAME}"
		exit 1
	fi
	echo "Installing cluster ${CLUSTER_NAME}..."
	DOMAIN_NAME=$(ocicli -csv cluster-list | q -H -d, "SELECT domain FROM - WHERE name='${CLUSTER_NAME}'")
	CLUSTER_ID=$(ocicli -csv cluster-list | q -H -d, "SELECT id FROM - WHERE name='${CLUSTER_NAME}'")
	echo "Cluster has domain name: ${DOMAIN_NAME} and ID: ${CLUSTER_ID}"
	echo "Fetching machine serials to schedule installation..."
	MACHINE_LIST_TMP=$(mktemp -t ocicli-cluster-install-machine-list.XXXXXX)
	ocicli -csv machine-list -a >${MACHINE_LIST_TMP}
	echo "-> billmon"
	BILLMONS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='billmon' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> billosd"
	BILLOSDS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='billosd' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> messaging"
	MESSAGINGS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='messaging' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> cephmon"
	CEPH_MONS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='cephmon' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> sql"
	SQLS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='sql' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> sqlmsg"
	SQLMSGS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='sqlmsg' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> tempest"
	TEMPESTS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='tempest' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> cephosd"
	CEPH_OSDS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='cephosd' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> compute with ceph osd"
	COMPUTE_WITH_CEPH_OSDS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='compute' AND cephosd='yes' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> controller"
	CONTROLLERS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='controller' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> network"
	NETWORKS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='network' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> compute"
	COMPUTES=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='compute' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> volume"
	VOLUMES=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='volume' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> swiftproxy"
	SWIFTPROXIES=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='swiftproxy' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> swiftstore"
	SWIFTSTORES=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='swiftstore' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	echo "-> DNS"
	DNSS=$(cat ${MACHINE_LIST_TMP} | q -H -d, "SELECT serial FROM - WHERE role='dns' AND cluster='${CLUSTER_NAME}'" 2>/dev/null | tr '\n' ' ')
	rm -f ${MACHINE_LIST_TMP}

	# If we're on a hyper converged cluster, with cephmon on controllers,
	# and cephosd on computes, then we must install controller first.
	if [ -z "${CEPH_MONS}" ] && [ -n "${COMPUTE_WITH_CEPH_OSDS}" ] ; then
		echo "Installing cephmon on controllers: ${CONTROLLERS}"
		for i in ${CONTROLLERS} ; do
			STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
			if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
		for i in ${CONTROLLERS} ; do
			echo -n "Waiting for ${i} (Ceph MON on controllers) to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
	fi

	# Install SQL and SQLMSG first, as they are independent.
	# We'll check for puppet later on...
	if [ -n "${SQLS}" ] || [ -n "${SQLMSGS}" ] ; then
		echo "Installing SQL machines: ${SQLS} ${SQLMSGS}"
		for i in ${SQLS} ${SQLMSGS} ; do
                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
                        if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
	fi

	# Install the Ceph MON machines, they must be up before OSDs.
	if [ -n "${BILLMONS}" ] || [ -n "${CEPH_MONS}" ] ; then
		echo "Installing CEPH MON machines: ${BILLMONS} ${CEPH_MONS}"
		for i in ${BILLMONS} ${CEPH_MONS} ; do
                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
                        if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
		for i in ${BILLMONS} ${CEPH_MONS} ; do
			echo -n "Waiting for ${i} (Ceph MON) to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
		echo ""
	fi
	# Install the Ceph OSD machines, they must be up before messaging and controllers
	if [ -n "${BILLOSDS}" ] || [ -n "${CEPH_OSDS}" ] || [ -n "${COMPUTE_WITH_CEPH_OSDS}" ] ; then
		echo "Installing CEPH OSD machines: ${BILLOSDS} ${CEPH_OSDS} ${COMPUTE_WITH_CEPH_OSDS}"
		for i in ${BILLOSDS} ${CEPH_OSDS} ${COMPUTE_WITH_CEPH_OSDS} ; do
			STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
			if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
		for i in ${BILLOSDS} ${CEPH_OSDS} ${COMPUTE_WITH_CEPH_OSDS} ; do
			echo -n "Waiting for ${i} to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
		echo ""
	fi

	# Wait for SQL machines to finish puppet install
	if [ -n "${SQLS}" ] || [ -n "${SQLMSGS}" ] ; then
		for i in ${SQLS} ${SQLMSGS} ; do
			echo -n "Waiting for ${i} (SQL) to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
		echo "Checking that SQL machines are up: ${SQLS} ${SQLMSGS}"
		for i in ${SQLS} ${SQLMSGS} ; do
			echo -n "Waiting for ${i} puppet run:"
			ocicli_cluster_wait_for_puppet $i
		done
	fi

	# Install the messaging machines, they must be up before the controllers,
	# otherwise, keystone bootstrap fails.
	if [ -n "${MESSAGINGS}" ] ; then
		echo "Installing MESSAGING machines: ${MESSAGINGS}"
		for i in ${MESSAGINGS} ; do
                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
                        if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
	fi
	# Install the controllers. They must be up before any other types.
	if [ -n "${CONTROLLERS}" ] ; then
		echo "Installing CONTROLLER machines: ${CONTROLLERS}"
		for i in ${CONTROLLERS} ; do
                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
                        if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
		for i in ${CONTROLLERS} ; do
			echo -n "Waiting for ${i} to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
		for i in ${CONTROLLERS} ; do
			echo -n "Waiting for ${i} puppet run:"
			ocicli_cluster_wait_for_puppet $i
		done
	fi
	# Install the network machines. They must be up before compute nodes.
	if [ -n "${NETWORKS}" ] ; then
		echo "Installing NETWORK machines: ${NETWORKS}"
		for i in ${NETWORKS} ; do
                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
                        if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
		for i in ${NETWORKS} ; do
			echo -n "Waiting for ${i} to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
		for i in ${NETWORKS} ; do
			echo -n "Waiting for ${i} puppet run:"
			ocicli_cluster_wait_for_puppet $i
		done
	fi
	# Install all the other machines, in no particular order.
	if [ -n "${COMPUTES}" ] || [ -n "${VOLUMES}" ] || [ -n "${SWIFTPROXIES}" ] || [ -n "${SWIFTSTORES}" ] || [ -n "${DNSS}" ] ; then
		echo "Installing COMPUTE, VOLUME, SWIFTPROXY and SWIFTSTORE machines: ${COMPUTES} ${VOLUMES} ${SWIFTPROXIES} ${SWIFTSTORES} ${DNSS}"
		for i in ${COMPUTES} ${VOLUMES} ${SWIFTPROXIES} ${SWIFTSTORES} ${DNSS} ; do
                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
                        if [ "${STATUS}" = "live" ] ; then
				ocicli machine-install-os $i
			fi
		done
		for i in ${COMPUTES} ${VOLUMES} ${SWIFTPROXIES} ${SWIFTSTORES} ; do
			echo -n "Waiting for ${i} to be installed:"
			ocicli_cluster_wait_for $i status installed
		done
		for i in ${COMPUTES} ${VOLUMES} ${SWIFTPROXIES} ${SWIFTSTORES} ; do
			echo -n "Waiting for ${i} puppet run:"
			ocicli_cluster_wait_for $i puppet success
		done
	fi

	# If we're on a hyper converged cluster, with cephmon on controllers,
	# and cephosd on computes, then we must wait for the controller + compute
	# 2nd pass of puppet run.
	if [ -z "${CEPH_MONS}" ] && [ -n "${COMPUTE_WITH_CEPH_OSDS}" ] ; then
		echo "-> Waiting 10 seconds before starting to wait for controllers"
		sleep 10
		for i in ${CONTROLLERS} ; do
			echo -n "Waiting for ${i} to finish its 2nd pass puppet run:"
			ocicli_cluster_wait_for_puppet $i
		done
		echo "-> Waiting 10 seconds before starting to wait for computes"
		sleep 10
		for i in ${COMPUTES} ; do
			echo -n "Waiting for ${i} to finish its 2nd pass puppet run:"
			ocicli_cluster_wait_for_puppet $i
		done
	fi

#	if [ -n "${TEMPESTS}" ] ; then
#		echo "Installing TEMPESTS machines: ${TEMPESTS}"
#		for i in ${TEMPESTS} ; do
#                        STATUS=$(ocicli -csv machine-list -a | q -H -d, "SELECT status FROM - WHERE serial='${i}'")
#                        if [ "${STATUS}" = "live" ] ; then
#				ocicli machine-install-os $i
#			fi
#		done
#	fi
}

ocicli_cluster_reset () {
	local CLUSTER_NAME=${1}
	local EXISTS=$(ocicli -csv cluster-list | q -H -d, "SELECT COUNT(id) FROM - WHERE name='${CLUSTER_NAME}'")
	if [ "${EXISTS}" != "1" ] ; then
		echo "Could not find cluster named ${CLUSTER_NAME}"
		exit 1
	fi
	echo -n "Please confirm with uppercase YES: "
	read CONFIRM
	if [ "${CONFIRM}" != "YES" ] ; then
		echo "Didn't confirm: exiting..."
		exit 0
	fi
	echo "Resetting cluster ${CLUSTER_NAME}..."
	MACHINES=$(ocicli -csv machine-list -a | q -H -d, "SELECT serial FROM - WHERE cluster='${CLUSTER_NAME}' AND status!='live'" | tr '\n' ' ')
	if [ -n "${MACHINES}" ] ; then
		echo "Rebooting machines in live mode: ${MACHINES}"
		for i in ${MACHINES} ; do
			echo "IPMI reboot: $i"
			ocicli machine-ipmi-reboot-on-live $i
		done
	fi
}

cluster_rolecounts_list () {
	local CLUSTER_NAME=${1}
	ocicli_call "action=cluster_rolecounts_list&name=${CLUSTER_NAME}"
	echo "role,count"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.role)|.["data"][] | "\(.role),\(.count)"'
}

ocicli_role_list (){
	ocicli_call "action=role_list"
	echo "id,name"
	cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.name)|.["data"][] | "\(.id),\(.name)"'
}

ocicli_swift_publish_ring (){
	CLUSTER_NAME=${1}
	if [ -z "${1}" ] ; then
		usage
	fi

	ALL_MACHINES=$(ocicli -csv machine-list -a | q -H -d, "SELECT hostname,Cur_ip FROM - WHERE (role='swiftstore' OR role='swiftproxy') AND cluster='swift02'")
	MY_CUR_DIR=$(pwd)
	cd /var/lib/oci/clusters/${CLUSTER_NAME}/swift-ring
	for MACHINE in ${ALL_MACHINES} ; do
		MACHINE_HOSTNAME=$(echo ${MACHINE} | cut -d, -f1)
		MACHINE_IP=$(echo ${MACHINE} | cut -d, -f2)
		echo "===> Copying ring to: ${MACHINE_HOSTNAME} (${MACHINE_IP})"
		SSH_AUTH_SOCK= scp -i /etc/openstack-cluster-installer/id_rsa account.builder account.ring.gz container.builder container.ring.gz object.builder object.ring.gz root@${MACHINE_IP}:/etc/swift
		echo "-> Fixing rights"
		SSH_AUTH_SOCK= ssh -i /etc/openstack-cluster-installer/id_rsa root@${MACHINE_IP} "chown swift:swift /etc/swift/account.ring.gz /etc/swift/container.ring.gz /etc/swift/object.ring.gz"
	done
}

ocicli_display_status (){
	STATUS=$(cat ${API_RESPONSE_FILE} | jq -r '.["status"]')
	if [ "${STATUS}" = 'success' ] ; then
		echo "Ok."
	else
		echo "Status not ok:"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	fi
}

#########################
### Parameter parsing ###
#########################

if [ -z "${1}" ] || [ "${1}" = "-h" ] || [ "${1}" = "--help" ]; then
	usage
fi

if [ -z "${OCI_API_URL}" ] ; then
	echo "Please add: export OCI_API_URL=\"http(s)://<url-or-IP-of-your-oci-server>/oci/api.php?\""
	echo "to your .bashrc in order to use "$(basename $0)
	echo "You may as well want to set OCI_LOGIN and OCI_PASS to be authenticated."
	exit 1
fi

if [ "${1}" = -d ] ; then
	DEBUG=on
	MINUS_D="-d"
	shift
fi

# If using -csv, procress as normal
if [ "${1}" = -csv ] ; then
	shift
else
	# If not, (and not for all commands...), we call ourself with -csv and filter the CSV output through the column program
	case ${1} in
	"machine-install-os")
		echo -n ""
	;;
	"check-all-ipmi")
		echo -n ""
	;;
	"password-show")
		echo -n ""
	;;
	"password-set")
		echo -n ""
	;;
	"machine-display-install-cmd")
		echo -n ""
	;;
	"machine-install-log")
		echo -n ""
	;;
	"machine-guess-racking")
		echo -n ""
	;;
	"machine-auto-rack")
		echo -n ""
	;;
	"machine-auto-add")
		echo -n ""
	;;
	"machine-megacli-apply")
		echo -n ""
	;;
	"machine-megacli-reset-raid")
		echo -n ""
	;;
	"machine-set-ipmi")
		echo -n ""
	;;
	"machine-ipmi-adopt")
		echo -n ""
	;;
	"machine-guessed-profile")
		echo -n ""
	;;
	"machine-save-ipmi-pass")
		echo -n ""
	;;
	"machine-forget-ipmi-pass")
		echo -n ""
	;;
	"machine-console")
		echo -n ""
	;;
	"machine-apply-ipmi")
		echo -n ""
	;;
	"machine-ipmi-cmd")
		echo -n ""
	;;
	"machine-wait-for-install")
		echo -n ""
	;;
	"machine-wait-for-puppet")
		echo -n ""
	;;
	"cluster-install")
		echo -n ""
	;;
	"cluster-reset")
		echo -n ""
	;;
	"cluster-create")
		echo -n ""
	;;
	"cluster-delete")
		echo -n ""
	;;
	"swift-calculate-ring")
		echo -n ""
	;;
	"swift-publish-ring")
		echo -n ""
	;;
	"--column")
		$0 ${MINUS_D} -csv $@ | column -t -s $','
		exit 0
	;;
	*)
		$0 ${MINUS_D} -csv $@ | csvlook --snifflimit 0 -d , --blanks -I
		exit 0
	;;
	esac
fi

ACTION=${1}
shift

case "${ACTION}" in
	"check-all-ipmi")
		if [ "${1}" = "--filter" ] ; then
			FILTER="--filter ${2}"
		else
			FILTER=""
		fi
		MACHINE_LIST=$(ocicli -csv machine-list ${FILTER} -a | q -H -d, "SELECT serial FROM -" | tr '\n' ' ')
                RED="\033[1;31m"
                NO_COL="\033[0m"
                GREEN="\033[1;32m"
		for machine in ${MACHINE_LIST} ; do
			echo -n "===> Checking $machine"
			ALL_VALS=$(ocicli -csv machine-list -a | q -H -d, "SELECT IPMI_IP,ipmi_port,ipmi_username,ipmi_password,dc,row,rack,ustart,uend,hostname FROM - WHERE serial='${machine}'")
			IPMI_ADDR=$(echo ${ALL_VALS} | cut -d, -f1)
			IPMI_PORT=$(echo ${ALL_VALS} | cut -d, -f2)
			IPMI_USER=$(echo ${ALL_VALS} | cut -d, -f3)
			IPMI_PASS=$(echo ${ALL_VALS} | cut -d, -f4)
			MACHINE_DC=$(echo ${ALL_VALS} | cut -d, -f5)
			MACHINE_ROW=$(echo ${ALL_VALS} | cut -d, -f6)
			MACHINE_RACK=$(echo ${ALL_VALS} | cut -d, -f7)
			MACHINE_USTART=$(echo ${ALL_VALS} | cut -d, -f8)
			MACHINE_UEND=$(echo ${ALL_VALS} | cut -d, -f9)
			HOSTNAME=$(echo ${ALL_VALS} | cut -d, -f10)
			echo -n " (dc:${MACHINE_DC}/row:${MACHINE_ROW}/rack:${MACHINE_RACK}/ustart:${MACHINE_USTART}/uend:${MACHINE_UEND}/hostname:${HOSTNAME}): "
			PW_STATUS=$(timeout 5 ipmitool -I lanplus -H ${IPMI_ADDR} -p ${IPMI_PORT} -U ${IPMI_USER} -P ${IPMI_PASS} chassis power status 2>&1 || true)
			if [ "${PW_STATUS}" = "Chassis Power is on" ] || [ "${PW_STATUS}" = "Chassis Power is off" ] ; then
				echo "${GREEN}ok${NO_COL}"
			else
				echo "${RED}not ok${NO_COL}"
			fi
		done
	;;
	"password-list")
		ocicli_password_list $@
	;;
	"password-show")
		ocicli_call "action=password_show&id=${1}"
		CLUSTER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["cluster"]')
		SERVICE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["service"]')
		PASS_TYPE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["passtype"]')
		PASS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["pass"]')
		PASS_TXT1=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["passtxt1"]')
		PASS_TXT2=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["passtxt2"]')
		AZ=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["az"]')
		echo "Cluster: $CLUSTER"
		echo "Service: $SERVICE"
		echo "AZ: $AZ"
		echo "Pass type: $PASS_TYPE"
		case "$PASS_TYPE" in
		"db"|"fsid"|"libvirtuuid"|"uuid"|"credential1"|"credential2"|"stats"|"openstackkey"|"monitoring"|"messaging"|"authtoken")
			echo "Pass: $PASS"
		;;
		"rndckey")
			echo "Pass: $PASS_TXT1"
		;;
		"ssh")
			echo "Public key:"
			echo ${PASS_TXT1}
			echo "Private key:"
			echo ${PASS_TXT2} | base64 -d
		;;
		*)
			echo "Display of this password type not implemented (yet)."
			exit 1
		;;
		esac
	;;
	"password-set")
		ocicli_call "action=password_show&id=${1}"
		STATUS=$(cat ${API_RESPONSE_FILE} | jq -r '.["status"]')
		if [ "${STATUS}" != "success" ] ; then
			echo "Cannot find password with such ID"
			exit 1
		else
			CLUSTER=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["cluster"]')
			SERVICE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["service"]')
			PASS_TYPE=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["passtype"]')
			PASS=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["pass"]')
			PASS_TXT1=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["passtxt1"]')
			PASS_TXT2=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["passtxt2"]')
			AZ=$(cat ${API_RESPONSE_FILE} | jq -r '.["data"]["az"]')
			case "$PASS_TYPE" in
			"db"|"fsid"|"libvirtuuid"|"uuid"|"credential1"|"credential2"|"stats"|"openstackkey")
				if [ -z "${2}" ] ; then
					echo "Missing pass param"
					exit 1
				fi
				CALL_OPT="&pass=${2}"
			;;
			"rndckey")
				if [ -z "${2}" ] ; then
					echo "Missing pass param"
					exit 1
				fi
				CALL_OPT="&passtxt1=${2}"
			;;
			"ssh")
				# Parse pubkey: can be a file, or the pubkey directly if file does not exist.
				if [ -z "${2}" ] ; then
					echo "No parameter for public key"
					exit 1
				fi
				if ! [ -e "${2}" ] ; then
					PUB_KEY=$(urlencode ${2})
				else
					PUB_KEY=$(urlencode $(cat ${2}))
				fi

				# Parse privkey: can be empty, in which case we store nothing, or can be a file.
				if [ -z "${3}" ] ; then
					PRIV_KEY=""
				else
					if ! [ -e "${3}" ] ; then
						echo "Cannot find private key: ${3}"
						exit 1
					fi
					PRIV_KEY=$(cat ${3} | base64 | tr -d '\n')
				fi
				CALL_OPT="&passtxt1=${PUB_KEY}&passtxt2=${PRIV_KEY}"
			;;
			*)
				echo "Setting this type of passwords is not implemented yet."
				exit 1
			;;
			esac
			ocicli_call "action=password_set&id=${1}${CALL_OPT}"
			echo "Ok."
		fi
	;;
	"machine-apply-ipmi")
		ocicli_call "action=machine_apply_ipmi&serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"machine-list")
		ocicli_machine_list $@
	;;
	"machine-show")
		ocicli_machine_show ${1}
	;;
	"machine-blk")
		ocicli_machine_blk ${1}
	;;
	"machine-guessed-profile")
		if [ "${2}" = "-d" ] || [ "${2}" = "--debug" ] ; then
			PROFILE_MYDEBUG="&debug=yes"
			ocicli_call "action=machine_guessed_profile&machine_serial=${1}${PROFILE_MYDEBUG}"
			cat ${API_RESPONSE_FILE} | jq -r '.["data"][]'
		else
			PROFILE_MYDEBUG=""
			ocicli_call "action=machine_guessed_profile&machine_serial=${1}${PROFILE_MYDEBUG}"
			cat ${API_RESPONSE_FILE} | jq -r '.["data"][]'
		fi
	;;
	"machine-check-megacli-applied")
		ocicli_call "action=machine_check_megacli_applied&machine_serial=${1}&profile_name=${2}"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"machine-megacli-apply")
		if [ "${2}" = "-d" ] || [ "${3}" = "-d" ]; then
			OUTPUT_DEBUG="yes"
			PROFILE_MYDEBUG="&debug=yes"
		else
			OUTPUT_DEBUG="no"
			PROFILE_MYDEBUG="&debug=no"
		fi
		if [ -n "${3}" ] || [ -n "${2}" -a "${2}" != "-d" ] ; then
			PROFILE="&profile_name=${2}"
		else
			PROFILE=""
		fi
		ocicli_call "action=machine_megacli_apply&machine_serial=${1}${PROFILE}${PROFILE_MYDEBUG}"
		if [ "${OUTPUT_DEBUG}" = "yes" ] ; then
			cat ${API_RESPONSE_FILE} | jq -r '.["data"][]'
		else
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
		fi
	;;
	"machine-megacli-reset-raid")
		ocicli_call "action=machine_megacli_reset_raid&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-guess-racking")
		ocicli_call "action=machine_guess_racking&machine_serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"machine-auto-rack")
		ocicli_call "action=machine_auto_rack&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-auto-add")
		ocicli_call "action=machine_auto_add&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-to-dns")
		ocicli_call "action=machine_to_dns&machine_serial=${1}"
		if [ "${2}" = "-d" ] ; then
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["command"]'
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["output"]'
		else
			ocicli_display_status
		fi
	;;
	"machine-out-of-dns")
		ocicli_call "action=machine_out_of_dns&machine_serial=${1}"
		if [ "${2}" = "-d" ] ; then
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["command"]'
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["output"]'
		else
			ocicli_display_status
		fi
	;;
	"machine-to-monitoring")
		ocicli_call "action=machine_to_monitoring&machine_serial=${1}"
		if [ "${2}" = "-d" ] ; then
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["command"]'
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["output"]'
		else
			ocicli_display_status
		fi
	;;
	"machine-out-of-monitoring")
		ocicli_call "action=machine_out_of_monitoring&machine_serial=${1}"
		if [ "${2}" = "-d" ] ; then
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["command"]'
			cat ${API_RESPONSE_FILE} | jq -r '.["data"]["output"]'
		else
			ocicli_display_status
		fi
	;;
	"machine-gen-root-pass")
		ocicli_call "action=machine_gen_root_pass&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-forget-root-pass")
		ocicli_call "action=machine_forget_root_pass&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-report-counter-reset")
		ocicli_call "action=machine_report_counter_reset&machine_serial=${1}"
		ocicli_display_status
	;;
	"profile-list")
		ocicli_profile_list
	;;
	"machine-set")
		ocicli_machine_set $@
	;;
	# Add a machine to a cluster
	"machine-add")
		if [ "${1}" = "--fixed-ip" ] ; then
			FIXED_IP_Q="fixed_ip=${2}&"
			shift
			shift
		else
			FIXED_IP_Q=""
		fi
		ocicli_call "action=machine_add&${FIXED_IP_Q}machine_serial=${1}&cluster_name=${2}&role_name=${3}&location_name=${4}"
		ocicli_display_status
	;;
	"machine-remove")
		ocicli_call "action=machine_remove&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-destroy")
		ocicli_call "action=machine_destroy&machine_serial=${1}"
		ocicli_display_status
	;;
	"machine-show-from-hostname")
		ocicli_call "action=machine_show_from_hostname&hostname=${1}"
		echo "serial,ipaddr,memory,status,lastseen,hostname"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"] | "\(.serial),\(.ipaddr),\(.memory),\(.status),\(.lastseen),\(.hostname)"'
	;;
	"machine-reboot-on-hdd")
		ocicli_call "action=machine_reboot_on_hdd&serial=${1}"
		ocicli_display_status
	;;
	"machine-reboot-on-live")
		ocicli_call "action=machine_reboot_on_live&serial=${1}"
		ocicli_display_status
	;;
	"machine-ipmi-reboot-on-hdd")
		ocicli_call "action=ipmi_reboot_on_hdd&serial=${1}"
		ocicli_display_status
	;;
	"machine-ipmi-reboot-on-live")
		ocicli_call "action=ipmi_reboot_on_live&serial=${1}"
		ocicli_display_status
	;;
	"machine-hpe-ilo-license-install")
		ocicli_call "action=hpe_ilo_license_install&serial=${1}"
		ocicli_display_status
	;;
	"machine-activate-ipmi-over-lan"|"machine-hpe-activate-ipmi-over-lan")
		ocicli_call "action=activate_ipmi_over_lan&serial=${1}"
		ocicli_display_status
	;;
	"machine-ipmi-cmd")
		ENCODED=$(urlencode ${2})
		ocicli_call "action=ipmi_cmd&serial=${1}&cmd=${ENCODED}"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"machine-ipmi-assign-ip")
		ocicli_call "action=ipmi_assign_ip&serial=${1}&ipmi_network=${2}"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"machine-ipmi-adopt")
		ocicli_call "action=machine_ipmi_adopt&serial=${1}"
		ocicli_display_status
	;;
	"machine-install-os")
		ocicli_call "action=machine_install_os&serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"machine-display-install-cmd")
		ocicli_call "action=machine_display_install_cmd&serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"machine-install-log")
		ocicli_call "action=machine_install_log&serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"machine-set-ipmi")
		# Prototype: machine-set-ipmi [--do-ipmitool-cmds] [--ipmi-defgw GATEWAY] [--ipmi-netmask NETMASK] [--ipmi-call-chassis-bootdev yes/no] <serial> <use-ipmi:yes/no> <ipmi-ip-addr> <ipmi-port> <ipmi-username> <ipmi-password>
		if [ "${1}" = "--do-ipmitool-cmds" ] ; then
			MORE_PARAMS="&perform_ipmitool_cmd=yes";
			shift
			if [ "${1}" = "--ipmi-defgw" ] ; then
				MORE_PARAMS="${MORE_PARAMS}&ipmi_default_gw=${2}"
				shift
				shift
			fi
			if [ "${1}" = "--ipmi-netmask" ] ; then
				MORE_PARAMS="${MORE_PARAMS}&ipmi_netmask=${2}"
				shift
				shift
			fi
			if [ "${1}" = "--ipmi-call-chassis-bootdev" ] ; then
				MORE_PARAMS="${MORE_PARAMS}&ipmi_call_chassis_bootdev=${2}"
				shift
				shift
			fi
		fi
		ocicli_call "action=machine_set_ipmi&serial=${1}&ipmi_use=${2}&ipmi_addr=${3}&ipmi_port=${4}&ipmi_username=${5}&ipmi_password=${6}${MORE_PARAMS}"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"machine-save-ipmi-pass")
		ocicli_call "action=machine_save_ipmi_pass&serial=${1}"
		ocicli_display_status
	;;
	"machine-forget-ipmi-pass")
		ocicli_call "action=machine_forget_ipmi_pass&serial=${1}"
		ocicli_display_status
	;;
	"machine-console")
		ocicli_call "action=ipmi_show_cmd_console&serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"machine-wipe")
		ocicli_call "action=machine_wipe&serial=${1}"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"machine-ip-add")
		ocicli_call "action=machine_ip_add&serial=${1}&network_name=${2}&ip_addr=${3}"
		ocicli_display_status
	;;
	"machine-ip-list")
		ocicli_machine_ip_list $1
	;;
	"machine-ip-remove")
		ocicli_call "action=machine_ip_remove&serial=${1}&ip_addr=${2}"
		ocicli_display_status
	;;
	"machine-renew-ipmi-password")
		MACHINE_IP=$(ocicli -csv machine-list | q -H -d, "SELECT Cur_ip FROM - WHERE serial='$1' OR hostname='$1'")
		MACHINE_VENDOR=$(ocicli -csv machine-list -h | q -H -d, "SELECT product_name FROM - WHERE serial='$1' OR hostname='$1'")
		if echo "${MACHINE_IP}" | grep -q -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' ; then
			if echo "${MACHINE_VENDOR}" | grep -q -E '^CL2[68]00'; then
				NEW_PASSWORD=$(openssl rand -hex 9 | cut -c -16)
				IPMI_USER=3
			else
				NEW_PASSWORD=$(openssl rand -hex 9 | cut -c -12)
				IPMI_USER=2
			fi
			if [ -r /etc/openstack-cluster-installer/id_rsa ] ; then
				ssh -i /etc/openstack-cluster-installer/id_rsa root@${MACHINE_IP} "ipmitool user set password ${IPMI_USER} ${NEW_PASSWORD}"
			else
				ssh root@${MACHINE_IP} "ipmitool user set password ${IPMI_USER} ${NEW_PASSWORD}"
			fi
			ocicli_call "action=machine_set&machine_serial=${1}&ipmi_password=${NEW_PASSWORD}"
			ocicli_display_status
		else
			echo "Cant-find-machine-ip"
		fi
	;;
	"machine-replace")
		ocicli_call "action=machine_replace&old_serial=${1}&new_serial=${2}"
		ocicli_display_status
	;;
	"machine-wait-for-install")
		ocicli_machine_wait_for_install $@
	;;
	"machine-wait-for-puppet")
		ocicli_machine_wait_for_puppet $@
	;;
	"ipmi-assign-check")
		ocicli_call "action=ipmi_assign_check"
		cat ${API_RESPONSE_FILE} | jq -r '.["message"]'
	;;
	"location-list")
		ocicli_location_list
	;;
	"location-create")
		ocicli_call "action=location_create&name=${1}&swiftregion=${2}"
		ocicli_display_status
	;;
	"location-delete")
		ocicli_call "action=location_delete&name=${1}"  
		ocicli_display_status
	;;

	"network-create")
		ocicli_call "action=new_network&name=${1}&ipaddr=${2}&cidr_mask=${3}&location=${4}&is_public=${5}"
		ocicli_display_status
	;;
	"network-list")
		ocicli_network_list
	;;
	"network-delete")
		ocicli_call "action=network_delete&name=${1}"
		ocicli_display_status
	;;
	"cluster-set")
		CALL="action=cluster_set&name=${1}"
		shift
		for i in $@ ; do
			case "${1}" in
			"--initial-cluster-setup")
				if [ -z "${2}" ] ; then
					echo "No parameter for --initial-cluster-setup"
					usage
					exit 1
				fi
				CALL="${CALL}&initial_cluster_setup=${2}"
				shift
				shift
			;;
			"--vip-hostname")
				if [ -z "${2}" ] ; then
					echo "No parameter for --vip-hostname"
					usage
					exit 1
				fi
				CALL="${CALL}&vip_hostname=${2}"
				shift
				shift
			;;
			"--region-name")
				if [ -z "${2}" ] ; then
					echo "No parameter for --region-name"
					usage
					exit 1
				fi
				CALL="${CALL}&region_name=${2}"
				shift
				shift
			;;
			"--swift-part-power")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-part-power"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_part_power=${2}"
				shift
				shift
			;;
			"--time-server-host")
				if [ -z "${2}" ] ; then
					echo "No parameter for --time-server-host"
					usage
					exit 1
				fi
				CALL="${CALL}&time_server_host=${2}"
				shift
				shift
			;;
			"--swift-encryption-key-id")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-encryption-key-id"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_encryption_key_id=${2}"
				shift
				shift
			;;
			"--swift-proxy-hostname")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-proxy-hostname"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_proxy_hostname=${2}"
				shift
				shift
			;;
			"--swift-disable-encryption")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-disable-encryption"
					usage
					exit 1
				fi
				if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
					echo "Wrong parameter for --swift-disable-encryption"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_disable_encryption=${2}"
				shift
				shift
			;;
			"--swift-object-replicator-concurrency")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-object-replicator-concurrency"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_object_replicator_concurrency=${2}"
				shift
				shift
			;;
			"--swift-rsync-connection-limit")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-rsync-connection-limit"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_rsync_connection_limit=${2}"
				shift
				shift
			;;
			"--swift-public-cloud-middlewares")
				if [ -z "${2}" ] ; then
					echo "No parameter for --swift-public-cloud_middlewares"
					usage
					exit 1
				fi
				if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
					echo "Wrong parameter for --swift-public-cloud-middlewares"
					usage
					exit 1
				fi
				CALL="${CALL}&swift_public_cloud_middlewares=${2}"
				shift
				shift
			;;
			"--extswift-use-external")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-use-external"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_use_external=${2}"
				shift
				shift
			;;
			"--extswift-auth-url")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-auth-url"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_auth_url=${2}"
				shift
				shift
			;;
			"--extswift-region")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-region"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_region=${2}"
				shift
				shift
			;;
			"--extswift-proxy-url")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-proxy-url"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_proxy_url=${2}"
				shift
				shift
			;;
			"--extswift-project-name")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-project-name"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_project_name=${2}"
				shift
				shift
			;;
			"--extswift-project-domain-name")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-project-domain-name"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_project_domain_name=${2}"
				shift
				shift
			;;
			"--extswift-user-name")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-user-name"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_user_name=${2}"
				shift
				shift
			;;
			"--extswift-user-domain-name")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-user-domain-name"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_user_domain_name=${2}"
				shift
				shift
			;;
			"--extswift-password")
				if [ -z "${2}" ] ; then
					echo "No parameter for --extswift-password"
					usage
					exit 1
				fi
				CALL="${CALL}&extswift_password=${2}"
				shift
				shift
			;;
			"--amp-secgroup-list")
				if [ -z "${2}" ] ; then
					echo "No parameter for --amp-secgroup-list"
					usage
					exit 1
				fi
				CALL="${CALL}&amp_secgroup_list=${2}"
				shift
				shift
			;;
			"--amp-boot-network-list")
				if [ -z "${2}" ] ; then
					echo "No parameter for --amp-boot-network-list"
					usage
					exit 1
				fi
				CALL="${CALL}&amp_boot_network_list=${2}"
				shift
				shift
			;;
			"--disable-notifications")
				if [ "${2}" != 'yes' ] && [ "${2}" != 'no' ] ; then
					echo "Paramter for --disable-notifications isn't yes or no"
					usage
					exit 1
				fi
				CALL="${CALL}&disable_notifications=${2}"
				shift
				shift
			;;
			"--enable-monitoring-graphs")
				if [ "${2}" != 'yes' ] && [ "${2}" != 'no' ] ; then
					echo "Paramter for --disable-notifications isn't yes or no"
					usage
					exit 1
				fi
				CALL="${CALL}&enable_monitoring_graphs=${2}"
				shift
				shift
			;;
			"--monitoring-graphite-host")
				if [ -z "${2}" ] ; then
					echo "No parameter for --monitoring-graphite-host"
					usage
					exit 1
				fi
				CALL="${CALL}&monitoring_graphite_host=${2}"
				shift
				shift
			;;
			"--monitoring-graphite-port")
				if [ -z "${2}" ] ; then
					echo "No parameter for --monitoring-graphite-port"
					usage
					exit 1
				fi
				CALL="${CALL}&monitoring_graphite_port=${2}"
				shift
				shift
			;;
			"--statsd-hostname")
				if [ -z "${2}" ] ; then
					echo "No parameter for --statsd-hostname"
					usage
					exit 1
				fi
				CALL="${CALL}&statsd_hostname=${2}"
				shift
				shift
			;;
			"--self-signed-api-cert")
				if [ -z "${2}" ] ; then
					echo "No parameter for --self-signed-api-cert"
					usage
					exit 1
				fi
				if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
					echo "Wrong parameter for --self-signed-api-cert"
					usage
					exit 1
				fi
				CALL="${CALL}&self_signed_api_cert=${2}"
				shift
				shift
			;;
			"--nested-virt")
				if [ -z "${2}" ] ; then
					echo "No parameter for --nested-virt"
					usage
					exit 1
				fi
				if [ "${2}" != "yes" ] && [ "${2}" != "no" ]  && [ "${2}" != "cluster_value" ]; then
					echo "Wrong parameter for --nested-virt"
					usage
					exit 1
				fi
				CALL="${CALL}&nested_virt=${2}"
				shift
				shift
			;;
			"--use-ovs-ifaces")
				if [ -z "${2}" ] ; then
					echo "No parameter for --use-ovs-ifaces"
					usage
					exit 1
				fi
				if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
					echo "Wrong parameter for --use-ovs-ifaces"
					usage
					exit 1
				fi
				CALL="${CALL}&use_ovs_ifaces=${2}"
				shift
				shift
			;;
			"--cpu-mode")
				if [ -z "${2}" ] ; then
					echo "No parameter for --cpu-mode"
					usage
					exit 1
				fi
				if [ "${2}" != "host-model" ] && [ "${2}" != "host-passthrough" ] && [ "${2}" != "custom" ] ; then
					echo "Wrong parameter for --cpu-mode"
					usage
					exit 1
				fi
				CALL="${CALL}&cpu_mode=${2}"
				shift
				shift
			;;
			"--cpu-model")
				if [ -z "${2}" ] ; then
					echo "No parameter for --cpu-model"
					usage
					exit 1
				fi
				CALL="${CALL}&cpu_model=${2}"
				shift
				shift
			;;
			"--cpu-model-extra-flags")
				if [ -z "${2}" ] ; then
					CALL="${CALL}&cpu_model_extra_flags="
				else
					ENCODED=$(urlencode ${2})
					CALL="${CALL}&cpu_model_extra_flags=${ENCODED}"
				fi
				shift
				shift
			;;
			"--hw-machine-type")
				if [ -z "${2}" ] ; then
					CALL="${CALL}&hw_machine_type="
				else
					ENCODED=$(urlencode ${2})
					CALL="${CALL}&hw_machine_type=${ENCODED}"
				fi
				shift
				shift
			;;
			"--nova-skip-cpu-compare-on-dest")
				if [ "${2}" = "yes" ] ; then
					CALL="${CALL}&nova_skip_cpu_compare_on_dest=yes"
				else
					CALL="${CALL}&nova_skip_cpu_compare_on_dest=no"
				fi
				shift
				shift
			;;
			"--nova-skip-cpu-compare-at-startup")
				if [ "${2}" = "yes" ] ; then
					CALL="${CALL}&nova_skip_cpu_compare_at_startup=yes"
				else
					CALL="${CALL}&nova_skip_cpu_compare_at_startup=no"
				fi
				shift
				shift
			;;
			"--nova-skip-hypervisor-version-check-on-lm")
				if [ "${2}" = "yes" ] ; then
					CALL="${CALL}&nova_skip_hypervisor_version_check_on_lm=yes"
				else
					CALL="${CALL}&nova_skip_hypervisor_version_check_on_lm=no"
				fi
				shift
				shift
			;;
			"--first-master")
				if [ -z "${2}" ] ; then
					echo "No parameter for --first-master"
					usage
					exit 1
				fi
				CALL="${CALL}&first_master=${2}"
				shift
				shift
			;;
			"--nameserver-v4-primary")
				if [ -z "${2}" ] ; then
					echo "No parameter for --nameserver-v4-primary"
					usage
					exit 1
				fi
				CALL="${CALL}&nameserver_v4_primary=${2}"
				shift
				shift
			;;
			"--nameserver-v4-secondary")
				if [ -z "${2}" ] ; then
					echo "No parameter for --nameserver-v4-secondary"
					usage
					exit 1
				fi
				CALL="${CALL}&nameserver_v4_secondary=${2}"
				shift
				shift
			;;
			"--nameserver-v6-primary")
				if [ -z "${2}" ] ; then
					echo "No parameter for --nameserver-v6-primary"
					usage
					exit 1
				fi
				CALL="${CALL}&nameserver_v6_primary=${2}"
				shift
				shift
			;;
			"--nameserver-v6-secondary")
				if [ -z "${2}" ] ; then
					echo "No parameter for --nameserver-v6-secondary"
					usage
					exit 1
				fi
				CALL="${CALL}&nameserver_v6_secondary=${2}"
				shift
				shift
			;;
			"--haproxy-custom-url")
				if [ -z "${2}" ] ; then
					echo "No parameter for --haproxy-custom-url"
					usage
					exit 1
				fi
				CALL="${CALL}&haproxy_custom_url=${2}"
				shift
				shift
			;;
			"--cephosd-automatic-provisionning")
				if [ -z "${2}" ] ; then
					echo "No parameter for --cephosd-automatic-provisionning"
					usage
					exit 1
				fi
				if [ "${2}" != "yes" ] && [ "${2}" != "no" ] ; then
					echo "Wrong parameter for --cephosd-automatic-provisionning"
					usage
					exit 1
				fi
				CALL="${CALL}&cephosd_automatic_provisionning=${2}"
				shift
				shift
			;;
			*)
				if [ -r ${VARIABLE_FILE} ] ; then
					OPTIONS=$(cat ${VARIABLE_FILE} | jq -r '.clusters | keys[]' | tr '\n' ' ')
					for OPTION in ${OPTIONS} ; do
						MY_OPTION="--"$(echo ${OPTION} | sed 's/_/-/g')
						if [ "${MY_OPTION}" = "${1}" ] ; then
							ENCODED_PARM=$(urlencode ${2})
							CALL="${CALL}&${OPTION}=${ENCODED_PARM}"
							shift
							shift
							continue
						fi
					done
				else
					echo -n ""
				fi
			;;
			esac
		done
		ocicli_call $CALL
		ocicli_display_status
	;;
	"network-set")
		CALL="action=network_set&network_name=${1}"
		shift
		for i in $@ ; do
			case "${1}" in
			"--role")
				if [ -z "${2}" ] ; then
					echo "No parameter for --role"
					usage
					exit 1
				fi
				CALL="${CALL}&role=${2}"
				shift
				shift
			;;
			"--iface1")
				if [ -z "${2}" ] ; then
					echo "No parameter for --iface1"
					usage
					exit 1
				fi
				CALL="${CALL}&iface1_name=${2}"
				shift
				shift
			;;
			"--iface2")
				if [ -z "${2}" ] ; then
					echo "No parameter for --iface2"
					usage
					exit 1
				fi
				CALL="${CALL}&iface2_name=${2}"
				shift
				shift
			;;
			"--lldp-match")
				if [ -z "${2}" ] ; then
					echo "No parameter for --lldp-match"
					usage
					exit 1
				fi
				CALL="${CALL}&lldp_match=${2}"
				shift
				shift
			;;
			"--ip")
				if [ -z "${2}" ] ; then
					echo "No parameter for --ip"
					usage
					exit 1
				fi
				CALL="${CALL}&ip=${2}"
				shift
				shift
			;;
			"--cidr")
				if [ -z "${2}" ] ; then
					echo "No parameter for --cidr"
					usage
					exit 1
				fi
				CALL="${CALL}&cidr=${2}"
				shift
				shift
			;;
			"--is-public")
				if [ -z "${2}" ] ; then
					echo "No parameter for --is-public"
					usage
					exit 1
				fi
				CALL="${CALL}&is_public=${2}"
				shift
				shift
			;;
			"--mtu")
				if [ -z "${2}" ] ; then
					echo "No parameter for --mtu"
					usage
					exit 1
				fi
				CALL="${CALL}&mtu=${2}"
				shift
				shift
			;;
			"--vlan")
				if [ -z "${2}" ] ; then
					echo "No parameter for --vlan"
					usage
					exit 1
				fi
				CALL="${CALL}&vlan=${2}"
				shift
				shift
			;;
			"--location")
				if [ -z "${2}" ] ; then
					echo "No parameter for --location"
					usage
					exit 1
				fi
				CALL="${CALL}&location=${2}"
				shift
				shift
			;;
			"--bridge-name")
				if [ -z "${2}" ] ; then
					echo "No parameter for --bridge-name"
					usage
					exit 1
				fi
				CALL="${CALL}&bridgename=${2}"
				shift
				shift
			;;
			"--ipmi-match-addr")
				if [ -z "${2}" ] ; then
					echo "No parameter for --ipmi-match-addr"
					usage
					exit 1
				fi
				CALL="${CALL}&ipmi_match_addr=${2}"
				shift
				shift
			;;
			"--ipmi-match-cidr")
				if [ -z "${2}" ] ; then
					echo "No parameter for --ipmi-match-cidr"
					usage
					exit 1
				fi
				CALL="${CALL}&ipmi_match_cidr=${2}"
				shift
				shift
			;;
			"--ipmi-mode")
				if [ -z "${2}" ] ; then
					echo "No parameter for --ipmi-mode"
					usage
					exit 1
				fi
				if [ "${2}" = "ocimanaged" ] ; then
					IPMI_MODE="&ipmi_mode=ocimanaged"
				else
					IPMI_MODE="&ipmi_mode=externaldhcp"
				fi
				CALL="${CALL}${IPMI_MODE}"
				shift
				shift
			;;
			"--first-ip")
				if [ -z "${2}" ] ; then
					echo "No parameter for --first-ip"
					usage
					exit 1
				fi
				CALL="${CALL}&first_ip=${2}"
				shift
				shift
			;;
			"--last-ip")
				if [ -z "${2}" ] ; then
					echo "No parameter for --last-ip"
					usage
					exit 1
				fi
				CALL="${CALL}&last_ip=${2}"
				shift
				shift
			;;
			"--vip-usage")
				if [ -z "${2}" ] ; then
					echo "No parameter for --vip-usage"
					usage
					exit 1
				fi
				CALL="${CALL}&vip_usage=${2}"
				shift
				shift
			;;
			*)
			;;
			esac
		done
		ocicli_call $CALL
		ocicli_display_status
	;;
	# Add a network to a cluster
	"network-add")
		ocicli_call "action=network_add&network_name=${1}&cluster_name=${2}&role_name=${3}&iface1=${4}&iface2=${5}"
		ocicli_display_status
	;;
	# Remove a network from a cluster
	"network-remove")
		ocicli_call "action=network_remove&network_name=${1}"
		ocicli_display_status
	;;

	"cluster-list")
		ocicli_cluster_list
	;;
	"cluster-create")
		ocicli_call "action=cluster_create&name=${1}&domain=${2}"
		ocicli_display_status
	;;
	"cluster-delete")
		ocicli_call "action=cluster_delete&name=${1}"
		ocicli_display_status
	;;
	"cluster-show")
		ocicli_cluster_show ${1}
	;;
	"cluster-show-networks")
		ocicli_cluster_show_networks $@
	;;
	"cluster-show-machines")
		ocicli_cluster_show_machines $@
	;;
	"cluster-show-ips")
		ocicli_call "action=cluster_show_ips&name=${1}"
		echo "hostname,ip"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.hostname)|.["data"][] | "\(.hostname),\(.ipaddr)"'
	;;
	"cluster-install")
		ocicli_cluster_install $@
	;;
	"cluster-reset")
		ocicli_cluster_reset $@
	;;
	"cluster-rolecounts-list")
		cluster_rolecounts_list $@
	;;
	"cluster-rolecounts-set")
		ocicli_call "action=cluster_rolecounts_set&name=${1}&role=${2}&count=${3}"
		ocicli_display_status
	;;
	"filebeat-output-host-list")
		ocicli_call "action=filebeat_output_host_list&cluster_name=${1}"
		echo "cluster,hostname,port"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]|=sort_by(.cluster_name,.hostname,.port)|.["data"][] | "\(.cluster_name),\(.hostname),\(.port)"'
	;;
	"filebeat-output-host-create")
		ocicli_call "action=filebeat_output_host_create&cluster_name=${1}&filebeat_host=${2}&filebeat_port=${3}"
		ocicli_display_status
	;;
	"filebeat-output-host-delete")
		ocicli_call "action=filebeat_output_host_delete&cluster_name=${1}&filebeat_host=${2}&filebeat_port=${3}"
		ocicli_display_status
	;;
	"swift-region-list")
		ocicli_swiftregion_list
	;;
	"swift-region-create")
		ocicli_call "action=swiftregion_create&name=${1}"
		ocicli_display_status
	;;
	"swift-region-delete")
		ocicli_call "action=swiftregion_delete&name=${1}"
		ocicli_display_status
	;;
	"swift-calculate-ring")
		if [ -z "${1}" ] ; then
			echo "Error: need the cluster name as parameter."
			exit 1
		fi
		CLUSTER_NAME="${1}"
		shift
		if [ -n "${1}" ] && [ "${1}" = "--ec-only" ]; then
			if [ -n "${2}" ] && [ "${2}" = "yes" ]; then
				EC_ONLY=yes
			else
				EC_ONLY=no
			fi
			shift
			shift
		else
			EC_ONLY=no
		fi
		if [ -n "${1}" ] ; then
			INIWEI_ACCOUNT="${1}"
		else
			INIWEI_ACCOUNT=1000
		fi
		if [ -n "${2}" ] ; then
			INIWEI_CONTAINER="${2}"
		else
			INIWEI_CONTAINER=1000
		fi
		if [ -n "${3}" ] ; then
			INIWEI_OBJECT="${3}"
		else
			INIWEI_OBJECT=1000
		fi
		ocicli_call "action=swift_caculate_ring&cluster_name=${CLUSTER_NAME}&ec_only=${EC_ONLY}&initial_account_weight=${INIWEI_ACCOUNT}&initial_container_weight=${INIWEI_CONTAINER}&initial_object_weight=${INIWEI_OBJECT}"
		echo "Output for the job:"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"swift-add-machine-to-ring")
		if [ -z "${1}" ] ; then
			echo "Error: need the machine serial or name as parameter."
			exit 1
		fi
		MACHINE_SERIAL="${1}"
		shift
		if [ -n "${1}" ] && [ "${1}" = "--ec-only" ]; then
			if [ -n "${2}" ] && [ "${2}" = "yes" ]; then
				EC_ONLY=yes
			else
				EC_ONLY=no
			fi
			shift
			shift
		else
			EC_ONLY=no
		fi
		if [ -n "${1}" ] ; then
			INIWEI_ACCOUNT="${1}"
		else
			INIWEI_ACCOUNT=1000
		fi
		if [ -n "${2}" ] ; then
			INIWEI_CONTAINER="${2}"
		else
			INIWEI_CONTAINER=1000
		fi
		if [ -n "${3}" ] ; then
			INIWEI_OBJECT="${3}"
		else
			INIWEI_OBJECT=1000
		fi
		ocicli_call "action=swift_add_machine_to_ring&machine_serial=${MACHINE_SERIAL}&ec_only=${EC_ONLY}&initial_account_weight=${INIWEI_ACCOUNT}&initial_container_weight=${INIWEI_CONTAINER}&initial_object_weight=${INIWEI_OBJECT}"
		echo "Output for the job:"
		cat ${API_RESPONSE_FILE} | jq -r '.["data"]'
	;;
	"swift-publish-ring")
		ocicli_swift_publish_ring $@
	;;
	"role-list")
		ocicli_role_list
	;;
	"role-create")
		ocicli_call "action=role_create&name=${1}"
		ocicli_display_status
	;;
	"role-delete")
		ocicli_call "action=role_delete&name=${1}"
		ocicli_display_status
	;;
	*)
		usage
	;;
esac

rm -f ${API_RESPONSE_FILE}
exit 0
