With this module, we will be able to implement a virt-v2v test.

As of implementation details, we uses virt-v2v command line tool
to convert an existing VM into libvirt-managed KVM, or an open
manageable virtualized environment - oVirt.

Signed-off-by: Alex Jia <[email protected]>
Signed-off-by: Wayne Sun <[email protected]>
---
 client/virt/virt_v2v.py |   59 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 client/virt/virt_v2v.py

diff --git a/client/virt/virt_v2v.py b/client/virt/virt_v2v.py
new file mode 100644
index 0000000..973d8ca
--- /dev/null
+++ b/client/virt/virt_v2v.py
@@ -0,0 +1,59 @@
+"""
+Utility functions to handle Virtual Machine conversion using virt-v2v.
+
+@copyright: 2008-2012 Red Hat Inc.
+"""
+
+import logging
+from autotest.client import os_dep, utils
+from autotest.server.hosts.ssh_host import SSHHost
+import virt_v2v_utils as v2v_utils
+
+DEBUG = False
+
+try:
+    V2V_EXEC = os_dep.command('virt-v2v')
+except ValueError:
+    V2V_EXEC = None
+
+
+def v2v_cmd(params):
+    """
+    Append cmd to 'virt-v2v' and execute, optionally return full results.
+
+    @param: params: A dictionary includes all of required parameters such as
+                    'target', 'hypervisor', 'hostname', 'storage', 'network'.
+    @return: stdout of command
+    """
+    if V2V_EXEC is None:
+        raise ValueError('Missing command: virt-v2v')
+    
+    target = params.get('target')
+    hypervisor = params.get('hypervisor')
+    hostname = params.get('hostname')
+    storage = params.get('storage')
+    network = params.get('network')
+    username = params.get('username')
+    password = params.get('password')
+
+    uri_obj = v2v_utils.URI(hypervisor)
+    # Return actual 'uri' according to 'hostname' and 'hypervisor'
+    uri = uri_obj.get_uri(hostname)
+
+    tgt_obj = v2v_utils.TARGERT(target, uri)
+    # Return virt-v2v command line options based on 'target' and 'hypervisor'
+    options = tgt_obj.get_cmd_options(params)
+
+    # Convert a existing VM without or with connection autoorization.
+    if hypervisor == 'esx':
+        v2v_utils.build_esx_no_verify(params)
+    elif hypervisor == 'xen':
+        SSHHost(hostname, user=username, port=22, password=password)
+    else:
+        pass
+
+    # Construct a final virt-v2v command
+    cmd = '%s %s' % (V2V_EXEC, options)
+    logging.debug('%s' % cmd)
+    cmd_result = utils.run(cmd, verbose=DEBUG)
+    return cmd_result.stdout.strip()
--
1.7.10.2

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to