Create a shell with a case statement (function is open, close, reset, display virtual machine)
#!/bin/bash
Case "$" in
Start)/* When the keyword is start, execute the statement that opens the virtual machine
echo Start ...
Virsh Start $ &>/dev/null
;;
Poweroff)/* Executes a statement that forces the virtual machine to be closed when the keyword is Poweroff
Echo Poweroff ...
Virsh Destroy &>/dev/null
;;
View)/* Executes the statement that displays the virtual machine interface, when the keyword is view
Virt-viewer &>/dev/null &
;;
Reset)/* When the keyword is reset, perform a restart of the virtual machine
echo Reset ...
Echo Poweroff ...
Virsh Destroy $ &>/dev/null/* Forcibly shutting down virtual machine
Echo del $1.xml ...
Virsh undefine $ &>/dev/null/* Delete Front end
Echo Create Disk ...
Qemu-img create-f qcow2-b/var/lib/libvirt/images/$2.img/var/lib/libvirt/images/$2.img &>/dev/null /* Take a snapshot of the hard disk
Echo Create-$ VM ...
Virt-install \/* Create a virtual machine
--name
--ram 1000 \
--DISK/VAR/LIB/LIBVIRT/IMAGES/$2.IMG \/* Create a hard drive directory
--import &>/dev/null &/* Import graphical interface
ECHO Create $ successful!!!
;;
*)
echo "Error:please input Reset|view|start|poweroff after three"
Esac
Create a shell with a case statement (function is open, close, reset, display virtual machine)