From: Ananda Baitharu Date: Mon, 29 Apr 2019 19:24:16 +0000 (+0000) Subject: Bug 683 Modify the ovf_converter tool to have a option for adding a cd/dvd device X-Git-Tag: v6.0.0~13^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F7437%2F2;p=osm%2Fdevops.git Bug 683 Modify the ovf_converter tool to have a option for adding a cd/dvd device Change-Id: Ibc754d0b2bd68ddb788252299f888a64dfa598f4 Signed-off-by: Ananda Baitharu --- diff --git a/tools/OVF_converter/format_converter/converter.py b/tools/OVF_converter/format_converter/converter.py index 3c647a9b..ca2a3691 100644 --- a/tools/OVF_converter/format_converter/converter.py +++ b/tools/OVF_converter/format_converter/converter.py @@ -33,6 +33,8 @@ from command_progress import CommandProgressbar 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), @@ -62,7 +64,7 @@ class OVFConverter(object): 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 @@ -126,6 +128,7 @@ class OVFConverter(object): 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() @@ -363,8 +366,14 @@ class OVFConverter(object): 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" ) diff --git a/tools/OVF_converter/format_converter/ovf_converter_cli.py b/tools/OVF_converter/format_converter/ovf_converter_cli.py index 209c05d9..a505bfee 100644 --- a/tools/OVF_converter/format_converter/ovf_converter_cli.py +++ b/tools/OVF_converter/format_converter/ovf_converter_cli.py @@ -68,6 +68,9 @@ def execute_cli(): " (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: @@ -79,6 +82,7 @@ def execute_cli(): disk=args.disk, os_type=args.osType, disk_controller=args.disk_Controller, + cdrom=args.cdrom, ) print("#### Start OVF conversion ####") diff --git a/tools/OVF_converter/ovf_template/ide_cdrom.xml b/tools/OVF_converter/ovf_template/ide_cdrom.xml new file mode 100644 index 00000000..ffab3928 --- /dev/null +++ b/tools/OVF_converter/ovf_template/ide_cdrom.xml @@ -0,0 +1,19 @@ + + + 0 + false + CD/DVD Drive + CD/DVD Drive 1 + + 3002 + 50 + 15 + + + 1 + IDE Controller + IDE Controller 1 + 50 + 5 + + diff --git a/tools/OVF_converter/readme.txt b/tools/OVF_converter/readme.txt index 0e6117b9..f74acb1e 100644 --- a/tools/OVF_converter/readme.txt +++ b/tools/OVF_converter/readme.txt @@ -119,7 +119,7 @@ o See all command line options of tool as: 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 @@ -151,6 +151,7 @@ o See all command line options of tool as: 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: