MODULE_DIR = os.path.dirname(__file__)
OVF_TEMPLATE_PATH = os.path.join(os.path.dirname(MODULE_DIR),
"ovf_template/template.xml")
+IDE_CDROM_XML_PATH = os.path.join(os.path.dirname(MODULE_DIR),
+ "ovf_template/ide_cdrom.xml")
OS_INFO_FILE_PATH = os.path.join(os.path.dirname(MODULE_DIR),
"config/os_type.yaml")
DISK_CONTROLLER_INFO_FILE_PATH = os.path.join(os.path.dirname(MODULE_DIR),
def __init__(self, source_img_path, output_location=None, output_ovf_name=None,
memory=None, cpu=None, disk=None, os_type=None,
- disk_controller=None,
+ disk_controller=None, cdrom=None,
options={'subformat':'streamOptimized'}):
"""
Constructor to initialize object of class OVFConverter
self.memory = str(memory) if memory is not None else None
self.cpu = str(cpu) if cpu is not None else None
self.os_type=str(os_type).strip() if os_type else None
+ self.cdrom = cdrom
if self.os_type:
self.osID , self.osType = self.__get_osType()
resource_subtype.getparent().remove(resource_subtype)
if "resourceSubType" in self.disk_controller_info:
resource_subtype.text = self.disk_controller_info["resourceSubType"]
-
- #Save output OVF
+ if self.cdrom:
+ last_item = list(virtualHardwareSection.iterfind('xmlns:Item',nsmap))[-1]
+ ide_cdrom_items_etree = ET.parse(IDE_CDROM_XML_PATH)
+ ide_cdrom_items = list(ide_cdrom_items_etree.iterfind('Item'))
+ for item in ide_cdrom_items:
+ last_item.addnext(item)
+
+ # Save output OVF
OVF_tree.write(self.output_path, xml_declaration=True,encoding='utf-8',
method="xml" )
" (default controller SCSI with lsilogicsas) "\
"(SATA, IDE, Paravirtual, Buslogic, Lsilogic, Lsilogicsas) (optional)")
+ parser.add_argument("--cdrom", action="store_true",
+ help="whether to include a cd/dvd device (optional)")
+
args = parser.parse_args()
if args.path:
disk=args.disk,
os_type=args.osType,
disk_controller=args.disk_Controller,
+ cdrom=args.cdrom,
)
print("#### Start OVF conversion ####")
--- /dev/null
+<Items>
+ <Item xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">
+ <rasd:AddressOnParent>0</rasd:AddressOnParent>
+ <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
+ <rasd:Description>CD/DVD Drive</rasd:Description>
+ <rasd:ElementName>CD/DVD Drive 1</rasd:ElementName>
+ <rasd:HostResource/>
+ <rasd:InstanceID>3002</rasd:InstanceID>
+ <rasd:Parent>50</rasd:Parent>
+ <rasd:ResourceType>15</rasd:ResourceType>
+ </Item>
+ <Item xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">
+ <rasd:Address>1</rasd:Address>
+ <rasd:Description>IDE Controller</rasd:Description>
+ <rasd:ElementName>IDE Controller 1</rasd:ElementName>
+ <rasd:InstanceID>50</rasd:InstanceID>
+ <rasd:ResourceType>5</rasd:ResourceType>
+ </Item>
+</Items>
root@ubuntu:/home/vmware/OVF_converter# ovf_converter -h
Usage: ovf_converter_cli.py [-h] [-v] [-o OUTPUT_LOCATION] [-n OVF_NAME]
[-m MEMORY] [-c CPU] [-d DISK] [-s OSTYPE]
- [-dc DISK_CONTROLLER]
+ [-dc DISK_CONTROLLER] [--cdrom]
path
OVF converter to convert .qcow2 or raw image into OVF
required disk controller type (default controller SCSI
with lsilogicsas) (SATA, IDE, Paravirtual, Buslogic,
lsilogic, lsilogicsas) (optional)
+ --cdrom whether to include a cd/dvd device (optional)
o Create OVF file from qcow2 or raw disk image as: