From 3e865c3bc22e932049b090a6e7e206cfe94f58d4 Mon Sep 17 00:00:00 2001 From: Guba Sándor <guba.sandor@cloud.bme.hu> Date: Mon, 21 Jul 2014 17:21:20 +0200 Subject: [PATCH] dashboard: add basic libvirt domain validator --- circle/dashboard/virtvalidator.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 circle/dashboard/virtvalidator.py diff --git a/circle/dashboard/virtvalidator.py b/circle/dashboard/virtvalidator.py new file mode 100644 index 0000000..d9d85b4 --- /dev/null +++ b/circle/dashboard/virtvalidator.py @@ -0,0 +1,20 @@ +from django.core.exceptions import ValidationError +from lxml import etree as ET + + +rng_file = "/usr/share/libvirt/schemas/domain.rng" + +header = """<domain type='kvm'> + <name>validator</name> + <memory unit='KiB'>1024</memory> + <os> + <type>hvm</type> + </os>""" +footer = """</domain>""" + + +def domain_validator(value): + xml = header + value + footer + relaxng = ET.RelaxNG(file=rng_file) + if not relaxng.validate(ET.fromstring(xml)): + raise ValidationError("%s is not valid libvirt Domain xml." % value) -- libgit2 0.26.0