Skip to content

Instantly share code, notes, and snippets.

@jeffrey4l
Created November 14, 2023 01:44
Show Gist options
  • Save jeffrey4l/5c4ad62188d79f41067e9e276f17553d to your computer and use it in GitHub Desktop.
Save jeffrey4l/5c4ad62188d79f41067e9e276f17553d to your computer and use it in GitHub Desktop.
#!/bin/bash
#==============请修改flavor image_id net_id availab_zone vm_name为环境对应参数===============================
flavor_id=2u2g
image_id=bdf6c505-f208-43cc-b85f-e19bbca05b1a
net_id=9978dfe6-9e7f-4746-83d7-242de771f4e3
availab_zone=az1.dc1
vm_name=test_poc_150vm
#================以下不可更改====================================================================
sysVolumeSize=8
source_type=image
prall_count=150
vm_operate=create
nova boot --flavor $flavor_id --block-device id=$image_id,source=$source_type,dest=volume,type=disk,size=$sysVolumeSize,bootindex=0,shutdown=remove --nic net-id=$net_id --availability-zone=$availab_zone --min=$prall_count $vm_name &
echo waiting create_vm complete
sleep 5
#==================检查VM状态======================================
while [[ 1 -eq 1 ]]
do
active_res=`openstack server list | grep $vm_name | grep -w ACTIVE | wc -l`
echo success_num=$active_res &
if((active_res==prall_count)); then
break;
fi
done
#==================获取端到端精确时间==============================
timeItemArr=()
for vmid in `openstack server list | grep $vm_name | grep -w ACTIVE | awk '{print $2}'`; do
vm_oper_line=`nova instance-action-list $vmid | tail -2 | head -1`
temp_vm_oper=`echo $vm_oper_line | awk '{print $2}'`
if [ "$vm_operate"x != "$temp_vm_oper"x ]; then
echo VM[$vmid] Operation[$temp_vm_oper] is not $vm_operate, please check whether is someOne operated the vm at the same time.
exit 0;
fi
vm_reqId=`echo $vm_oper_line | awk '{print $4}'`
vm_oper_info=`nova instance-action $vmid $vm_reqId`
startTime=`echo "${vm_oper_info}" | awk '/\|(\x20)+start_time(\x20)+\|/{"date -d "$4" +%s.%N"| getline time ;print time}'`
endTime=`echo "${vm_oper_info}" | awk -F \' '/\|(\x20)+\|(\x20)+u(\x27)finish_time/{"date -d "$4" +%s.%N" | getline time; print time}'`
timeItemArr=(${timeItemArr[*]} `echo "$startTime"` `echo "$endTime"`)
echo vmid=$vmid vm_reqId=$vm_reqId startTime=`echo $startTime` endTime=`echo $endTime`
done
#echo ${timeItemArr[*]}
min_start_time=`printf '%s\n' "${timeItemArr[@]}" | sort -n | head -1`
max_end_time=`printf '%s\n' "${timeItemArr[@]}" | sort -n | tail -1`
interval=$(echo "scale=2;($max_end_time-$min_start_time)/1" | bc)
echo $vm_operate $prall_count VM, spendTime=$interval s, startTime=`date -d @$min_start_time +"%Y-%m-%d %H:%M:%S.%N"` endTime=`date -d @$max_end_time +"%Y-%m-%d %H:%M:%S.%N"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment