From: Satheesh Rajendran <[email protected]>

Signed-off-by: Satheesh Rajendran <[email protected]>
---
 virttest/virsh.py |  210 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 210 insertions(+), 0 deletions(-)

diff --git a/virttest/virsh.py b/virttest/virsh.py
index cab73af..5ecaf12 100644
--- a/virttest/virsh.py
+++ b/virttest/virsh.py
@@ -1033,6 +1033,7 @@ def pool_create_as(name, pool_type, target, extra="", 
**dargs):
 
     if not name:
         logging.error("Please give a pool name")
+        return False
 
     types = [ 'dir', 'fs', 'netfs', 'disk', 'iscsi', 'logical' ]
 
@@ -1052,6 +1053,215 @@ def pool_create_as(name, pool_type, target, extra="", 
**dargs):
         logging.error("Failed to create pool: %s." % detail)
         return False
 
+def pool_list(option="", extra="", **dargs):
+    """
+    Prints the pool information of Host
+
+    @param: option: options given to command
+    --all - gives all pool details, including inactive
+    --inactive - gives only inactive pool details
+    --details - Gives the complete details about the pools
+    @param: extra: to provide extra options(to enter invalid options)
+    """
+
+    cmd = "pool-list %s %s" % (option, extra)
+    return command(cmd, **dargs)
+
+
+def pool_define_as(name, pool_type, target, extra="", **dargs):
+    """
+    Define the pool from the arguments
+
+    @param: name: Name of the pool to be defined
+    @param: typ: Type of the pool to be defined
+    dir - file system directory
+    disk - Physical Disk Device
+    fs - Pre-formatted Block Device
+    netfs - Network Exported Directory
+    iscsi - iSCSI Target
+    logical - LVM Volume Group
+    mpath - Multipath Device Enumerater
+    scsi - SCSI Host Adapter
+    @param: target: libvirt uri to send guest to
+    @param: extra: Free-form string of options
+    @param: dargs: standardized virsh function API keywords
+    @return: True if pool define command was successful
+    """
+
+    if not name:
+        logging.error("Please give a pool name")
+        return False
+
+    types = [ 'dir', 'fs', 'netfs', 'disk', 'iscsi', 'logical' ]
+
+    if pool_type and pool_type not in types:
+        logging.error("Only support pool types: %s." % types)
+    elif not pool_type:
+        pool_type = types[0]
+
+    logging.info("Define %s type pool %s" % (pool_type, name))
+    cmd = "pool-define-as --name %s --type %s --target %s %s" \
+          % (name, pool_type, target, extra)
+    dargs['ignore_status'] = False
+    try:
+        command(cmd, **dargs)
+        return True
+    except error.CmdError, detail:
+        logging.error("Failed to define pool: %s." % detail)
+        return False
+
+
+def pool_start(name, extra="", **dargs):
+    """
+    Start the defined pool
+    @param: name: Name of the pool to be started
+    @param: extra: Free-form string of options
+    @param: dargs: standardized virsh function API keywords
+    @return: True if pool start command was successful
+    """
+
+    if not name:
+        logging.error("Please give a pool name")
+        return False
+
+    cmd = "pool-start %s %s" % (name, extra)
+    dargs['ignore_status'] = False
+    try:
+        command(cmd, **dargs)
+        return True
+    except error.CmdError, detail:
+        logging.error("Failed to start a pool: %s" % detail)
+        return False
+
+
+def pool_autostart(name, extra="", **dargs):
+    """
+    Mark for autostart of a pool
+    @param: name: Name of the pool to be mark for autostart
+    @param: extra: Free-form string of options
+    @param: dargs: standardized virsh function API keywords
+    @return: True if pool autostart command was successful
+    """
+
+    if not name:
+        logging.error("Please give a pool name")
+        return False
+
+    cmd = "pool-autostart %s %s" % (name, extra)
+    dargs['ignore_status'] = False
+    try:
+        command(cmd, **dargs)
+        return True
+    except error.CmdError, detail:
+        logging.error("Failed to mark autostart to a pool" % detail)
+        return False
+
+def pool_undefine(name, extra="", **dargs):
+    """
+    Undefine the given pool
+
+    @param: name: Name of the pool to be undefined
+    @param: extra: Free-form string of options
+    @param: dargs: standardized virsh function API keywords
+    @return: True if pool undefine command was successful
+    """
+
+    if not name:
+        logging.error("Please give a pool name")
+        return False
+
+    cmd = "pool-undefine %s %s" % (name, extra)
+    dargs['ignore_status'] = False
+    try:
+        command(cmd, **dargs)
+        return True
+    except error.CmdError, detail:
+        logging.debug("Failed to undefine the pool" % detail)
+        return False
+
+
+def vol_create_as(name, pool_name, capacity, allocation, frmt, \
+                      extra="", **dargs):
+    """
+    To create the volumes on different available pool
+
+    @param: name: Name of the volume to be created
+    @param: pool_name: Name of the pool to be used
+    @param: capacity: Size of the volume
+    @param: allocaltion: Size of the volume to be pre-allocated
+    @param: frmt: volume formats(e.g. raw, qed, qcow2)
+    @param: extra: Free-form string of options
+    @param: dargs: standardized virsh function API keywords
+    @return: True if pool undefine command was successful
+    """
+
+    cmd = "vol-create-as"
+    if not pool_name:
+        logging.error("Please give a available pool name")
+        return False
+    else:
+        cmd += " --pool %s" % (pool_name)
+    if not name:
+        logging.error("Please give a volume name")
+        return False
+    else:
+        cmd += " %s" % (name)
+    if not capacity:
+        logging.error("Please give the capacity of a volume")
+        return False
+    else:
+        cmd += " --capacity %s" % (capacity)
+    if allocation:
+        cmd += " --allocation %s" % (allocation)
+    if format:
+        cmd += " --format %s" % (frmt)
+    if extra:
+        cmd += " %s" % (extra)
+
+    try:
+        command(cmd, **dargs)
+        return True
+    except error.CmdError, detail:
+        logging.error("Failed to create a volume %s", detail)
+        return False
+
+
+def vol_list(pool_name, extra="", **dargs):
+    """
+    List the volumes for a given pool
+    """
+
+    if not pool_name:
+        logging.error("Please give a pool name")
+        return False
+
+    cmd = "vol-list %s %s" % (pool_name, extra)
+    try:
+        return command(cmd, **dargs)
+    except error.CmdError, detail:
+        logging.debug("Failed to list the volume\n %s", detail)
+        return False
+
+def vol_delete(vol_name, pool_name, extra="", **dargs):
+    """
+    Delete a given volume
+    """
+
+    if not vol_name:
+        logging.error("Please give a volume name to delete")
+        return False
+    if not pool_name:
+        logging.error("Please give the respective pool name")
+        return False
+
+    cmd = "vol-delete %s %s %s" % (vol_name, pool_name, extra)
+    try:
+        command(cmd, **dargs)
+        return True
+    except error.CmdError, detail:
+        logging.error("Failed to delete a volume %", detail)
+        return False
+
 
 def capabilities(option='', **dargs):
     """
-- 
1.7.1

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to