zoukankan      html  css  js  c++  java
  • shell-计算虚拟机创建时间

    因为要验证虚拟机创建时间,所以写了下面一个脚本

    
    #!/bin/bash
    ###########################################################################################
    #
    # This tool is used to test vm   create time
    #
    ###########################################################################################
    
    VM_NUM=$1
    IMAGE_ID=$2
    
    NET_ID=7baf14cb-d2db-4b52-9874-f120363ace34
    FLAVOR_ID=bbc2bc57-42cd-484c-986d-82a5f0d83028
    #Use the uuid as the vm name
    VM_NAME=`cat /proc/sys/kernel/random/uuid`
    
    #create vm
    nova boot  --flavor $FLAVOR_ID    --image $IMAGE_ID   --nic net-id=$NET_ID --max-count $VM_NUM  $VM_NAME
    
    #Record start time
    starttime=`date +'%Y-%m-%d %H:%M:%S'`
    start_seconds=$(date --date="$starttime" +%s);
    
    #Calculate the creation time for each vm
    get_vm_time()
    
    {
    
    local endtime
    local end_seconds
    local vm_time
    local status
    
    
    
    while :; 
    do
    status=`nova show $1 | grep "OS-EXT-STS:vm_state" | awk '{print $4}'` 
    
    case $status in
    "active")
    endtime=`date +'%Y-%m-%d %H:%M:%S'`
    end_seconds=$(date --date="$endtime" +%s);
    echo "create $1 used "$((end_seconds-start_seconds))  "s"
    break
    ;;
    "error")
    echo "create $1 failed" 
    break
    ;;
    esac
    
    done
    
    }
    
    #If you create only one vm ,The name of the virtual machine is : $VM_NAME 
    if [ $VM_NUM -eq 1 ];then
    get_vm_time $VM_NAME >> $VM_NAME.txt &
    
    #If you create multiple vm.Statistics of vm creation time
    else
    	for i in $(seq 1 ${VM_NUM});do
    	get_vm_time $VM_NAME-$i >> $VM_NAME.txt  &
    
    	done
    fi
    
    
  • 相关阅读:
    JAVA课程设计——飞机大战(团队)
    面向对象设计大作业
    OO之接口-DAO模式代码阅读及应用
    有理数类设计
    图总结
    树、二叉树、查找算法总结
    二叉排序树
    数据结构小结
    C语言文件
    小程序云开发:联表查询去重及排序的不严谨笨办法
  • 原文地址:https://www.cnblogs.com/mrwuzs/p/10571707.html
Copyright © 2011-2022 走看看