Skip to content

Instantly share code, notes, and snippets.

@DaffyDuke
Last active March 4, 2017 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaffyDuke/9c8faee53869ba76574a7d10defc89c4 to your computer and use it in GitHub Desktop.
Save DaffyDuke/9c8faee53869ba76574a7d10defc89c4 to your computer and use it in GitHub Desktop.
conversion d'OVA

Voici un petit script qui permet de convertir une image packer buildée avec VBox en fichier OVA utilisable par VMWare.L'idée est de modifier le XML (le .ovf) pour supprimer les contrôleurs IDEs, la carte son, et surtout de modifier le type de virtualisation, sinon VMWare rejette l'image.Source : https://github.com/asyd

"post-processors": [{
"type": "shell-local",
"inline": [
"../bin/ovf-postprocess.py output-demo/rhel7-demo.ovf",
"ovftool --lax output-demo/rhel7-demo.ovf rhel7-demo.ova",
"rm -fr output-demo"
]
}]
#!/usr/bin/env python
from lxml import etree
import argparse
def main(filename):
# Load XML
ovf = etree.parse(filename)
root = ovf.getroot()
# Update VirtualSystemType
virtual_system_type = root.find('.//{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData}VirtualSystemType')
virtual_system_type.text = 'vmx-11'
# Get namespaces dict
nsmap = root.nsmap
# Remove None
nsmap.pop(None)
# Remove IDE controllers and sound card
for section in ["ideController0", "ideController1", "sound"]:
for item in root.xpath('.//rasd:ElementName[text()="%s"]/..' % section, namespaces=nsmap):
print("Item %s removed" % section)
item.getparent().remove(item)
# Finally save the modified XML
with open(filename, 'w') as f:
f.write(etree.tostring(root))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("filename", help='File to modify')
args = parser.parse_args()
main(args.filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment