Created
October 13, 2017 10:07
-
-
Save maurorappa/da98cf5c3c596d3c05e3fd40302b15de to your computer and use it in GitHub Desktop.
ovf_fiddler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script to edit the OVF Vm descriptor file, in this case change the memory size unit and remove the "System" part in the xml | |
# this was need to be able to import the OVF Vm from Virtualbox to Vsphere | |
import lxml.etree as et | |
import sys | |
import os | |
file_name = sys.argv[1] | |
try: | |
os.path.isfile(file_name) | |
except: | |
print("file not found!") | |
fh = open(file_name) | |
data = fh.read() | |
fh.close() | |
data = data.replace("MegaBytes", "byte * 2^20") | |
tree = et.fromstring(data) | |
ns = { | |
"def": "http://schemas.dmtf.org/ovf/envelope/1", | |
"ovf": "http://schemas.dmtf.org/ovf/envelope/1", | |
"rasd": "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData", | |
"vssd": "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData", | |
"xsi": "http://www.w3.org/2001/XMLSchema-instance", | |
"vbox": "http://www.virtualbox.org/ovf/machine"} | |
for bad in tree.xpath("//def:System", namespaces=ns): | |
bad.getparent().remove(bad) | |
#print et.tostring(tree, pretty_print=True) | |
#os.rename(file_name, file_name + '.bak') | |
fh = open(file_name, "w+") | |
fh.write(et.tostring(tree)) | |
fh.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment