libvirt-cim-bounces@redhat.com wrote on 2008-10-30 10:53:32:

> # HG changeset patch
> # User Guolian Yun <yunguol@cn.ibm.com>
> # Date 1225335207 25200
> # Node ID 91f9a0bed4667b6b30a241569ef70a93b8bc0b2b
> # Parent  408dbb3a61b43bd0def587a9ea7e648105def002
> [TEST] #2 Create a new module of xm_virt_util.py in ..
> /lib/XenKvmLib, move some functions from live.py under lib/XenKvmLib to it


  Please ignore this patch, I missed my DCO here. I will resend a new patch.

  Thanks!
>
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/AllocationCapabilities/02_alloccap_gi_errs.py
> --- a/suites/libvirt-
> cim/cimtest/AllocationCapabilities/02_alloccap_gi_errs.py   Mon Oct
> 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/AllocationCapabilities/02_alloccap_gi_errs.py   Wed Oct
> 29 19:53:27 2008 -0700
> @@ -57,7 +57,7 @@
>  from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
>  from CimTest.ReturnCodes import PASS, SKIP, FAIL
>  from XenKvmLib.common_util import try_getinstance
> -from VirtLib.live import net_list
> +from XenKvmLib.xm_virt_util import net_list
>  from XenKvmLib.test_xml import netxml
>  from XenKvmLib.test_doms import create_vnet
>  from XenKvmLib.const import do_main, platform_sup, default_pool_name
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/ComputerSystem/01_enum.py
> --- a/suites/libvirt-cim/cimtest/ComputerSystem/01_enum.py   Mon Oct
> 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/ComputerSystem/01_enum.py   Wed Oct
> 29 19:53:27 2008 -0700
> @@ -25,7 +25,7 @@
>  import sys
>  from XenKvmLib.const import do_main
>  from XenKvmLib import enumclass
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import domain_list
>  from XenKvmLib.classes import get_typed_class
>  from VirtLib import utils
>  from CimTest import Globals
> @@ -41,7 +41,7 @@
>      cs_class = get_typed_class(options.virt, 'ComputerSystem')
>      try:
>          cs = enumclass.EnumInstances(options.ip, cs_class)
> -        live_cs = live.domain_list(options.ip, options.virt)
> +        live_cs = domain_list(options.ip, options.virt)
>          for system in cs:
>              name = system.name
>              try:
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/ComputerSystem/02_nosystems.py
> --- a/suites/libvirt-cim/cimtest/ComputerSystem/02_nosystems.py  
> Mon Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/ComputerSystem/02_nosystems.py  
> Wed Oct 29 19:53:27 2008 -0700
> @@ -25,7 +25,7 @@
>  import sys
>  import pywbem
>  from XenKvmLib import enumclass
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import domain_list
>  from VirtLib import utils
>  from XenKvmLib.classes import get_typed_class
>  from CimTest.Globals import logger, CIM_ERROR_ENUMERATE
> @@ -35,7 +35,7 @@
>  sup_types = ['KVM', 'LXC']
>  
>  def clean_system(host, virt):
> -    l = live.domain_list(host, virt)
> +    l = domain_list(host, virt)
>      if len(l) > 0:
>          return False
>      else:
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/ElementCapabilities/01_forward.py
> --- a/suites/libvirt-cim/cimtest/ElementCapabilities/01_forward.py  
> Mon Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/ElementCapabilities/01_forward.py  
> Wed Oct 29 19:53:27 2008 -0700
> @@ -22,7 +22,7 @@
>  
>  import sys
>  from VirtLib import utils
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import domain_list
>  from XenKvmLib import vxml
>  from XenKvmLib import assoc
>  from XenKvmLib import enumclass
> @@ -114,7 +114,7 @@
>          logger.error("Failed to define the dom: %s", test_dom)
>          return FAIL
>  
> -    cs = live.domain_list(server, virt)
> +    cs = domain_list(server, virt)
>      ccn  = get_typed_class(virt, "ComputerSystem")
>      for system in cs:  
>          try:
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/ElementCapabilities/02_reverse.py
> --- a/suites/libvirt-cim/cimtest/ElementCapabilities/02_reverse.py  
> Mon Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/ElementCapabilities/02_reverse.py  
> Wed Oct 29 19:53:27 2008 -0700
> @@ -23,7 +23,7 @@
>  
>  import sys
>  from VirtLib import utils
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import domain_list
>  from XenKvmLib import assoc
>  from XenKvmLib import enumclass
>  from XenKvmLib import vxml
> @@ -154,7 +154,7 @@
>          logger.error("Failed to define the dom: %s" % test_dom)
>          return FAIL
>  
> -    cs = live.domain_list(options.ip, options.virt)
> +    cs = domain_list(options.ip, options.virt)
>      for system in cs:
>          cn = get_typed_class(options.virt,
> "EnabledLogicalElementCapabilities")
>          status, elec_cs = call_assoc(options.ip, cn, system, options.virt)
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/EnabledLogicalElementCapabilities/01_enum.py
> --- a/suites/libvirt-
> cim/cimtest/EnabledLogicalElementCapabilities/01_enum.py   Mon Oct
> 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/EnabledLogicalElementCapabilities/01_enum.py   Wed Oct
> 29 19:53:27 2008 -0700
> @@ -26,7 +26,7 @@
>  from XenKvmLib.classes import get_typed_class
>  from CimTest import Globals
>  from XenKvmLib.const import do_main
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import domain_list
>  from VirtLib import utils
>  
>  sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
> @@ -44,7 +44,7 @@
>          return 1
>  
>      
> -    names = live.domain_list(options.ip, options.virt)
> +    names = domain_list(options.ip, options.virt)
>      
>      if len(elec) != len(names):
>          Globals.logger.error("Get domain list error, the number of
> domains is not equal")
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/Processor/01_processor.py
> --- a/suites/libvirt-cim/cimtest/Processor/01_processor.py   Mon Oct
> 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/Processor/01_processor.py   Wed Oct
> 29 19:53:27 2008 -0700
> @@ -25,7 +25,7 @@
>  import sys
>  import pywbem
>  from VirtLib import utils
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import active_domain_list
>  from XenKvmLib.enumclass import GetInstance
>  from XenKvmLib.test_xml import testxml
>  from XenKvmLib.classes import get_typed_class
> @@ -48,7 +48,7 @@
>      vsxml.start(options.ip)
>  
>      # Processor instance enumerate need the domain to be active
> -    domlist = live.active_domain_list(options.ip, options.virt)
> +    domlist = active_domain_list(options.ip, options.virt)
>      proc_class = get_typed_class(options.virt, "Processor")
>      if test_dom not in domlist:
>          status = FAIL
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/ResourcePool/01_enum.py
> --- a/suites/libvirt-cim/cimtest/ResourcePool/01_enum.py   Mon Oct
> 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/ResourcePool/01_enum.py   Wed Oct
> 29 19:53:27 2008 -0700
> @@ -34,7 +34,7 @@
>  from CimTest.Globals import logger
>  from XenKvmLib.const import do_main, default_pool_name
>  from CimTest.ReturnCodes import PASS, FAIL, SKIP
> -from VirtLib.live import net_list
> +from XenKvmLib.xm_virt_util import net_list
>  from XenKvmLib.vsms import RASD_TYPE_PROC, RASD_TYPE_MEM,
> RASD_TYPE_NET_ETHER, \
>  RASD_TYPE_DISK
>  
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/ResourcePool/02_rp_gi_errors.py
> --- a/suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py  
> Mon Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py  
> Wed Oct 29 19:53:27 2008 -0700
> @@ -28,7 +28,7 @@
>  import os
>  import sys
>  import pywbem
> -from VirtLib.live import net_list
> +from XenKvmLib.xm_virt_util import net_list
>  from XenKvmLib import assoc
>  from XenKvmLib import vxml
>  from XenKvmLib.common_util import try_getinstance
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/SettingsDefineCapabilities/01_forward.py
> --- a/suites/libvirt-
> cim/cimtest/SettingsDefineCapabilities/01_forward.py   Mon Oct 27
> 20:03:31 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/SettingsDefineCapabilities/01_forward.py   Wed Oct 29
> 19:53:27 2008 -0700
> @@ -57,7 +57,7 @@
>  from distutils.file_util import move_file
>  from XenKvmLib import assoc
>  from XenKvmLib import enumclass
> -from VirtLib.live import virsh_version
> +from XenKvmLib.xm_virt_util import virsh_version
>  from CimTest.ReturnCodes import PASS, FAIL, SKIP
>  from CimTest.Globals import logger, CIM_ERROR_GETINSTANCE,
> CIM_ERROR_ASSOCIATORS
>  from XenKvmLib.const import do_main, default_pool_name, default_network_name
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/VSSD/01_enum.py
> --- a/suites/libvirt-cim/cimtest/VSSD/01_enum.py   Mon Oct 27 20:03:
> 31 2008 -0700
> +++ b/suites/libvirt-cim/cimtest/VSSD/01_enum.py   Wed Oct 29 19:53:
> 27 2008 -0700
> @@ -27,7 +27,7 @@
>  # Date : 25-10-2007
>  
>  import sys
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import domain_list
>  from XenKvmLib import enumclass
>  from XenKvmLib.classes import get_typed_class
>  from XenKvmLib.test_doms import destroy_and_undefine_all
> @@ -53,7 +53,7 @@
>          status = FAIL
>  
>      try:
> -        live_cs = live.domain_list(options.ip, options.virt)
> +        live_cs = domain_list(options.ip, options.virt)
>          vssd_class = get_typed_class(options.virt,
> "VirtualSystemSettingData")
>          syslst = enumclass.EnumInstances(options.ip, vssd_class)
>          found = 0
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py
> --- a/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py   Mon
> Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py   Wed
> Oct 29 19:53:27 2008 -0700
> @@ -25,7 +25,7 @@
>  import pywbem
>  from pywbem.cim_obj import CIMInstanceName
>  from VirtLib import utils
> -from VirtLib.live import domain_list, active_domain_list
> +from XenKvmLib.xm_virt_util import domain_list, active_domain_list
>  from XenKvmLib import vsms, vxml
>  from XenKvmLib.classes import get_typed_class
>  from XenKvmLib.const import do_main
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/08_modifyresource.py
> --- a/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/08_modifyresource.py  
> Mon Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/08_modifyresource.py  
> Wed Oct 29 19:53:27 2008 -0700
> @@ -26,7 +26,7 @@
>  import pywbem
>  from pywbem.cim_obj import CIMInstanceName
>  from VirtLib import utils
> -from VirtLib.live import network_by_bridge
> +from XenKvmLib.xm_virt_util import network_by_bridge
>  from XenKvmLib import vsms
>  from XenKvmLib import vxml
>  from CimTest.Globals import logger
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/10_hv_version.py
> --- a/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/10_hv_version.py   Mon
> Oct 27 20:03:31 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/10_hv_version.py   Wed
> Oct 29 19:53:27 2008 -0700
> @@ -22,7 +22,7 @@
>  
>  import sys
>  import pywbem
> -from VirtLib import live
> +from XenKvmLib.xm_virt_util import get_hv_ver
>  from XenKvmLib import vsms
>  from XenKvmLib.const import do_main
>  from CimTest.Globals import logger
> @@ -47,7 +47,7 @@
>  
>      try:
>          cim_ver = service["Caption"]
> -        local_ver = live.get_hv_ver(options.ip, options.virt)
> +        local_ver = get_hv_ver(options.ip, options.virt)
>  
>          if cim_ver != local_ver:
>              logger.error("CIM says version is `%s', but libvirt says `%s'" \
> diff -r 408dbb3a61b4 -r 91f9a0bed466 suites/libvirt-
> cim/lib/XenKvmLib/xm_virt_util.py
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py   Wed Oct 29
> 19:53:27 2008 -0700
> @@ -0,0 +1,238 @@
> +#
> +# Copyright 2008 IBM Corp.
> +#
> +# Authors:
> +#    Dan Smith <danms@us.ibm.com>
> +#    Deepti B. Kalakeri <dkalaker@in.ibm.com>
> +#    Kaitlin Rupert <karupert@us.ibm.com>
> +#    Veerendra Chandrappa <vechandr@in.ibm.com>
> +#    Zhengang Li <lizg@cn.ibm.com>
> +#
> +# This library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +#
> +# This library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public
> +# License along with this library; if not, write to the Free Software
> +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> +#
> +import os
> +from VirtLib import utils
> +import socket
> +
> +def xm_domname(ip, domid):
> +
> +    cmd = "xm domname %s" % domid
> +
> +    rc, out = utils.run_remote(ip, cmd)
> +    if rc != 0:
> +        return None
> +
> +    return out
> +
> +def list_guests_on_bridge(ip, bridge):
> +    """Returns a list of domU names that have vifs in the
> +    specified bridge.
> +    """
> +
> +    cmd = "brctl show %s | grep 'vif' | grep -v vif0.*" % bridge
> +
> +    rc, out = utils.run_remote(ip, cmd)
> +    if rc != 0:
> +        return []
> +
> +    ret = []
> +    lines = out.splitlines()
> +    for l in lines:
> +        vif = l.split()[-1]
> +        domid = vif.replace('vif', '').split('.')[0]
> +        domname = xm_domname(ip, domid)
> +        if domname != None:
> +            ret.append(domname)
> +
> +    return ret
> +
> +def disk_list(ip, vs_name):
> +    """Returns the list of disk of the specified VS
> +    """
> +
> +    guest_cmd = "cat /proc/partitions | awk '/^ /{ print $4 } ' "
> +    rc, out = utils.run_remote_guest(ip, vs_name, guest_cmd)
> +
> +    if rc != 0:
> +        return None
> +
> +    return out
> +
> +def max_free_mem(server):
> +    """Function to get max free mem on dom0.
> +
> +    Returns an int containing the value in MB.
> +    """
> +
> +    xm_ret, mfm = utils.run_remote(server,
> +                    "xm info | awk -F ': ' '/max_free_memory/ {print \$2}'")
> +    if xm_ret != 0:
> +        return None
> +
> +    return int(mfm)
> +
> +def domain_list(server, virt="Xen"):
> +    """Function to list all domains"""
> +    if virt == "XenFV":
> +       virt = "Xen"
> +
> +    cmd = "virsh -c %s list --all | sed -e '1,2 d' -e '$ d'" % \
> +                utils.virt2uri(virt)
> +    ret, out = utils.run_remote(server, cmd)
> +
> +    if ret != 0:
> +        return None
> +    names = []
> +    lines = out.split("\n")
> +    for line in lines:
> +        dinfo = line.split()
> +        if len(dinfo) > 1:
> +            names.append(dinfo[1])
> +
> +    return names
> +
> +def active_domain_list(server, virt="Xen"):
> +    """Function to list all active domains"""
> +    if virt == "XenFV":
> +        virt = "Xen"
> +
> +    cmd = "virsh -c %s list | sed -e '1,2 d' -e '$ d'" % \
> +                utils.virt2uri(virt)
> +    ret, out = utils.run_remote(server, cmd)
> +
> +    if ret != 0:
> +        return None
> +    names = []
> +    lines = out.split("\n")
> +    for line in lines:
> +        dinfo = line.split()
> +        if len(dinfo) > 1:
> +            names.append(dinfo[1])
> +
> +    return names
> +
> +def bootloader(server, gtype = 0):
> +    """
> +       Function to find the bootloader to be used.
> +       It uses the following steps to determine the bootloader.
> +       1) The function checks if the machine is full virt or para virt.
> +       2) Checks if a Full virt guest option is set
> +          NOTE : gtype = 1 for FV and gtype = 0 for PV
> +          i) If yes, then verifies if the machine has the support to
> +             create the full virt guest. If both options are true then
> +             bootloader is set to 'hvmloader'
> +          ii) Otherwise, a paravirt guest creation is requested.
> +              a) Verfies the OS on which it is running is Red
> hat/Fedora/SLES.
> +              b) sets the bootloader to pygrub for Red hat/Fedora
> +                 or domUloader.py for SLES.
> +       3) returns the bootloader.
> +    """
> +    if fv_cap(server) and gtype == 1:
> +        bootloader = "/usr/lib/xen/boot/hvmloader"
> +    else:
> +        cmd = "cat /etc/issue | grep -v ^$ | egrep 'Red Hat|Fedora'"
> +        ret, out = utils.run_remote(server,cmd)
> +        if ret != 0:
> +        # For SLES
> +            bootloader = "/usr/lib/xen/boot/domUloader.py"
> +        else:
> +        # For Red Hat or Fedora
> +            bootloader = "/usr/bin/pygrub"
> +    return bootloader
> +
> +def net_list(server, virt="Xen"):
> +    """Function to list active network"""
> +    names = []
> +    cmd = "virsh -c %s net-list | sed -e '1,2 d' -e '$ d'" % \
> +                utils.virt2uri(virt)
> +    ret, out = utils.run_remote(server, cmd)
> +
> +    if ret != 0:
> +        return names
> +    lines = out.split("\n")
> +    for line in lines:
> +        virt_network = line.split()
> +        if len(virt_network) >= 1 and virt_network[1] == "active":
> +            names.append(virt_network[0])
> +
> +    return names
> +
> +def get_bridge_from_network_xml(network, server, virt="Xen"):
> +    """Function returns bridge name for a given virtual network"""
> +
> +    cmd = "virsh -c %s net-dumpxml %s | awk '/bridge name/ { print $2 }'" % \
> +                (utils.virt2uri(virt), network)
> +    ret, out = utils.run_remote(server, cmd)
> +
> +    if ret != 0:
> +        return None
> +    bridge = out.split("'")
> +    if len(bridge) > 1:
> +        return bridge[1]
> +
> +def network_by_bridge(bridge, server, virt="Xen"):
> +    """Function returns virtual network for a given bridge"""
> +
> +    networks = net_list(server, virt)
> +    if len(networks) == 0:
> +        return None
> +
> +    for network in networks:
> +        if bridge == get_bridge_from_network_xml(network, server, virt):
> +            return network
> +
> +    return None
> +
> +def virsh_version(server, virt="KVM"):
> +    cmd = "virsh -c %s -v " % utils.virt2uri(virt)
> +    ret, out = utils.run_remote(server, cmd)
> +    if ret != 0:
> +        return None
> +    return out
> +
> +def diskpool_list(server, virt="KVM"):
> +    """Function to list active DiskPool list"""
> +    names = []
> +    cmd = "virsh -c %s pool-list | sed -e '1,2 d' -e '$ d'" % \
> +           utils.virt2uri(virt)
> +    ret, out = utils.run_remote(server, cmd)
> +
> +    if ret != 0:
> +        return names
> +
> +    lines = out.split("\n")
> +    for line in lines:
> +        disk_pool = line.split()
> +        if len(disk_pool) >= 1 and disk_pool[1] == "active":
> +            names.append(disk_pool[0])
> +
> +    return names
> +
> +def virsh_vcpuinfo(server, dom, virt="Xen"):
> +    cmd = "virsh -c %s vcpuinfo %s | grep VCPU | wc -l" % (utils.
> virt2uri(virt),
> +          dom)
> +    ret, out = utils.run_remote(server, cmd)
> +    if out.isdigit():
> +        return out
> +    return None
> +
> +def get_hv_ver(server, virt="Xen"):
> +    cmd = "virsh -c %s version | grep ^Running | cut -d ' ' -f 3,4"
> % utils.virt2uri(virt)
> +    ret, out = utils.run_remote(server, cmd)
> +    if ret == 0:
> +        return out
> +    else:
> +        return None
> +
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim