From 4c936f6fab5120bc85ef540d85a69f8ebd648c8a Mon Sep 17 00:00:00 2001 From: stephane Date: Tue, 26 May 2015 16:39:37 -0700 Subject: [PATCH] Add ability to write CSV file Let users write the CSV content out to a file rather than redirecting, copy/paste, etc. etc. Change-Id: Icdae8bfd197c015fb803558668b77c9c7a420611 --- tools/create_vm_nodes.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/create_vm_nodes.sh b/tools/create_vm_nodes.sh index 0b156d9ca..f488745b4 100755 --- a/tools/create_vm_nodes.sh +++ b/tools/create_vm_nodes.sh @@ -17,6 +17,9 @@ # # Create 3 nodes with base name of 'junk' # sudo NODEBASE=junk NODECOUNT=3 create_nodes.sh # +# # Write out the csv file +# sudo OUTFILE=/path/to/file.csv create_nodes.sh +# # THANKS # Thanks to the author(s) of the Ironic supporting code within devstack, # from which all of this is derived. @@ -47,7 +50,6 @@ VM_LOGDIR=/var/log/libvirt/baremetal_logs CSV_OUTPUT="CSV entries:" - ############################################################################# # FUNCTION # create_node @@ -213,12 +215,19 @@ then exit 1 fi +CSV_LINES=() +IFS=$'\n' for (( i=1; i<=${NODECOUNT}; i++ )) do name=${NODEBASE}${i} mac=$(create_node $name $VM_CPU $VM_RAM $VM_DISK amd64 $VM_NET_BRIDGE $VM_EMULATOR $VM_LOGDIR) - CSV_OUTPUT="${CSV_OUTPUT}\n$mac,root,undefined,192.168.122.1,$VM_CPU,$VM_RAM,$VM_DISK,flavor,type,a8cb6624-0d9f-c882-affc-046ebb96ec0${i},$name,192.168.122.$((i+1))" + CSV_LINES+=("$mac,root,undefined,192.168.122.1,$VM_CPU,$VM_RAM,$VM_DISK,flavor,type,a8cb6624-0d9f-c882-affc-046ebb96ec0${i},$name,192.168.122.$((i+1))") done -echo -e "${CSV_OUTPUT}" +echo ${CSV_OUTPUT} +echo -e "${CSV_LINES[*]}" + +if [ $OUTFILE ]; then + echo -e "${CSV_LINES[*]}" > $OUTFILE +fi