Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- from xml.dom.minidom import parseString
- def parse(file):
- config = {}
- dom = parseString(file)
- section = dom.getElementsByTagName("ns1:PropertySection")[0]
- for property in section.getElementsByTagName("ns1:Property"):
- key = property.getAttribute("ns1:key")
- value = property.getAttribute("ns1:value")
- config[key] = value
- dom.unlink()
- return config
- # Check for argument
- try:
- ovf_file = sys.argv[1]
- except IndexError:
- print "Supply a file as an argument."
- sys.exit(1)
- # Read file
- try:
- ovf = open(ovf_file).read()
- except IOError:
- print "Unable to read file '%s'." % ovf_file
- sys.exit(1)
- # Parse ovf context file
- ovf_config = parse(ovf)
- # `ovf_config` will be a dictionary, for example:
- #{ u'org.linuxdist.x.ExternalGateway': u'84.21.173.254',
- # u'org.linuxdist.x.ExternalIP': u'84.21.173.158',
- # u'org.linuxdist.x.TARGET_CONF': u'hdc',
- # u'org.linuxdist.x.hostname': u'balancer'}
- ################################################################################
- # Insert user script here #
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement