Skip to content

Instantly share code, notes, and snippets.

@eshizhan
Last active April 25, 2021 22:05
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save eshizhan/6650285 to your computer and use it in GitHub Desktop.
Save eshizhan/6650285 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
#
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('vmx_' + fn, 'wb')
nfp.write(fp.encode('utf8'))
nfp.close()
@obtim
Copy link

obtim commented Jan 16, 2014

There is a problem when using the script:
C:\Users\test>C:\Python34\python.exe c:\temp\conv2vmx-ovf.py c:\temp\inventor
t 1.4.ova
Traceback (most recent call last):
File "c:\temp\conv2vmx-ovf.py", line 11, in
fp = open(fn).read()
FileNotFoundError: [Errno 2] No such file or directory: 'c:\temp\inventort'

C:\Users\test>C:\Python34\python.exe c:\temp\conv2vmx-ovf.py c:\temp\4.ova
Traceback (most recent call last):
File "c:\temp\conv2vmx-ovf.py", line 11, in
fp = open(fn).read()
File "C:\Python34\lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 79043: ch
aracter maps to

Operating System: Windows 7 SP1 Russian x64
Python 3.4.0 beta 2
Full admin rights in the system
Antivirus is disabled
Ova template is 679834 kb

@eshizhan
Copy link
Author

You need export ovf, NOT ova.

@minhoryang
Copy link

Without ".decode('utf-8')" at line 11, it run well with python 3.3. Thanks!

@eshizhan
Copy link
Author

Supportting Python 2.x and 3.x now.

@Low351
Copy link

Low351 commented Mar 3, 2015

Thanks eshizhan, this script helped me :) I used python 2.7.8 on Cygwin.

obtim, I realize your post is old but as information for anyone who follow, to work with the .ovf files simply untar the .ova and retar it.

create a new directory and untar the .ova file to it (all this was done in Cygwin but should work on any 'nix)

$ 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 *

and now you should have a fixed .ova file in workdir

@fxpester
Copy link

fxpester commented Apr 1, 2015

works like a charm on Mac OS X and CentOS

@dandye
Copy link

dandye commented Apr 1, 2015

Another issue is the order of the RASD fields:

"The DMTF RASD specifies a set of fields that can be set. We only a subset of those fields in an OVF descriptor. The fields in a RASD must be ordered alphabetically."[1]

[1] http://blogs.vmware.com/vapp/2009/11/virtual-hardware-in-ovf-part-1.html

@tobia
Copy link

tobia commented Jul 10, 2015

Many thanks.

Works like a charm to import the free IE 7/8/9/10/11 Virtual machines from Microsoft into a VMWare vSphere 5.

Just download and unpack the RAR (you can use any RAR utility on the .sfx) then unpack the OVA using a TAR utility, run this script on the OVF, and import the converted OVF into vSphere Client (File > Deploy OVF Template)

@gotvach
Copy link

gotvach commented Aug 6, 2015

It really helped me out today for importing into vSphere 5.1. Thanks for sharing this!

@nbolton
Copy link

nbolton commented Mar 3, 2016

C:\Users\Nick\Documents>conv2vmx-ovf.py ws1-vm1.ova
Traceback (most recent call last):
  File "C:\Users\Nick\Documents\conv2vmx-ovf.py", line 13, in <module>
    fp = fp.decode('utf-8')
  File "C:\Python26\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 13948: inval
id start byte

@nbolton
Copy link

nbolton commented Mar 3, 2016

Ah, terrible UI...

image

@SaxHornet
Copy link

Hy nbolton, How to fix your error you've got above ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment