Roy Golan has uploaded a new change for review.

Change subject: Convert OVF to VDSM create parameters (vm.conf)
......................................................................

Convert OVF to VDSM create parameters (vm.conf)

Change-Id: Ie7dd763dd701158e945ed2006520c6a073318d2c
Signed-off-by: Roy Golan <rgo...@redhat.com>
---
A src/ovirt_hosted_engine_setup/ovf/ovf2vmConf.py
1 file changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/42/42342/1

diff --git a/src/ovirt_hosted_engine_setup/ovf/ovf2vmConf.py 
b/src/ovirt_hosted_engine_setup/ovf/ovf2vmConf.py
new file mode 100644
index 0000000..5350d25
--- /dev/null
+++ b/src/ovirt_hosted_engine_setup/ovf/ovf2vmConf.py
@@ -0,0 +1,64 @@
+import ovfenvelope
+import os
+import sys
+import tempfile
+import shutil
+
+RES_ALLOCATION_NS = 'Content/Section/Item/{' \
+                    'http://schemas.dmtf.org/wbem/wscim/1/cim-schema' \
+                    '/2/CIM_ResourceAllocationSettingData' \
+                    '}'
+
+OVF_NS = '{http://schemas.dmtf.org/ovf/envelope/1/}'
+
+DISPLAY_TYPES = {
+    1: 'vga',
+    2: 'cirrus',
+    3: 'qxl'
+}
+
+
+def getCpuType():
+    return {}
+
+
+def ovf2vmConf(ovfPath):
+    tmpdir = tempfile.mkdtemp()
+    tree = ovfenvelope.etree_.parse(
+        os.path.join(
+            tmpdir,
+            ovfPath,
+        )
+    )
+    vmConf = {}
+    # general
+    vmConf['vmId'] = tree.find('Content/Section').attrib[OVF_NS + 'id']
+    vmConf['vmName'] = tree.find('Content/Name').text
+    vmConf['display'] = DISPLAY_TYPES.get(
+        int(tree.find('Content/DefaultDisplayType').text))
+    vmConf['cpuType'] = getCpuType()
+    # disks
+    disk = tree.find('Section/Disk')
+    disksize = int(disk.attrib[OVF_NS + 'size'])
+    diskalias = disk.attrib[(OVF_NS + 'disk-alias')]
+    diskpath = disk.attrib[(OVF_NS + 'fileRef')]
+    # cpu
+    num_of_sockets = int(tree.find(RES_ALLOCATION_NS + 'num_of_sockets').text)
+    cpu_per_socket = int(tree.find(RES_ALLOCATION_NS + 'cpu_per_socket').text)
+    vmConf['smp'] = num_of_sockets * cpu_per_socket
+    # mem
+    # TODO use it to convert memSize
+    unit = tree.find(RES_ALLOCATION_NS + 'AllocationUnits').text
+    vmConf['memSize'] = tree.find(RES_ALLOCATION_NS + 'VirtualQuantity').text
+    shutil.rmtree(tmpdir)
+    return vmConf
+
+
+class VmConf():
+    def __init__(self, ovfObj):
+        self.ovfObj = ovfObj
+
+
+if __name__ == '__main__':
+    vmConf = ovf2vmConf(sys.argv[1])
+    print(vmConf)


-- 
To view, visit https://gerrit.ovirt.org/42342
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7dd763dd701158e945ed2006520c6a073318d2c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: master
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to