From 89760285c64c81ddb39751a5dc564937626a7c33 Mon Sep 17 00:00:00 2001 From: Marco Yuen <marcoy@gmail.com> Date: Tue, 22 Feb 2011 12:21:18 -0500 Subject: [PATCH] Fix the Eucalyptus RSpec schema. --- .../eucalyptus/euca_rspec_validator.py | 28 +++++++++++++++++++ sfa/managers/eucalyptus/eucalyptus.rnc | 6 ++-- sfa/managers/eucalyptus/eucalyptus.rng | 8 ++++-- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 sfa/managers/eucalyptus/euca_rspec_validator.py diff --git a/sfa/managers/eucalyptus/euca_rspec_validator.py b/sfa/managers/eucalyptus/euca_rspec_validator.py new file mode 100755 index 00000000..7e25063d --- /dev/null +++ b/sfa/managers/eucalyptus/euca_rspec_validator.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from __future__ import with_statement +import sys +import os +from lxml import etree as ET + +## +# The location of the RelaxNG schema. +# +EUCALYPTUS_RSPEC_SCHEMA='eucalyptus.rng' + +def main(): + with open(sys.argv[1], 'r') as f: + xml = f.read() + schemaXML = ET.parse(EUCALYPTUS_RSPEC_SCHEMA) + rspecValidator = ET.RelaxNG(schemaXML) + rspecXML = ET.XML(xml) + if not rspecValidator(rspecXML): + error = rspecValidator.error_log.last_error + message = '%s (line %s)' % (error.message, error.line) + print message + else: + print 'It is valid' + +if __name__ == "__main__": + main() + diff --git a/sfa/managers/eucalyptus/eucalyptus.rnc b/sfa/managers/eucalyptus/eucalyptus.rnc index 49c1f339..ba9758c4 100644 --- a/sfa/managers/eucalyptus/eucalyptus.rnc +++ b/sfa/managers/eucalyptus/eucalyptus.rnc @@ -48,8 +48,8 @@ vm_type = element vm_type { cores, memory, disk_space, - request?, - euca_instances? + euca_instances?, + request? } request = element request { @@ -74,7 +74,7 @@ euca_instance = element euca_instance { attribute id { xsd:ID }, state, public_dns, - keypair + keypair? } ipv4 = element ipv4 { text } type = element type { text } diff --git a/sfa/managers/eucalyptus/eucalyptus.rng b/sfa/managers/eucalyptus/eucalyptus.rng index ec91e05b..51d23c64 100644 --- a/sfa/managers/eucalyptus/eucalyptus.rng +++ b/sfa/managers/eucalyptus/eucalyptus.rng @@ -106,10 +106,10 @@ <ref name="memory"/> <ref name="disk_space"/> <optional> - <ref name="request"/> + <ref name="euca_instances"/> </optional> <optional> - <ref name="euca_instances"/> + <ref name="request"/> </optional> </element> </define> @@ -144,7 +144,9 @@ </attribute> <ref name="state"/> <ref name="public_dns"/> - <ref name="keypair"/> + <optional> + <ref name="keypair"/> + </optional> </element> </define> <define name="ipv4"> -- 2.47.0