Reuse previous libvirt_vm module and add new virsh pool functions, and then
we can create/check a libvirt pool via these functions and use virt-v2v to
convert an existing VM into the pool later.

Signed-off-by: Alex Jia <a...@redhat.com>
---
 client/virt/libvirt_vm.py |   61 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index 8d2cd1e..6491d50 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -484,6 +484,67 @@ def virsh_detach_device(name, xml_file, extra="", uri=""):
         return False
 
 
+def virsh_pool_info(name, uri = ""):
+    """
+    Returns basic information about the storage pool.
+    """
+    cmd = "pool-info %s" % name
+    try:
+        virsh_cmd(cmd, uri)
+        return True
+    except error.CmdError, detail:
+        logging.error("Pool %s doesn't exist:\n%s", name, detail)
+        return False
+
+def virsh_pool_destroy(name, uri = ""):
+    """
+    Forcefully stop a given pool.
+    """
+    cmd = "pool-destroy %s" % name
+    try:
+        virsh_cmd(cmd, uri)
+        return True
+    except error.CmdError, details:
+        logging.error("Failed to destroy pool: %s." % detail)
+        return False
+
+def virsh_pool_create_as(name, _type, target, extra = "", uri = ""):
+    """
+    Create a pool from a set of args.
+
+    @param: name: name of pool
+    @param: type: storage pool type such as 'dir'
+    @param: target: libvirt uri to send guest to
+    @param: extra: Free-form string of options
+    @return: True if pool creation command was successful
+    """
+
+    if not name:
+        logging.error("Please give a pool name")
+
+    if os.path.isdir(target):
+        logging.debug("Underlying storage is: %s" % target)
+    else:
+        logging.error("'target' argument must be a directory")
+
+    types = [ 'dir', 'fs', 'netfs', 'disk', 'iscsi', 'logical' ]
+
+    if _type and _type not in types:
+        logging.error("Only support pool types: %s." % types)
+    elif not _type:
+        _type = types[0]
+
+    logging.info("Create %s type pool %s" % (_type, name))
+    cmd = "pool-create-as --name %s --type %s --target %s %s" \
+          % (name, _type, target, extra)
+    try:
+        virsh_cmd(cmd, uri)
+        return True
+    except error.CmdError, detail:
+        logging.warning("Failed to create pool: %s." % detail)
+        return False
+
+
 class VM(virt_vm.BaseVM):
     """
     This class handles all basic VM operations for libvirt.
-- 
1.7.10.2

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to