Advertisement
j_melis

Untitled

Sep 27th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. from xml.dom.minidom import parseString
  5.  
  6. def parse(file):
  7. config = {}
  8. dom = parseString(file)
  9. section = dom.getElementsByTagName("ns1:PropertySection")[0]
  10. for property in section.getElementsByTagName("ns1:Property"):
  11. key = property.getAttribute("ns1:key")
  12. value = property.getAttribute("ns1:value")
  13. config[key] = value
  14. dom.unlink()
  15. return config
  16.  
  17. # Check for argument
  18. try:
  19. ovf_file = sys.argv[1]
  20. except IndexError:
  21. print "Supply a file as an argument."
  22. sys.exit(1)
  23.  
  24. # Read file
  25. try:
  26. ovf = open(ovf_file).read()
  27. except IOError:
  28. print "Unable to read file '%s'." % ovf_file
  29. sys.exit(1)
  30.  
  31. # Parse ovf context file
  32. ovf_config = parse(ovf)
  33.  
  34. # `ovf_config` will be a dictionary, for example:
  35. #{ u'org.linuxdist.x.ExternalGateway': u'84.21.173.254',
  36. # u'org.linuxdist.x.ExternalIP': u'84.21.173.158',
  37. # u'org.linuxdist.x.TARGET_CONF': u'hdc',
  38. # u'org.linuxdist.x.hostname': u'balancer'}
  39.  
  40. ################################################################################
  41. # Insert user script here #
  42. ################################################################################
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement