virtualisation/vmid: vm id of qm name
This commit is contained in:
parent
9d7d80d8d1
commit
ab6eb33072
1 changed files with 46 additions and 0 deletions
46
gestion/virtualisation/vmid
Executable file
46
gestion/virtualisation/vmid
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
VM_PATH=/etc/pve/qemu-server
|
||||
PVE_PATH=/etc/pve
|
||||
LOCAL_VM_PATH=/etc/pve/local/qemu-server
|
||||
SERIAL_PATH=/var/run/qemu-server
|
||||
|
||||
if [[ ! -d /etc/pve ]]; then
|
||||
echo "Not a proxmox server !"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Please give vmid or pve name"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
if [[ "`whoami`" != "root" ]]; then
|
||||
echo "You must probably be root"
|
||||
exit 42
|
||||
fi
|
||||
|
||||
if [[ $1 != *[!0-9]* ]]; then
|
||||
vmid=$1
|
||||
else
|
||||
echo "Looking for vmid of $1 ..."
|
||||
for host in `ls $PVE_PATH/nodes`; do
|
||||
p=$PVE_PATH/nodes/$host/qemu-server
|
||||
for f in `ls $p`; do
|
||||
grep "name: *$1" $p/$f -q && {
|
||||
vmid=`echo $f | grep -o "[0-9]*"`
|
||||
node=$host
|
||||
echo "Found vmid $vmid"
|
||||
break
|
||||
}
|
||||
done
|
||||
done
|
||||
if [[ -z "$node" ]]; then
|
||||
echo "vmid not found"
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$node" != "`hostname`" ]]; then
|
||||
echo "Wrong node (go to $node)"
|
||||
exit 3
|
||||
fi
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue