Skip to content

Instantly share code, notes, and snippets.

@ypid
Forked from eshizhan/conv2vmx-ovf.py
Created January 30, 2016 17:28
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 ypid/a547f58e9823b42cf0ae to your computer and use it in GitHub Desktop.
Save ypid/a547f58e9823b42cf0ae to your computer and use it in GitHub Desktop.
a script that can help import VMs into VMware ESXi from VirtualBox. tested vbox 4.2.18 and ESXi 5.1.
#!/usr/bin/env python
#
# usage:
# conv2vmx-ovf.py some-vm.ovf
#
# ref: http://www.cnblogs.com/eshizhan/p/3332020.html
# ref: https://gist.github.com/eshizhan/6650285
#
# Maybe also worth checking out: https://gist.github.com/robdyke/d81b0f1976be440052af
# https://gist.github.com/Naddmr/1a159610573609095158
#
# https://gist.github.com/eshizhan/6650285#gistcomment-1405082
# mkdir workdir
# $ tar xvf filename.ova -C workdir
# $ cd workdir
# $ conv2vmx-ovf.py filename.ovf
# $ mv vmx_filename.ovf filename.ovf
# $ tar cvf filename.ova *
# Note the order! ovf must come first.
# $ tar cvf $file.ova $file.ovf $file.mf *-disk*
import sys
fn = sys.argv[1]
fp = open(fn).read()
if hasattr(fp, 'decode'):
fp = fp.decode('utf-8')
fp = fp.replace('<OperatingSystemSection ovf:id="80">', '<OperatingSystemSection ovf:id="101">')
fp = fp.replace('<vssd:VirtualSystemType>virtualbox-2.2', '<vssd:VirtualSystemType>vmx-7')
fp = fp.replace('<rasd:Caption>sataController', '<rasd:Caption>scsiController')
fp = fp.replace('<rasd:Description>SATA Controller', '<rasd:Description>SCSI Controller')
fp = fp.replace('<rasd:ElementName>sataController', '<rasd:ElementName>scsiController')
fp = fp.replace('<rasd:ResourceSubType>AHCI', '<rasd:ResourceSubType>lsilogic')
fp = fp.replace('<rasd:ResourceType>20', '<rasd:ResourceType>6')
end = fp.find('<rasd:Caption>sound')
start = fp.rfind('<Item>', 0, end)
fp = fp[:start] + '<Item ovf:required="false">' + fp[start+len('<Item>'):]
nfp = open(fn, 'wb')
nfp.write(fp.encode('utf8'))
nfp.close()
[flake8]
max-line-length = 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment