Commit d5c535da by Guba Sándor Committed by Őry Máté

dashboard: add exception handling

parent 842b98c9
from django.core.exceptions import ValidationError
from lxml import etree as ET
import logging
rng_file = "/usr/share/libvirt/schemas/domain.rng"
header = """<domain type='kvm'>
<memory unit='KiB'>1024</memory>
footer = """</domain>"""
# Mandatory xml elements dor parsing
header = "<domain type='kvm'><name>validator</name>\
<memory unit='KiB'>1024</memory>\
footer = "</domain>"
logger = logging.getLogger()
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)
parsed_xml = ET.fromstring(xml)
except Exception as e:
raise ValidationError(e.message)
relaxng = ET.RelaxNG(file=rng_file)
logger.critical("%s RelaxNG libvirt domain schema file "
"is missing for validation.", rng_file)
except Exception as e:
raise ValidationError(e.message)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment