Авторские статьи об OpenSource

Reboot in command-line of virtual machine Proxmox VE.


If you haven’t heard about Proxmox VE, you should better memorize it. It will be useful when you need comfortable and free solution for implementation of virtualization. Proxmox VE is Debian Linux + web interface, because of which you will access to powerful functional of hypervisor KVM, Qemu, container LXC and Ceph. Proxmox VE has advanced API allowing realizing an alternate way to access your virtual machines. In this article we will tell about command-line utility pvesh which uses API and helps admin with automation of his daily tasks. We face the task to reboot the virtual machine not with the own commands from the schedulers of operating system (from the inside of virtual machine), but from outside by means of Proxmox VE. Namely, to send a signal as if the power button that orders virtual server to wrap it up is pressed.

We would like to create a solution that will not be anchored to a current location of virtual machines on physical servers in virtualization cluster. My colleagues and I actively use Live Migration and nowadays VM1 works on node2, and tomorrow it will be sent online to node3.

This request immediately put paid to the use of low-level command qm, which demands ordering from that cluster node, where the exact virtual machine is working. I have already displayed the power of PveSh in examples since it uses API Proxmox VE and allows putting plans into action.

Before rebooting the servers we should remember that there was given valuable advice about preparing them for work in virtualization environment for MS Windows Server. While attempting to turn them off with the help of web interface or in the console, you will receive a request. We must change such behavior.

Windows 2008 guest best practices
Windows 2012 guest best practices

Unfortunately, when you press virtual power button you turn off the virtual server instead of rebooting it. That is, you will have "restart" in the meaning "shutdown + start". For script’s work only jq is required. The default repositories Debian and Ubuntu have it and it facilitates the work with JSON answers. Script’s work is not very difficult. At first, according to the given VMID we get node-name for our cluster on which the virtual machine is working at the moment. Make shutdown. Then we interrogate the status at infinite loop and when it becomes stopped we can interrupt the loop while and start the virtual machine.

#!/bin/bash
# vasilisc.com
clear

if ! [ -x "$(command -v jq)" ]; then
        echo 'Error: jq is not installed.' >&2
        echo "apt-get install jq"
        exit 1
fi

if [ -z $1 ]; then
        echo "Use "$0" VMID"
        exit 1
fi

VMID=$1
NODE=`pvesh get /cluster/resources --type vm | jq --raw-output ".[] | select(.vmid == ${VMID}) | .node"`

# shutdown VM
pvesh create /nodes/${NODE}/qemu/${VMID}/status/shutdown

# get status
while true 
do
        STATUS=`pvesh get /nodes/${NODE}/qemu/${VMID}/status/current | jq --raw-output ".status"`
        echo "NODE="${NODE}" VMID="${VMID}" is "${STATUS}
        sleep 5

        if [ "${STATUS}" == "stopped" ]; then
        		break
        fi
done

# start
sleep 5
pvesh create /nodes/${NODE}/qemu/${VMID}/status/start
date

exit 0

Proxmox VE API. Access.
Proxmox VE API. Cluster.
Proxmox VE API. Storage.
Proxmox VE API. Pools.
Proxmox VE API. Versions.
Proxmox VE API. Nodes.

    Twitter   


Разделы

Главная
Новости
Ворох бумаг
Видео Linux
Игры в Linux
Безопасность
Статьи о FreeBSD
Статьи об Ubuntu
Статьи о Snappy
Статьи об Ubuntu Phone
Статьи о Kubuntu
Статьи о Xubuntu
Статьи о Lubuntu
Статьи об Open Source
Карта сайта

Лучшее на сайте:

1С под Linux.   Ускорение Ubuntu.   21 пример iptables.   Цикл статей о Ceph.   Убунту в дикой среде.   Ubuntu Linux на SSD.   Ubuntu для блондинок.   Поддержка железа в Linux.   BTSync на службе у админа.   Андроид программы в Ubuntu.   Прокидывание портов для p2p.   Анти СПАМ в Postfix.  



Круги Гугл Ада.


Группа поддержки