Skip to content

Commit

Permalink
✨ check QEMU guest agent during backup
Browse files Browse the repository at this point in the history
  • Loading branch information
bunop committed Feb 8, 2022
1 parent d3c8afd commit 7b82a04
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import signal
import subprocess
import uuid
import json

# To inspect xml
import xml.etree.ElementTree as ET

import libvirt
import libvirt_qemu

# Logging istance
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -188,6 +190,27 @@ def domainIsActive(self):

return False

def domainHasGuestAgent(self):
"""Test if Guest Agent is up and running"""

try:
response = libvirt_qemu.qemuAgentCommand(
self.domain,
'{"execute":"guest-ping"}',
timeout=30,
flags=0)

except libvirt.libvirtError as error:
logger.error(error)
return False

data = json.loads(response)

if 'return' in data:
return True

return False

def getDisks(self):
"""Call getDisk on my instance"""

Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* copy CD-rom data
* testing wrong configurations
* rotating using dates, not numbers
* dealing with power off VM (delete snapshot will not update domain)
* dealing with power off VM
* deal with empty configurations
* python packaging?
7 changes: 7 additions & 0 deletions kvmBackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def backup(domain, parameters, backupdir):
"domain '%s' is not Active: is VM up and running?" % domain)
raise NotImplementedError("Cannot backup an inactive domain!")

# check that guest agent is Up and running
if not snapshot.domainHasGuestAgent():
logger.error("QEMU guest agent is a requisite for a safe snapshot")
logger.error("Please check kvmBackup wiki pages for more info")
raise RuntimeError(
"Guest agent is not running. Check '%s' domain" % domain)

# check if no snapshot are defined
if snapshot.hasCurrentSnapshot() is True:
raise Exception("Domain '%s' has already a snapshot" % (domain))
Expand Down

0 comments on commit 7b82a04

Please sign in to comment.