diff --git a/tools/get-vm-info.sh b/tools/get-vm-info.sh index 36f136d..4b34acf 100755 --- a/tools/get-vm-info.sh +++ b/tools/get-vm-info.sh @@ -4,7 +4,7 @@ #================================================================================ if [ "${GOVC_URL}" = "" ] ; then - printf "\n%bERROR : You must log to govc before using this script.%b\n\n" "${RED}" "${STD}" ; exit 1 + printf "\n%bERROR : You must log to govc before using this script.%b\n" "${RED}" "${STD}" ; exit 1 fi #--- Check scripts options @@ -32,7 +32,7 @@ while [ ${nbParameters} -gt 0 ] ; do else vm_name="$(govc vm.info -vm.ip=${vm_ip} | grep "Name:" | sed -e "s+^Name: *++g")" if [ "${vm_name}" = "" ] ; then - printf "\n%bERROR : No existing vm with ip \"${vm_ip}\".%b\n\n" "${RED}" "${STD}" ; exit 1 + printf "\n%bERROR : No existing vm with ip \"${vm_ip}\".%b\n" "${RED}" "${STD}" ; exit 1 fi fi ;; @@ -43,7 +43,7 @@ while [ ${nbParameters} -gt 0 ] ; do vm_disk_id="$(echo "${vm_disk_id}" | tr [:upper:] [:lower:])" vm_id="$(govc object.collect -json -type m / config.hardware.device | jq -r '.|select(.changeSet[].val._value[].backing.fileName|tostring|match("'$vm_disk_id'")) | [.obj.type, .obj.value] | join(":")')" if [ "${vm_id}" = "" ] ; then - printf "\n%bERROR : No existing vm with disk id \"${vm_disk_id}\".%b\n\n" "${RED}" "${STD}" ; exit 1 + printf "\n%bERROR : No existing vm with disk id \"${vm_disk_id}\".%b\n" "${RED}" "${STD}" ; exit 1 fi vm_ipath="$(echo "${vm_id}" | xargs govc ls -L | xargs -I {} -n 1 echo "{}")" vm_name="$(govc vm.info -vm.ipath="${vm_ipath}" | grep "Name:" | awk '{print $2}')" @@ -56,7 +56,7 @@ while [ ${nbParameters} -gt 0 ] ; do vm_macaddress="$(echo "${vm_macaddress}" | tr [:upper:] [:lower:])" vm_id="$(govc object.collect -json -type m / config.hardware.device | jq -r '. | select(.changeSet[].val.virtualDevice[].macAddress == "'$vm_macaddress'") | [.obj.type, .obj.value] | join(":")')" if [ "${vm_id}" = "" ] ; then - printf "\n%bERROR : No existing vm with mac address \"${vm_macaddress}\".%b\n\n" "${RED}" "${STD}" ; exit 1 + printf "\n%bERROR : No existing vm with mac address \"${vm_macaddress}\".%b\n" "${RED}" "${STD}" ; exit 1 fi vm_ipath="$(echo "${vm_id}" | xargs govc ls -L | xargs -I {} -n 1 echo "{}")" vm_name="$(govc vm.info -vm.ipath="${vm_ipath}" | grep "Name:" | awk '{print $2}')" @@ -75,12 +75,13 @@ done printf "\n%bGet \"${vm_name}\" properties...%b\n" "${REVERSE}${YELLOW}" "${STD}" vm_info="$(govc vm.info -json ${vm_name} | jq -r '.virtualMachines[]' 2> /dev/null)" if [ "${vm_info}" = "" ] ; then - printf "\n%bERROR : No existing vm with name \"${vm_name}\".%b\n\n" "${RED}" "${STD}" ; exit 1 + printf "\n%bERROR : No existing vm with name \"${vm_name}\".%b\n" "${RED}" "${STD}" ; exit 1 fi vm_host="$(govc vm.info ${vm_name} | awk '/Host/ {print $2}' 2> /dev/null)" hw_version="$(echo "${vm_info}" | jq -r '.config.version' 2> /dev/null)" vm_datastore="$(echo "${vm_info}"| jq -r '.config.datastoreUrl[].name' 2> /dev/null | tr '\n' ',' | sed -e "s+,$++" -e "s+,+, +g")" +vm_disk_persistent_id="$(echo "${vm_info}" | jq -r '.config.vAppConfig.property[].id' 2> /dev/null)" power_state="$(echo "${vm_info}" | jq -r '.summary.runtime.powerState' 2> /dev/null)" vm_uptime="$(echo "${vm_info}" | jq -r '.summary.quickStats.uptimeSeconds' 2> /dev/null)" vm_uptime_days="$(expr ${vm_uptime} / 86400)" @@ -108,22 +109,25 @@ if [ "${bosh_properties}" != "null" ] ; then instance="$(echo "${bosh_properties}" | jq -r --arg KEY "${key}" '.[]|select(.key|tostring == $KEY)|.value')" key="$(echo "${tags}" | jq -r '.|select(.name == "created_at")|.key')" created="$(echo "${bosh_properties}" | jq -r --arg KEY "${key}" '.[]|select(.key|tostring == $KEY)|.value')" - printf "bosh director : ${director}\n" - printf "bosh deployment : ${deployment}\n" - printf "bosh instance : ${instance}\n" - printf "bosh created : ${created}\n\n" + printf "bosh director : ${director}\n" + printf "bosh deployment : ${deployment}\n" + printf "bosh instance : ${instance}\n" + printf "bosh created : ${created}\n\n" fi -printf "vm name : ${vm_name}\n" -printf "vm host : ${vm_host}\n" -printf "vm datastore : ${vm_datastore}\n" -printf "vm hw version : ${hw_version}\n" -printf "vm power state : ${power_state}\n" -printf "vm uptime : ${vm_uptime}\n" -printf "cpus : ${nb_cpus}\n" -printf "memory size Mb : ${memory_size}\n" -printf "ethernet cards : ${nb_ethernet}\n" -printf "vm ips : ${vm_ips}\n" -printf "vm macAddress : ${macAddress}\n" -printf "disks : ${nb_diks}\n" +printf "vm name : ${vm_name}\n" +printf "vm host : ${vm_host}\n" +printf "vm datastore : ${vm_datastore}\n" +if [ "${vm_disk_persistent_id}" != "" ] ; then + printf "persistent disk id : ${vm_disk_persistent_id}\n" +fi +printf "vm hw version : ${hw_version}\n" +printf "vm power state : ${power_state}\n" +printf "vm uptime : ${vm_uptime}\n" +printf "cpus : ${nb_cpus}\n" +printf "memory size Mb : ${memory_size}\n" +printf "ethernet cards : ${nb_ethernet}\n" +printf "vm ips : ${vm_ips}\n" +printf "vm macAddress : ${macAddress}\n" +printf "disks : ${nb_diks}\n" govc guest.df -vm ${vm_name}