Bug 683 Modify the ovf_converter tool to have a option for adding a cd/dvd device 37/7437/2
authorAnanda Baitharu <ananda.baitharu@riftio.com>
Mon, 29 Apr 2019 19:24:16 +0000 (19:24 +0000)
committerAnanda Baitharu <ananda.baitharu@riftio.com>
Wed, 22 May 2019 10:54:01 +0000 (10:54 +0000)
Change-Id: Ibc754d0b2bd68ddb788252299f888a64dfa598f4
Signed-off-by: Ananda Baitharu <ananda.baitharu@riftio.com>
tools/OVF_converter/format_converter/converter.py
tools/OVF_converter/format_converter/ovf_converter_cli.py
tools/OVF_converter/ovf_template/ide_cdrom.xml [new file with mode: 0644]
tools/OVF_converter/readme.txt

index 3c647a9..ca2a369 100644 (file)
@@ -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" )
 
index 209c05d..a505bfe 100644 (file)
@@ -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 (file)
index 0000000..ffab392
--- /dev/null
@@ -0,0 +1,19 @@
+<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>
index 0e6117b..f74acb1 100644 (file)
@@ -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: