From: Satheesh Rajendran <[email protected]>

vcpupin(): to pin the vcpu to cpu
get_vcpus_pid(): to get the vcpu pid
virsh_qemu_monitor_command(): implements virsh qemu-monitor-command
virsh_vcpupin(): implements virsh vcpupin command
virsh_vcpuinfo(): implements virsh vcpuinfo command
virsh_vcpucount_live(): implements vcpucount command


Signed-off-by: Satheesh Rajendran <[email protected]>
---
 client/virt/libvirt_vm.py |   63 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index 25a403b..d4b2306 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -116,6 +116,49 @@ def virsh_cmd(cmd, uri="", ignore_status=False, 
print_info=False):
     return ret
 
 
+def virsh_qemu_monitor_command(domname, command, uri="",
+                               ignore_status=False, print_info=False):
+    """
+    This helps to execute the qemu monitor command through virsh command.
+    """
+
+    cmd_qemu_monitor = "qemu-monitor-command %s --hmp \'%s\'" % (domname, 
command)
+    return virsh_cmd(cmd_qemu_monitor, uri, ignore_status, print_info)
+
+
+def virsh_vcpupin(domname, vcpu, cpu, uri="",
+                  ignore_status=False, print_info=False):
+    """
+    Changes the cpu affinity for respective vcpu.
+    """
+
+    try:
+        cmd_vcpupin = "vcpupin %s %s %s" % (domname, vcpu, cpu)
+        virsh_cmd(cmd_vcpupin, uri, ignore_status, print_info)
+
+    except error.CmdError, detail:
+        logging.error("Virsh vcpupin VM %s failed:\n%s", domname, detail)
+        return False
+
+
+def virsh_vcpuinfo(domname, uri="", ignore_status=False, print_info=False):
+    """
+    Prints the vcpuinfo of a given domain.
+    """
+
+    cmd_vcpuinfo = "vcpuinfo %s" % domname
+    return virsh_cmd(cmd_vcpuinfo, uri, ignore_status, 
print_info).stdout.strip()
+
+
+def virsh_vcpucount_live(domname, uri="", ignore_status=False, 
print_info=False):
+    """
+    Prints the vcpucount of a given domain.
+    """
+
+    cmd_vcpucount = "vcpucount --live --active %s" % domname
+    return virsh_cmd(cmd_vcpucount, uri, ignore_status, 
print_info).stdout.strip()
+
+
 def virsh_freecell(uri = "", ignore_status=False, extra = ""):
     """
     Prints the available amount of memory on the machine or within a NUMA cell.
@@ -1564,6 +1607,19 @@ class VM(virt_vm.BaseVM):
         return pid
 
 
+    def get_vcpus_pid(self):
+        """
+        Return the vcpu's pid for a given VM.
+
+        @return: list of PID of vcpus of a VM.
+        """
+
+        vcpu_pids = []
+        output = virsh_qemu_monitor_command(self.name, "info cpus")
+        vcpu_pids = re.findall(r'thread_id=(\d+)', output.stdout)
+        return vcpu_pids
+
+
     def get_shell_pid(self):
         """
         Return the PID of the parent shell process.
@@ -1746,3 +1802,10 @@ class VM(virt_vm.BaseVM):
         Override BaseVM restore_from_file method
         """
         virsh_restore(self.name, path, uri=self.connect_uri)
+
+
+    def vcpupin(self, vcpu, cpu):
+        """
+        To pin vcpu to cpu
+        """
+        virsh_vcpupin(self.name, vcpu, cpu)
-- 
1.7.5.4

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

Reply via email to