Shahar Havivi has uploaded a new change for review.

Change subject: v2v: Import VM from OVA file
......................................................................

v2v: Import VM from OVA file

OVA is a tar file which contain a VM with its Ovf file and its disks as
well.

Change-Id: I0e440748ecc503f4d61e8f4f61bb0c7387589354
Signed-off-by: Shahar Havivi <[email protected]>
---
M vdsm/API.py
M vdsm/rpc/bindingxmlrpc.py
M vdsm/rpc/vdsmapi-schema.json
M vdsm/v2v.py
4 files changed, 58 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/67/43367/1

diff --git a/vdsm/API.py b/vdsm/API.py
index 4c3724e..704f37b 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -1440,6 +1440,9 @@
         return v2v.convert_external_vm(uri, username, password, vminfo, jobid,
                                        self._cif.irs)
 
+    def convertOva(self, ova_path, vminfo, jobid):
+        return v2v.convert_ova(ova_path, vminfo, jobid, self._cif.irs)
+
     def getConvertedVm(self, jobid):
         return v2v.get_converted_vm(jobid)
 
diff --git a/vdsm/rpc/bindingxmlrpc.py b/vdsm/rpc/bindingxmlrpc.py
index b9dd54e..bc74e22 100644
--- a/vdsm/rpc/bindingxmlrpc.py
+++ b/vdsm/rpc/bindingxmlrpc.py
@@ -381,6 +381,10 @@
         api = API.Global()
         return api.convertExternalVm(uri, username, password, vminfo, jobid)
 
+    def convertOva(self, ova_path, vminfo, jobid):
+        api = API.Global()
+        return api.convert_ova(ova_path, vminfo, jobid)
+
     def getConvertedVm(self, jobid):
         api = API.Global()
         return api.getConvertedVm(jobid)
@@ -1109,6 +1113,7 @@
                 (self.getExternalVMs, 'getExternalVMs'),
                 (self.getOvaInfo, 'getOvaInfo'),
                 (self.convertExternalVm, 'convertExternalVm'),
+                (self.convertOva, 'convertOva'),
                 (self.getConvertedVm, 'getConvertedVm'),
                 (self.abortV2VJob, 'abortV2VJob'),
                 (self.deleteV2VJob, 'deleteV2VJob'),
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index 291aee5..b4c577b 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -3947,6 +3947,23 @@
   'data': {'ova_path': 'str'},
   'returns': 'ExternalVmInfo'}
 
+##
+# @Host.convertOva:
+#
+# Convert VM from external file (OVA) to data domain
+#
+# @ova_path:     actual path to the ova file
+#
+# @vminfo:       information of the VM such as name, id etc
+#
+# @jobid:        Assign a UUID to this operation which can be used
+#                to identify it in @HostStats
+#
+# Since: 4.17.0
+##
+{'command': {'class': 'Host', 'name': 'convertOva'},
+  'data': {'ova_path': 'str', 'vminfo': 'ExternalVmInfo',
+  'jobid': 'UUID'}}
 
 ##
 # @Host.convertExternalVm:
diff --git a/vdsm/v2v.py b/vdsm/v2v.py
index e891894..28fb55e 100644
--- a/vdsm/v2v.py
+++ b/vdsm/v2v.py
@@ -167,6 +167,13 @@
     return {'status': doneCode}
 
 
+def convert_ova(ova_path, vminfo, job_id, irs):
+    job = ImportVm.from_ova(ova_path, vminfo, job_id, irs)
+    job.start()
+    _add_job(job_id, job)
+    return {'status': doneCode}
+
+
 def get_ova_info(ova_path):
     ns = {'ovf': _OVF_NS, 'rasd': _RASD_NS}
 
@@ -325,6 +332,8 @@
         self._passwd_file = None
         self._create_command = None
 
+        self._ova_path = None
+
     @classmethod
     def from_libvirt(cls, uri, username, password, vminfo, job_id, irs):
         obj = cls(vminfo, job_id, irs)
@@ -334,6 +343,14 @@
         obj._password = password
         obj._passwd_file = os.path.join(_V2V_DIR, "%s.tmp" % job_id)
         obj._create_command = cls._from_libvirt_command
+        return obj
+
+    @classmethod
+    def from_ova(cls, ova_path, vminfo, job_id, irs):
+        obj = cls(vminfo, job_id, irs)
+
+        obj._ova_path = ova_path
+        obj._create_command = cls._from_ova_command
         return obj
 
     def start(self):
@@ -453,6 +470,22 @@
                     self._vminfo['vmName']])
         return cmd
 
+    def _from_ova_command(self):
+        cmd = [_VIRT_V2V.cmd,
+               '-i', 'ova', self._ova_path,
+               '-o', 'vdsm',
+               '-of', self._get_disk_format(),
+               '-oa', self._vminfo.get('allocation', 'sparse').lower(),
+               self._generate_disk_parameters(),
+               '--vdsm-vm-uuid',
+               self._id,
+               '--vdsm-ovf-output',
+               _V2V_DIR,
+               '--machine-readable',
+               '-os',
+               get_storage_domain_path(self._prepared_volumes[0]['path'])]
+        return cmd
+
     def abort(self):
         self._status = STATUS.ABORTED
         logging.info('Job %r aborting...', self._id)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e440748ecc503f4d61e8f4f61bb0c7387589354
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Shahar Havivi <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to